Repository navigation
Reject wheels that require executable stacks - #732
CAOShurong wants to merge 10 commits into
Conversation
mayeut
left a comment
There was a problem hiding this comment.
Thanks for the PR
Can you update one of the integration tests using build_numpy to check for failure before patching openblas ? (requires moving openblas patch outside build_numpy)
2b65e8f to
85bff4b
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The new executable-stack detection is correctly integrated into policy evaluation and is covered by focused unit/integration tests, with matching CLI and JSON schema updates.
Pull request overview
This PR adds detection of ELF objects that request an executable stack (via PT_GNU_STACK + execute flag), classifying affected wheels as Linux-only in show output and rejecting them during repair for manylinux policies (fixes #634).
Changes:
- Add
elf_has_executable_stack()inelfutilsand plumb results throughwheel_abito produce anexecutable_stack_policy. - Update
auditwheel show --jsonschema/output (version bumped to 2) and include a newexecutable_stackboolean plus a text warning. - Make
auditwheel repairerror out when targeting a stricter policy than allowed due to executable-stack requirements; add unit/integration coverage.
File summaries
| File | Description |
|---|---|
src/auditwheel/elfutils.py |
Adds ELF PT_GNU_STACK executable-stack detection helper. |
src/auditwheel/wheel_abi.py |
Records executable-stack findings and incorporates them into policy selection. |
src/auditwheel/main_show.py |
Emits new JSON flag + text warning; bumps JSON version to 2. |
src/auditwheel/show-schema.json |
Updates JSON schema to version 2 and adds executable_stack field. |
src/auditwheel/main_repair.py |
Rejects repairs to stricter policies when executable stack is required. |
tests/unit/test_elfutils.py |
Adds unit tests for executable-stack detection. |
tests/unit/test_wheel_abi.py |
Updates unit test to stub executable-stack detection. |
tests/unit/test_main_show.py |
Updates JSON version expectations and validates new JSON key. |
tests/integration/test_manylinux.py |
Adjusts numpy integration flow to validate rejection then clearing executable stack. |
tests/integration/test_bundled_wheels.py |
Adds a targeted repair rejection test for executable-stack wheels. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if elf_has_executable_stack(elf): | ||
| executable_stack.append(fn) |
There was a problem hiding this comment.
this only applies to elf files already present in the wheels and thus misses grafted libs which explains the failing tests.
85bff4b to
06b62ac
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #732 +/- ##
==========================================
+ Coverage 96.08% 96.30% +0.22%
==========================================
Files 23 23
Lines 2042 2086 +44
Branches 388 403 +15
==========================================
+ Hits 1962 2009 +47
+ Misses 46 44 -2
+ Partials 34 33 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
elf_has_executable_stack() returns False when PT_GNU_STACK is missing. A missing marker is not the same as an explicit non-executable GNU_STACK; legacy/unknown ELF can still be treated as needing an executable stack. For a reject-on-exec-stack check, can the no-GNU_STACK case be handled as unknown/unsafe rather than safe, with a fixture for it?
What's the behaviour of recent distributions in this case ? I'm not sure we should be stricter than this. |
|
I checked current glibc. Missing PT_GNU_STACK is still not universally equivalent to a non-executable stack: glibc falls back to the architecture ABI default when the header is absent, and the glibc 2.41 execstack work explicitly calls out DSOs without PT_GNU_STACK as using the default executable-stack behavior. That caused real dlopen compatibility failures and led to the execstack tunable added in 2025. So I would avoid returning False for the missing-header case. A tri-state result seems cleaner: executable / non-executable / unknown. If auditwheel wants distro parity rather than conservative rejection, unknown does not necessarily have to fail repair, but it should not be classified as explicitly safe. References: https://snapshots.sourceware.org/glibc/trunk/latest/manual/html_node/Dynamic-Linking-Tunables.html and https://sourceware.org/pipermail/glibc-bugs/2025-February/058936.html |
Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
|
The missing-header follow-up is implemented in The glibc loader and execstack documentation support the target-dependent distinction; they do not establish a single recent-distribution runtime result. No distro/ Real bundled ELF regressions cover absent/RW/RWX on x86_64, i686, AArch64 and big-endian s390x. Related tests pass 67/67 repeatedly, including against the isolated installed wheel and built-sdist tests; one known Windows-path case is explicitly deselected. Full unit runs retain the same21 baseline Windows/environment failures (254/21 before,275/21 after). Installed real CLI checks cover JSON/text, successful This revision and communication were generated with OpenAI Codex. The prior body's unsupported personal-review wording has been corrected; no human review or production use is claimed. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Rechecked current head 0a7b9cc. The missing-PT_GNU_STACK case now has the tri-state behavior I asked for: explicit RW remains false, explicit RWX remains true, and an absent header is represented as unknown/None rather than safe. That state is surfaced in text/JSON and covered with real ELF fixtures across multiple architectures; grafted-library handling also treats unknown separately without converting it into a blanket repair rejection. My earlier concern is resolved. No remaining blocker from my review.
mayeut
left a comment
There was a problem hiding this comment.
Thanks for the follow-up but digging a bit more into this leads to _get_executable_stack_policy needing to handle the libc and architecture specific behavior.
The behavior per libc is as follow:
- musl: does not read
PT_GNU_STACKfor anything other than the stack size - android: if @mhsmith knows, I'd defer to his knowledge, I've not checked that one
- glibc:
- The following architectures default to executable stack given glibc source code (
grep -r DEFAULT_STACK_PROT_PERMS glibc-2.44 | grep -v ChangeLog | sort):armv7li686s390xx86_64
I've checked that a missingPT_GNU_STACKdoes indeed trigger a failure todlopenonx86_64but not onaarch64
- Regarding in which context we'd want to check this, it can become trickier if we don't apply some security rule on top of what exists for executables in Linux distros:
- For python extensions and their dependencies, we do want the check (dlopen).
- For executables and their dependencies, we don't want the check.
- If there are some "orphan" (not a python extension, an executable or one of their dependencies) .so in the wheel, we'll want to check them as well (they'll most likely be loaded with dlopen).
- The following architectures default to executable stack given glibc source code (
I've said in an earlier comment that I did not think we should be stricter than Linux distros but I did not think of the differences between python extensions, executables, "orphan" so. This is just adding too much complexity here and in this case, I'd rather be stricter:
- reject when explicitly executable on all libc / architecture
- on musl, ignore missing
PT_GNU_STACK - on glibc, missing
PT_GNU_STACKshould be handled per architecture to get the correct default value.
I missed that _get_executable_stack_policy re-opens ELF files to parse them again. This will be viewed as a regression speed-wise. It might be better to move elf_has_executable_stack in lddtree.py and add the relevant member to DynamicExecutable/DynamicLibrary.
|
I can see that the Android linker defaults to producing files with an PT_GNU_STACK header marked as non-executable. I don't know how strictly enforced this is at runtime, but given Android's increasingly tight attitude to security, I think auditwheel requiring an explicitly non-executable stack would be a good idea. |
|
Updated in 530e436: the stack requirement is now cached in the dependency tree, so policy evaluation no longer reopens ELF files. Missing headers follow the glibc architecture defaults, are allowed on musl, and require an explicit non-executable declaration on Android. Explicit executable requests remain rejected everywhere, including executables/orphan libraries; policy-specific grafting and no-graft handling are preserved. The installed x86_64 repair entry now rejects the missing-header case. Repeated unit runs retain the same 21 Windows baseline failures, with all 123 additional cases passing. Linux loader, native patchelf and Android runtime checks remain untested locally. |
| log.debug("processing: %s", fn) | ||
| elftree = ldd(fn, exclude=exclude, ldpaths=ld_paths_from_arg(args_ldpaths)) | ||
|
|
||
| if elftree.executable_stack is None: |
There was a problem hiding this comment.
Can we move this check after the architecture and libc checks? With the current order we could end up in a situation when an unrelated .so with incompatible architecture causes the wheel to fail the executable stack check.
There was a problem hiding this comment.
Good catch, @lkollar. I checked get_wheel_elfdata(): it adds the ELF to executable_stack / unknown_executable_stack before the architecture and libc checks can skip that file, so an incompatible .so can still affect the stack policy. Moving the collection after those checks makes sense. A regression with a foreign-architecture library that requests an executable stack would pin this down. Thanks for spotting it.
There was a problem hiding this comment.
Moved stack collection after the architecture and libc checks. The real-wheel regressions cover foreign/unknown architectures and incompatible libc, with missing, RW and RWX stack headers; compatible unsafe libraries remain rejected. All 24 new cases pass, including from the built wheel. Existing unit/bundled-wheel outcomes are unchanged on Windows (422 passed, 27 pre-existing platform failures).
Fixes #634.
Cache the nullable
PT_GNU_STACKrequirement inDynamicExecutable/DynamicLibrarywhile reading the dependency tree. Stack-policy evaluation now uses that metadata instead of reopening dependency ELF files.The check covers ELF files in the wheel, including executables and orphan libraries. External libraries only constrain policies which would actually graft them; the no-graft path remains separate. Missing-header diagnostics and JSON
nullretain the distinction between an absent declaration and an explicit non-executable one; a rejected target policy reportstrue.Validation of
530e43625ca55ad7984ad21eaf0574f6bd558c25on Windows Python 3.13:showcases cover seven glibc architectures, seven musl architectures and Android AArch64, with absent/RW/RWX headers. The x86_64repair --patcher noneentry now rejects the missing-header wheel which the submitted baseline allowed; explicit RW succeeds and RWX is rejected.libc.pyos.confstrerror.These are static ELF analysis and metadata-repair checks. Linux
dlopen, native patchelf repair, Android runtime enforcement, other Python/OS versions and physical multi-architecture execution were not run locally. Public CI and maintainer acceptance remain separate.Provenance correction: OpenAI Codex performed the investigation, implementation and automated verification; this text is also AI-generated. No personal human review or production use is claimed. The previous body’s “I reviewed the resulting diff” sentence was unsupported by verified evidence; this update removes that wording.