Skip to content

ADR-3532: Preserve trusted executable launch links

  • Status: Accepted (directory-mode and ACL rule for links in the resolved file's directory conditionally superseded by ADR-3534 when the resolved file is known unprotected or both entries have replacement protection)
  • Date: 2026-11-11
  • Deciders: Repository maintainers
  • Tags: python, security, testing

Context

The bounded process runner checks the resolved executable against its allowlist, but a virtual environment also depends on the path passed to the operating system at launch. The macOS framework interpreter stub sets __PYVENV_LAUNCHER__ from _NSGetExecutablePath in Mac/Tools/pythonw.c. Executing the resolved interpreter loses the virtual environment even when argv[0] retains its link name. The master Build run 42940218976 and Builds run 42940218931 failed in python/test/tools_test.py with a missing numpy module after resolved-file launch. The Linux interpreter's Modules/getpath.py uses argv[0], so Linux results did not expose that regression.

Preserving the named launch path introduces another requirement: another user must not be able to retarget any followed symbolic link between validation and execution. The same rule applies to the byte-identical runner shipped in the tester package. Bounded traversal and fail-closed validation follow principles.md.

Hosted Ubuntu tool-cache directories are other-writable without sticky protection: images/ubuntu/scripts/build/configure-system.sh L15 at runner-images commit 5ebd98a1ebeb applies chmod -R 777 /opt (read 2026-11-11). Refusing interpreter links in those directories rejected /opt/hostedtoolcache/Python/3.14.10/x64/bin/python3 and failed every Linux leg at e3b9b8d7b: Pre-Commit (run 42987466493), Tooling Tests and Python Package Tests (run 42987466133), and the Ubuntu clang and gcc DNN builds (run 42987466031). Regular executable files in those directories passed because the trust check applies only to links.

Decision

Launch the named absolute path on Linux and macOS only after checking every symbolic link followed in kernel traversal order, including links introduced by directory components and relative or absolute link targets. Require each link's lstat owner and its already resolved containing directory's owner to be the current user or root. Group-writable or other-writable containing directories without sticky protection are untrusted regardless of group membership. Sticky directories retain their mode-based protection. Linux POSIX ACL write grants are covered by the ACL mask in the group mode bits, so mode-based refusal also covers named-user and named-group write grants.

On macOS, inspect the extended ACL of each link's containing directory with acl_get_link_np(..., ACL_TYPE_EXTENDED). Any allow entry makes the directory untrusted, including sticky directories; deny-only ACLs add no permission. This deliberately rejects all allow entries rather than attempting to interpret subjects or permission combinations. A missing ACL (NULL with ENOENT) permits the mode check. Library or symbol lookup failure, any other ACL read error, unreadable or unknown tags, failed cleanup, and more than MAX_DARWIN_ACL_ENTRIES = 128 entries fail closed. Free every non-NULL ACL. Only the link's parent directory receives ACL inspection: replacing a link requires directory entry rights such as add_file and delete_child. Other POSIX platforms always launch the resolved file because their ACL models are not inspected.

When a chain is untrusted, including when link ownership or containing-directory metadata cannot be read, launch the resolved file with the caller's argv[0], restoring the previous behaviour. Preserve the named launch path only for trusted Linux and macOS chains; never execute through an untrusted link. Walk and evaluate links before strict file resolution so missing executables still report executable is unavailable. Bound traversal with MAX_EXECUTABLE_LINK_HOPS = 40 (Linux MAXSYMLINKS) and MAX_EXECUTABLE_WALK_STEPS = 4096, raising CommandValidationError naming the exceeded bound. Keep allowlist and runnable-file checks on the resolved file. Platforms without os.getuid, including Windows, launch the resolved file; Windows virtual environments use real interpreter files.

Alternatives considered

Option Pros Cons Why not chosen
Always launch the resolved file Removes symbolic-link retargeting from the launch path Loses macOS virtual-environment discovery; master runs 42940218976 and 42940218931 failed Retained only for untrusted chains and platforms without os.getuid
Always set executable to the resolved file and retain the link as argv[0] Preserves the argument name used by Linux discovery Same previous implementation and same macOS failures: the stub observes the executed path Retained for untrusted chains; trusted chains preserve macOS virtual environments
Check link trust, then select named or resolved launch Preserves trusted virtual environments and avoids executing through untrusted links Requires bounded traversal and ownership checks; ancestor-directory gap remains Chosen
Refuse untrusted links (earlier revision of this change) Prevents execution through untrusted links Refuses every hosted Ubuntu tool-cache interpreter; all Linux legs failed at e3b9b8d7b (runs 42987466493, 42987466133, 42987466031) Resolved-file launch avoids the untrusted link without rejecting the interpreter
Trust group-writable directories when every listed member is trusted (earlier revision) Preserves named launch through group-writable installation prefixes Group membership cannot be listed completely: nested groups in macOS directory services and SSSD ignore_group_members hide members The membership check is not fail-closed

Consequences

  • Positive: Trusted virtual-environment interpreter links and multi-call executable names survive launch. Tests cover sticky directories, group-write refusal, untrusted owners, platform selection, ACL results and entry bounds, intermediate links, allowlist refusal, traversal order, and both walk bounds. Native macOS tests exercise mode 0755 directories with allow and deny-only ACLs in the build matrix, independently of C build impact.
  • Negative: macOS Homebrew-Python virtual environments reached through the group-writable Homebrew prefix launch the resolved file and lose the virtual environment, as with the previous resolved-file behaviour. The installer grants group write to admin-group users (install.sh L164, L181–191 at 7986efac2501). Other untrusted macOS framework interpreter links have the same limitation. The check assumes root and the current user are trusted.
  • Neutral / follow-ups: Ancestor directories above each link's containing directory are not checked. An ancestor replacement can still change path resolution, the same residual risk as a plain absolute-path launch. These checks do not provide an atomic executable handle or protect against the current user or root changing the path. The walker is a bounded component walk with no recursion. The runner copies remain byte-identical.

Known gaps

  • The resolved file's own directory is not checked; hosted tool-cache directories are mode 777. Ancestor directories above each link's containing directory are also not checked. These checks do not eliminate path replacement races.
  • User-namespace sandboxes may expose unmapped host root as overflow uid 65534. Links with that owner select resolved-file launch; this was measured for /usr/bin/python3 in a user-namespace build sandbox on 2026-11-11. test_foreign_link_owner_launches_resolved_file covers that selection rule.

References