Skip to content

symcheck: Check for binaries requiring a writeable + executable stack#934

Merged
tgross35 merged 4 commits intorust-lang:mainfrom
tgross35:check-wx-sections
Feb 11, 2026
Merged

symcheck: Check for binaries requiring a writeable + executable stack#934
tgross35 merged 4 commits intorust-lang:mainfrom
tgross35:check-wx-sections

Conversation

@tgross35
Copy link
Copy Markdown
Contributor

@tgross35 tgross35 commented May 30, 2025

Implement the following logic:

  • For elf executable binaries, check for PT_GNU_STACK with PF_X. This
    combination tells the kernel to make the stack executable.
  • For elf intermediate objects, check for .note.GNU-stack with
    SHF_EXECINSTR. This combination in an object file tells the linker to
    give the final binary PT_GNU_STACK PF_X.
  • For elf intermediate objects with no .note.GNU-stack, assume the
    legacy behavior that assumes an executable stack is required.
  • For non-elf binaries, don't check anything. In a follow up it may be
    possible to check for MH_ALLOW_STACK_EXECUTION on Mach-O binaries,
    but it doesn't seem possible to get the latest compiler to emit this.

This appears to match what is done by scanelf to emit !WX 1, which
seems to be the tool used to create the output in the issue. The ld
manpage 2 also has some useful notes about these flags, as does the
presentation at 3.

Closes: #183

@tgross35 tgross35 force-pushed the check-wx-sections branch from ada5714 to 9f44c32 Compare May 30, 2025 02:44
@tgross35
Copy link
Copy Markdown
Contributor Author

Thumb makes sense to skip as a bare metal target. Note sure about ppc64

@tgross35

This comment was marked as outdated.

@tgross35

This comment was marked as outdated.

@tgross35
Copy link
Copy Markdown
Contributor Author

tgross35 commented Jun 2, 2025

@tgross35 tgross35 force-pushed the check-wx-sections branch 3 times, most recently from b6e06fd to fea76d5 Compare June 14, 2025 23:48
@tgross35 tgross35 force-pushed the check-wx-sections branch 12 times, most recently from ca874ea to fdb8c4e Compare September 12, 2025 09:07
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 10, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@tgross35 tgross35 force-pushed the check-wx-sections branch 5 times, most recently from 8a4a1e9 to f2baf7f Compare February 10, 2026 08:48
@tgross35 tgross35 force-pushed the check-wx-sections branch 17 times, most recently from 9268f62 to e011e5d Compare February 11, 2026 08:16
PE executables don't seem to have anything in the symbol table. Don't
assert that we find any symbols in this case, which allows using
symcheck for executable binaries.
@tgross35 tgross35 force-pushed the check-wx-sections branch 3 times, most recently from 5947bdf to 20b54c0 Compare February 11, 2026 20:33
Implement the following logic:

* For elf executable binaries, check for PT_GNU_STACK with PF_X. This
  combination tells the kernel to make the stack executable.
* For elf intermediate objects, check for `.note.GNU-stack` with
  SHF_EXECINSTR. This combination in an object file tells the linker to
  give the final binary PT_GNU_STACK PF_X.
* For elf intermediate objects with no `.note.GNU-stack`, assume the
  legacy behavior that assumes an executable stack is required.
* For non-elf binaries, don't check anything. In a follow up it may be
  possible to check for `MH_ALLOW_STACK_EXECUTION` on Mach-O binaries,
  but it doesn't seem possible to get the latest compiler to emit this.

This appears to match what is done by `scanelf` to emit `!WX` [1], which
seems to be the tool used to create the output in the issue. The ld
manpage [2] also has some useful notes about these flags, as does the
presentation at [3].

Closes: rust-lang#183

[1]: https://github.com/gentoo/pax-utils/blob/9ef54b472e42ba2c5479fbd86b8be2275724b064/scanelf.c
[2]: https://man7.org/linux/man-pages/man1/ld.1.html
[3]: https://www.ndss-symposium.org/wp-content/uploads/6D-s0924-ye.pdf
@tgross35 tgross35 changed the title Use symcheck to locate writeable+executable object files symcheck: Check for binaries requiring a writeable + executable stack Feb 11, 2026
@tgross35 tgross35 enabled auto-merge (rebase) February 11, 2026 20:42
@tgross35 tgross35 merged commit a7b1d8e into rust-lang:main Feb 11, 2026
38 checks passed
@tgross35 tgross35 deleted the check-wx-sections branch February 11, 2026 20:47
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.

Parts of libcompiler_builtins are compiled as WX

2 participants