fix(relinker): give Linux guest modules a default non-executable stack #1506

Merged
kali113 merged 1 commit from upstream-pr/1506 into main 2026-10-10 01:05:35 +00:00
kali113 commented 2026-10-08 10:23:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kali113 on 2026-10-08T10:23:55Z.


What

Converted Linux guest libraries without PT_GNU_STACK can fail to load on glibc 2.41+: its absence is interpreted as an executable-stack requirement, and dlopen refuses it when the process stack is non-executable (glibc change).

Emit a default RW, non-executable stack header only when absent. Preserve explicit input headers, including executable flags and stack-size hints. The regression converts headerless, RW and RWX fixtures, verifies the output headers, and on Linux x86-64 loads the first two outputs, calls their export and verifies that the process stack remains non-executable. The original headerless input reproduces cannot enable executable stack as shared object requires; the fixed output loads and returns 42. The #1156 discussion encountered the same loader failure.

Rebuilt directly on main d70b8998: one commit, four files. No changes from #1265, #1913, #1986 or #1999 remain. Main's merged #1586 unwind-header constant is preserved. The stack change is independently mergeable.

Tested

Exact source head d5241d28: independent validation passes on native GitHub Linux and Windows runners, Release / GCC, including full default builds, all-library packaging and three repetitions of the relevant runtime tests under a 30-second limit. All three related tests execute on Linux and Windows; Linux x86-64 additionally performs native loading and checks process-stack permissions. Windows checks ELF conversion and headers.

These are fork validation jobs, not collaborator-dispatched upstream checks. Unrelated tests from the full suite were not run in this validation.

Local macOS 27.0.1 arm64, Apple Clang, Release relinker-only build: all 39 registered tests pass, longest 1.56 s. Native Linux loading is skipped on macOS and checked by Linux validation. Conventions and git diff --check pass.

