relinker: PT_GNU_STACK and PT_GNU_RELRO are dropped from Linux output #6394

Closed
opened 2026-10-15 13:56:07 +00:00 by midasmatterhorn · 1 comment
midasmatterhorn commented 2026-10-15 13:56:07 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by midasmatterhorn on 2026-10-15T13:56:07Z.


The Linux output silently drops PT_GNU_STACK and PT_GNU_RELRO. On x86-64 Linux a main executable without PT_GNU_STACK is loaded with an executable stack (EXSTACK_DEFAULT), and without PT_GNU_RELRO the GOT and .dynamic stay writable after relocation — both weaker than what the guest module asked for.

SegmentFilter::_isSceSpecificSegment (core/relinker/elfpatcher/src/general/SegmentFilter.cpp:6-16) treats everything in [PT_LOOS, PT_HIOS] as SCE-specific and drops it. PT_GNU_STACK (0x6474e551) and PT_GNU_RELRO (0x6474e552) live in that range; only PT_GNU_EH_FRAME is rescued at line 15. Evidence that the drop is not intended: LinuxGuestModuleWriter.cpp:25 deliberately adds a PT_GNU_STACK to guest-module output, and LinuxElfPatcher.cpp:100 carries a PT_GNU_STACK special case in RebaseProgramHeaders that is dead because the filter always removes the header first.

Reproduced with a relinker-only build of main 92cdc7b62 on macOS 27.0.1 arm64, on a minimal ET_EXEC fixture (code PT_LOAD + PT_DYNAMIC + four extra headers; default options, exit code 0 in every row):

input extra headers output segment types GNU_STACK kept GNU_RELRO kept
4x PT_SCE_VERSION (baseline) PT_LOAD, PT_DYNAMIC, PT_PHDR, PT_NOTE no no
one of them is PT_GNU_STACK (RW) unchanged no no
one of them is PT_GNU_RELRO unchanged no no

Suggested fix: keep PT_GNU_STACK (its addresses are 0, RebaseProgramHeaders already handles it) and PT_GNU_RELRO (rebase its range like a PT_LOAD); or, if the input lacks one, synthesise a non-executable PT_GNU_STACK as LinuxGuestModuleWriter does.

Found by an AI-assisted audit (DeepSeek V4.1 Flash via OpenCode); every row above was executed against the real relinker binary. I can send the fix with regression tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5867514167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6394). Originally posted by [midasmatterhorn](https://github.com/midasmatterhorn) on 2026-10-15T13:56:07Z. --- The Linux output silently drops `PT_GNU_STACK` and `PT_GNU_RELRO`. On x86-64 Linux a main executable without `PT_GNU_STACK` is loaded with an executable stack (`EXSTACK_DEFAULT`), and without `PT_GNU_RELRO` the GOT and `.dynamic` stay writable after relocation — both weaker than what the guest module asked for. `SegmentFilter::_isSceSpecificSegment` (core/relinker/elfpatcher/src/general/SegmentFilter.cpp:6-16) treats everything in `[PT_LOOS, PT_HIOS]` as SCE-specific and drops it. `PT_GNU_STACK` (`0x6474e551`) and `PT_GNU_RELRO` (`0x6474e552`) live in that range; only `PT_GNU_EH_FRAME` is rescued at line 15. Evidence that the drop is not intended: `LinuxGuestModuleWriter.cpp:25` deliberately adds a `PT_GNU_STACK` to guest-module output, and `LinuxElfPatcher.cpp:100` carries a `PT_GNU_STACK` special case in `RebaseProgramHeaders` that is dead because the filter always removes the header first. Reproduced with a relinker-only build of `main` `92cdc7b62` on macOS 27.0.1 arm64, on a minimal `ET_EXEC` fixture (code `PT_LOAD` + `PT_DYNAMIC` + four extra headers; default options, exit code 0 in every row): | input extra headers | output segment types | GNU_STACK kept | GNU_RELRO kept | | --- | --- | --- | --- | | 4x `PT_SCE_VERSION` (baseline) | `PT_LOAD, PT_DYNAMIC, PT_PHDR, PT_NOTE` | no | no | | one of them is `PT_GNU_STACK` (RW) | unchanged | no | no | | one of them is `PT_GNU_RELRO` | unchanged | no | no | Suggested fix: keep `PT_GNU_STACK` (its addresses are 0, `RebaseProgramHeaders` already handles it) and `PT_GNU_RELRO` (rebase its range like a `PT_LOAD`); or, if the input lacks one, synthesise a non-executable `PT_GNU_STACK` as `LinuxGuestModuleWriter` does. Found by an AI-assisted audit (DeepSeek V4.1 Flash via OpenCode); every row above was executed against the real `relinker` binary. I can send the fix with regression tests.
MarcZX10 commented 2026-10-15 14:12:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T14:12:49Z.


The reported headers are dropped on current main. PR #6406 keeps both PT_GNU_STACK and PT_GNU_RELRO through segment filtering and adds normal/fixed-base integration coverage. The new CTest passes, and it fails against the current unmodified relinker because PT_GNU_STACK is missing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6194162873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6394#issuecomment-6194162873). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-15T14:12:49Z. --- The reported headers are dropped on current main. [PR #6406](https://github.com/boykopovar/AnyPS5/pull/6406) keeps both `PT_GNU_STACK` and `PT_GNU_RELRO` through segment filtering and adds normal/fixed-base integration coverage. The new CTest passes, and it fails against the current unmodified relinker because `PT_GNU_STACK` is missing.
Sign in to join this conversation.
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#6394
No description provided.