Skip to content

Fix PHDR coverage after repeated executable rewrites - #679

Merged
domenkozar merged 2 commits into
masterfrom
fix-header-load-pht-growth-675
Oct 30, 2026
Merged

domenkozar merged 2 commits into
masterfrom
fix-header-load-pht-growth-675

Conversation

@domenkozar

Copy link
Copy Markdown
Member

Repeated ET_EXEC rewrites can grow the program header table past the header LOAD after splitting NOTE segments. Looking up the LOAD by the table's start lets patchelf reuse and extend it, fixing invalid PHDR coverage on x86_64 and the subsequent AArch64 assertion failure.

Applies Jacob Michels' fix from 964670e with original authorship preserved. Adds an unreleased changelog entry and extends the regression test with a third rewrite. Prepared and validated with Codex assistance.

Validation:

  • Reproduced the reported Grpc.Tools 2.83.0 failures on x86_64 and AArch64 ELF files; all three rewrites have clean readelf output with the fix. AArch64 binaries were not executed.
  • Full test suite: 68 passed, 5 skipped. Separate property test: 25 passed, 0 failed, seed 675.
  • Extended regression test and ShellCheck pass; git diff --check is clean.

Fixes #675.

rewriteSectionsExecutable() looked up the header LOAD by the offset just
past the program header table. A previous rewrite sizes that LOAD with
only a few bytes of slack after the table. When normalizeNoteSegments()
then splits a multi-note PT_NOTE, the table grows past the LOAD's end,
so the lookup finds nothing: the LOAD is neither reused nor extended and
older LOADs are not trimmed. The PHDR segment is left outside any LOAD,
and a relocated .dynamic can land in a read-only mapping, so ld.so
crashes writing DT_DEBUG.

The table always starts right after the ELF header, so look the LOAD up
there instead.

Fixes #675.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@domenkozar
domenkozar enabled auto-merge October 30, 2026 16:05
@domenkozar
domenkozar added this pull request to the merge queue Oct 30, 2026
MIPS default linker scripts leave .interp as an orphan, so INSERT AFTER .interp fails before the test suite can run. Anchor the test notes before .dynsym instead, keeping them before .dynstr so the regression still exercises program header growth.
@domenkozar
domenkozar removed this pull request from the merge queue due to a manual request Oct 30, 2026
@domenkozar
domenkozar added this pull request to the merge queue Oct 30, 2026
@domenkozar
domenkozar removed this pull request from the merge queue due to a manual request Oct 30, 2026
@domenkozar
domenkozar enabled auto-merge October 30, 2026 16:24
@domenkozar
domenkozar added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit 2f0aba6 Oct 30, 2026
30 checks passed
@domenkozar
domenkozar deleted the fix-header-load-pht-growth-675 branch October 30, 2026 16:40
@domenkozar domenkozar mentioned this pull request Oct 30, 2026
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.

PHDR segment not covered by a LOAD segment after repeated rewrites

2 participants