Skip to content

Report guest path for /proc/self/exe under Rosetta#154

Open
jserv wants to merge 1 commit into
mainfrom
readlink
Open

Report guest path for /proc/self/exe under Rosetta#154
jserv wants to merge 1 commit into
mainfrom
readlink

Conversation

@jserv

@jserv jserv commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

On x86_64 guests, readlink("/proc/self/exe") and
readlink("/proc/self/fd/N") (with N from opening /proc/self/exe) returned the Rosetta translator path (ROSETTA_PATH) instead of the running guest binary. GNU coreutils ships a multi-call binary whose applets self-identify by reading /proc/self/exe, opening it, then readlink-ing /proc/self/fd/N and matching the basename. Getting "rosetta" back made every applet abort with "unknown program 'rosetta'", which broke Debian/Ubuntu maintainer scripts under apt upgrade and dpkg -i.

Factor the /proc/self/exe resolution (ELF-path snapshot plus sysroot-prefix strip) into proc_readlink_self_exe. Drop the Rosetta early-return from the direct /proc/self/exe branch, and in the /proc/self/fd/N branch substitute the guest binary when the host fd resolves to ROSETTA_PATH.

proc_intercept_open("/proc/self/exe") still hands back an fd to ROSETTA_PATH so the VZ ioctl gate (rosetta_ioctl_target_fd) keeps recognising Rosetta's own self-identification; only the guest-visible readlink string changed.

Close #107


Summary by cubic

Fixes wrong /proc/self/exe reporting under Rosetta. readlink("/proc/self/exe") and readlink("/proc/self/fd/N") now return the guest binary path (sysroot-stripped) so multi-call binaries no longer abort.

  • Bug Fixes

    • Return the guest binary for readlink("/proc/self/exe") and readlink("/proc/self/fd/N") on x86_64 under Rosetta, with sysroot prefix stripped.
    • Keep open("/proc/self/exe") returning a host fd to ROSETTA_PATH so the VZ ioctl gate still recognizes Rosetta.
    • Add a regression test asserting /proc/self/exe resolves to the guest (basename busybox), not Rosetta.
  • Refactors

    • Extract proc_readlink_self_exe() to resolve the ELF path and strip the sysroot; reuse in both readlink paths.
    • Remove the Rosetta early-return for /proc/self/exe and substitute the guest path when an fd resolves to ROSETTA_PATH.

Written for commit ebd6d26. Summary will update on new commits.

Review in cubic

@jserv jserv requested review from Max042004 and doanbaotrung July 5, 2026 21:43
cubic-dev-ai[bot]

This comment was marked as resolved.

On x86_64 guests, readlink("/proc/self/exe") and
readlink("/proc/self/fd/N") (with N from opening /proc/self/exe) returned
the Rosetta translator path (ROSETTA_PATH) instead of the running guest
binary. GNU coreutils ships a multi-call binary whose applets
self-identify by reading /proc/self/exe, opening it, then readlink-ing
/proc/self/fd/N and matching the basename. Getting "rosetta" back made
every applet abort with "unknown program 'rosetta'", which broke
Debian/Ubuntu maintainer scripts under apt upgrade and dpkg -i.

Factor the /proc/self/exe resolution (ELF-path snapshot plus
sysroot-prefix strip) into proc_readlink_self_exe. Drop the Rosetta
early-return from the direct /proc/self/exe branch, and in the
/proc/self/fd/N branch substitute the guest binary when the host fd
resolves to ROSETTA_PATH.

proc_intercept_open("/proc/self/exe") still hands back an fd to
ROSETTA_PATH so the VZ ioctl gate (rosetta_ioctl_target_fd) keeps
recognising Rosetta's own self-identification; only the guest-visible
readlink string changed.

Close #107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readlink("/proc/self/exe") and readlink("/proc/self/fd/N") return the Rosetta translator path instead of the guest binary path on x86_64 guests

1 participant