Checklist

  • Based on main snapshot d70b8998; no other open PR implements this change
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4785318095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506). Originally posted by [kali113](https://github.com/kali113) on 2026-10-08T10:23:55Z. --- ### What Converted Linux guest libraries without `PT_GNU_STACK` can fail to load on glibc 2.41+: its absence is interpreted as an executable-stack requirement, and `dlopen` refuses it when the process stack is non-executable ([glibc change](https://sourceware.org/pipermail/glibc-cvs/2024q4/086970.html)). Emit a default RW, non-executable stack header only when absent. Preserve explicit input headers, including executable flags and stack-size hints. The regression converts headerless, RW and RWX fixtures, verifies the output headers, and on Linux x86-64 loads the first two outputs, calls their export and verifies that the process stack remains non-executable. The original headerless input reproduces `cannot enable executable stack as shared object requires`; the fixed output loads and returns 42. The #1156 discussion encountered the same loader failure. Rebuilt directly on `main` `d70b8998`: one commit, four files. No changes from #1265, #1913, #1986 or #1999 remain. Main's merged #1586 unwind-header constant is preserved. The stack change is independently mergeable. ### Tested Exact source head `d5241d28`: [independent validation](https://github.com/kali113/AnyPS5/actions/runs/37925995362) passes on native GitHub Linux and Windows runners, Release / GCC, including full default builds, all-library packaging and three repetitions of the relevant runtime tests under a 30-second limit. All three related tests execute on Linux and Windows; Linux x86-64 additionally performs native loading and checks process-stack permissions. Windows checks ELF conversion and headers. These are fork validation jobs, not collaborator-dispatched upstream checks. Unrelated tests from the full suite were not run in this validation. Local macOS 27.0.1 arm64, Apple Clang, Release relinker-only build: all **39 registered tests pass**, longest **1.56 s**. Native Linux loading is skipped on macOS and checked by Linux validation. Conventions and `git diff --check` pass. ### Checklist - [x] Based on `main` snapshot `d70b8998`; no other open PR implements this change - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, OpenAI Codex
klosixgaming-arch commented 2026-10-08 10:52:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T10:52:57Z.

Review: COMMENTED


This is a well-documented and thoroughly tested fix for a real glibc 2.41+ compatibility issue. The approach of adding a default non-executable PT_GNU_STACK header when absent is the standard solution.

Strengths:

  • Clear before/after comparison table showing the exact problem and fix
  • Extensive testing across multiple platforms (macOS, Debian container, native x86-64 Linux)
  • Proper handling of edge cases (explicit RWX headers preserved and still rejected by loader)
  • Comprehensive test suite that actually loads converted libraries via dlopen

Minor suggestions:

  1. Consider adding a comment explaining why flag value 6 is used (PF_R | PF_W = read-write, non-executable) for future maintainers
  2. The magic number 0x6474e551 could potentially be replaced with an ELF constant if available in the codebase's headers

Overall this looks ready to merge once any rebase conflicts are resolved. Good work on the thorough testing and documentation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455453861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#pullrequestreview-5455453861). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T10:52:57Z. **Review:** COMMENTED --- This is a well-documented and thoroughly tested fix for a real glibc 2.41+ compatibility issue. The approach of adding a default non-executable PT_GNU_STACK header when absent is the standard solution. **Strengths:** - Clear before/after comparison table showing the exact problem and fix - Extensive testing across multiple platforms (macOS, Debian container, native x86-64 Linux) - Proper handling of edge cases (explicit RWX headers preserved and still rejected by loader) - Comprehensive test suite that actually loads converted libraries via dlopen **Minor suggestions:** 1. Consider adding a comment explaining why flag value 6 is used (PF_R | PF_W = read-write, non-executable) for future maintainers 2. The magic number 0x6474e551 could potentially be replaced with an ELF constant if available in the codebase's headers Overall this looks ready to merge once any rebase conflicts are resolved. Good work on the thorough testing and documentation.
klosixgaming-arch commented 2026-10-08 11:27:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:27:04Z.

Review: APPROVED


Good improvement for Linux compatibility and security. Adding a GNU_STACK program header to converted guest modules ensures proper stack permissions (non-executable by default) which is important for modern Linux systems.

Strengths:

  • Clean implementation that preserves existing GNU_STACK headers if present, or adds one with non-executable flags (6 = PF_R | PF_W) if missing
  • Comprehensive test coverage including native dlopen execution on Linux x86-64 to verify stack permissions at runtime
  • Good documentation of the security implications in the PR description

Technical notes:

  • The approach of checking for existing GNU_STACK headers before adding a new one is correct
  • Proper use of PF_R | PF_W flags (non-executable) as the default
  • Test properly verifies both header presence and actual runtime stack permissions via /proc/self/maps

This will improve compatibility with modern Linux systems that expect or require the GNU_STACK header. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455828635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#pullrequestreview-5455828635). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:27:04Z. **Review:** APPROVED --- Good improvement for Linux compatibility and security. Adding a GNU_STACK program header to converted guest modules ensures proper stack permissions (non-executable by default) which is important for modern Linux systems. **Strengths:** - Clean implementation that preserves existing GNU_STACK headers if present, or adds one with non-executable flags (6 = PF_R | PF_W) if missing - Comprehensive test coverage including native dlopen execution on Linux x86-64 to verify stack permissions at runtime - Good documentation of the security implications in the PR description **Technical notes:** - The approach of checking for existing GNU_STACK headers before adding a new one is correct - Proper use of PF_R | PF_W flags (non-executable) as the default - Test properly verifies both header presence and actual runtime stack permissions via /proc/self/maps This will improve compatibility with modern Linux systems that expect or require the GNU_STACK header. Ready to merge.
kali113 commented 2026-10-08 12:29:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kali113 on 2026-10-08T12:29:05Z.


@klosixgaming-arch I will update both PRs at 22 CEST time. thanks for the comments and help!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059872390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#issuecomment-6059872390). Originally posted by [kali113](https://github.com/kali113) on 2026-10-08T12:29:05Z. --- @klosixgaming-arch I will update both PRs at 22 CEST time. thanks for the comments and help!
copilot-pull-request-reviewer[bot] commented 2026-10-08 20:04:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-08T20:04:45Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5462220143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#pullrequestreview-5462220143). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-08T20:04:45Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
kali113 commented 2026-10-08 20:14:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kali113 on 2026-10-08T20:14:42Z.


@adriadam10 Could you review this when you have time? I’ve rebased it onto current main, addressed the review suggestions, and marked it ready for review. Validation passes on Linux, Windows and macOS; the upstream checks are still queued. Thanks!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068225063 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#issuecomment-6068225063). Originally posted by [kali113](https://github.com/kali113) on 2026-10-08T20:14:42Z. --- @adriadam10 Could you review this when you have time? I’ve rebased it onto current main, addressed the review suggestions, and marked it ready for review. Validation passes on Linux, Windows and macOS; the upstream checks are still queued. Thanks!
adriadam10 commented 2026-10-10 01:05:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:05:33Z.


Checked the diff against the description: PT_GNU_STACK (RW) is emitted only when the input has none, explicit headers are kept as-is. linux_guest_stack passes with the change and fails without it; relinker CI is green on Linux, Windows and macOS; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091973912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1506#issuecomment-6091973912). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:05:33Z. --- Checked the diff against the description: `PT_GNU_STACK` (RW) is emitted only when the input has none, explicit headers are kept as-is. `linux_guest_stack` passes with the change and fails without it; relinker CI is green on Linux, Windows and macOS; merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1506
No description provided.