Repository navigation
Keep the guest's environ and musl's in step - #9
Open
buyemune-sys wants to merge 2 commits into
Open
buyemune-sys wants to merge 2 commits into
buyemune-sys wants to merge 2 commits into
Conversation
Security updates replaced libapparmor1 4.0.1really4.0.1-0ubuntu0.24.04.7 with .9 and libexpat1 2.6.1-2ubuntu0.4 with ubuntu0.6, and the pool kept only the new files, so the cold-cache Fetch x86_64 job answers 404 and every x86-64 job behind it is skipped. Both pins move to the versions noble-updates ships now; their SHA256s match the archive's Packages index. The other twelve pins are still served.
A glibc executable that touches environ carries a COPY relocation for it, so the guest reads and writes its own copy while musl's getenv, setenv, system and friends keep using musl's variable. Repointing environ — which setproctitle implementations do, moving the environment to the heap and overwriting the original strings with the title — then left musl reading clobbered memory: after Tarantool's box.cfg, os.getenv returned nothing and children started with a garbage environment. The environment entry points now pull the guest's pointer into musl before each call and push musl's back after the calls that may reallocate it, the way the getopt wrappers already shuttle optind. The guest test repoints environ and reads it back through getenv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
buyemune-sys
force-pushed
the
fix/environ-copy-relocation
branch
from
October 20, 2026 08:11
8dfa199 to
bc03d22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
A glibc executable that touches
environcarries a COPY relocation for it: the executable's.bssholds its own copy of the pointer. solo copies musl'senvironvalue into it once (SH_OBJECT("environ", …),lib/glibc_shim.cpp:4991). From then on there are two variables: the guest reads and writes its own, while musl'sgetenv/setenv/system/popenuse musl's.As long as the guest leaves
environalone, nothing shows. Butsetproctitleimplementations (nginx, postgres, Tarantool and others) repointenvironto a heap copy and overwrite the original string area with the process title. musl then reads overwritten memory.Example, in Tarantool after
box.cfg{}undersolo run:Child processes get a garbage environment as well.
The fix
This follows the existing
optind/optargsynchronization aroundgetopt(lib/glibc_shim.cpp:1557). Beforegetenv,setenv,unsetenv,putenv,clearenv,execvp,system,popenandtzset, the bridge pulls the guest's pointer into musl; after the calls that may reallocate the environment, it pushes musl's value back. The guest's copy is looked up asenvironor__environthroughElfImage::lookupGlobal. Only a successful lookup is cached, so the library-only case (no guest executable) behaves as before: musl's variable is the ABI.All of these names are added to
overrideNames; otherwise resolution would find musl's functions first.Test
The guest repoints
environto its own array{"SOLO_GUEST_ENV=repointed", 0}and reads it back throughgetenv. Needle:guest environ repointed=repointed.main:guest environ repointed=smoke-value. It already fails on the PIE guest, because this toolchain emits a COPY relocation for PIE too;./build testpasses.