Conversation
… p_memsz arm64 --pie binaries died at startup on native 4K/16K-page kernels: `mprotect of the PT_GNU_RELRO region failed`, SIGTRAP (mach#1885). The ELF writer rounds PT_GNU_RELRO p_memsz up to the IMAGE max-page (64 KiB on aarch64, mach#1845), but the kernel maps the tiny .data.rel.ro segment rounded to the RUNTIME page; on a runtime page smaller than the image max-page the re-protect spanned the unmapped tail and faulted ENOMEM. mach-std#347 made that fatal. Take the extent from the RELRO segment's backing PT_LOAD (its actual mapped size) instead of the writer's rounded p_memsz, and round it up to AT_PAGESZ in relro_reprotect - the pages the kernel actually mapped. The rounding now lives against the runtime page, not the build-time max-page. #347's fatal semantics stay: AT_PAGESZ absence, a region with no backing segment, a misaligned start, or an mprotect failure each panic naming the invariant. Update the negative-path probe to force a misaligned start (the congruence gate is gone).
Collaborator
Author
Verified on native arm64 (scratch CI, GitHub 4 KiB-page aarch64 runner)Runtime fix alone repairs already-released binaries — probe built with the RELEASED mach (unchanged 64K writer) + this branch:
Full fix (this + the mach writer PR mach#1888) — probe built with both:
CI green (build + cross-arm64 + cross-riscv64, incl. the relro probe). This PR is the crash fix and is sufficient on its own to make mach's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the critical arm64 startup crash briar-systems/mach#1885. Std side of the fix; the mach writer side (honest PT_GNU_RELRO p_memsz) follows per the release/pin choreography.
Root cause (errno evidence, native arm64)
On a native 4 KiB-page aarch64 kernel,
--piebinaries died at startup:mprotect of the PT_GNU_RELRO region failed, SIGTRAP (exit 133). The ELF writer roundsPT_GNU_RELROp_memsz up to the IMAGE max-page (64 KiB on aarch64, mach#1845), but the kernel maps the tiny.data.rel.rosegment rounded to the RUNTIME page (4 KiB). The re-protect then mprotected 64 KiB starting at a segment only one 4 KiB page is mapped for → spanned the unmapped gap up to the next 64K-aligned segment →ENOMEM. mach-std#347 made that fatal.Evidence (GitHub arm64 runner, 6.17.0-azure, PAGE_SIZE 4096):
readelfshows.data.rel.roLOAD MemSiz0x10butGNU_RELROMemSiz0x10000;straceshowsmprotect(…, 65536, …) = -1 ENOMEM.Fix
_rt_relocatenow takes the re-protect extent from the RELRO segment's backingPT_LOAD(its actual mapped size), andrelro_reprotectrounds that up toAT_PAGESZ— the pages the kernel actually mapped. The rounding lives against the runtime page, not the build-time max-page. PT_GNU_RELRO covers exactly the.data.rel.roload segment in mach's layout, so that segment's p_memsz is the authoritative region size; the runtime does not rely on the writer's over-rounded p_memsz, so this repairs already-released v2.14.0 binaries on rebuild (no new mach release needed).#347's fatal semantics stay: an absent AT_PAGESZ, a region with no backing segment, a misaligned start, or an mprotect failure each panic naming the invariant — no silent-unhardened path.
Verification
EXIT=42(hardened),mprotect(…, 4096, …) = 0— was65536 = -1 ENOMEM/ exit 133.mach build .+mach test .green (620/620);test/relro/verify.shgreen (happy exit 42; fault forces a misaligned start → panic + death by signal). Cross-arch qemu green.int linux-arm64(native) once this is pinned.🤖 Generated with Claude Code