Skip to content

tests: add property test for binary-preserving rewrites - #651

Merged
Mic92 merged 5 commits into
masterfrom
property-testing
Jun 25, 2026
Merged

Mic92 merged 5 commits into
masterfrom
property-testing

Conversation

@Mic92

@Mic92 Mic92 commented Jun 24, 2026

Copy link
Copy Markdown
Member

The existing fuzz harness feeds mostly-invalid bytes looking for crashes. This adds the complementary property: applying patchelf operations to a valid, runnable binary must leave it runnable.

It builds dynamic executables with randomized layout/link options (page size, separate-code, relro, hash style, build-id, PIE), applies a random sequence of rpath/needed/interpreter/replace-needed operations, and runs the binary after each one. Dependencies are resolved via LD_LIBRARY_PATH so rpath edits exercise the section rewrite without changing whether libs are findable, and each case verifies the freshly built binary runs before patching so a build hiccup is skipped rather than reported as a regression.

@Mic92
Mic92 force-pushed the property-testing branch 9 times, most recently from 4a3e1df to 0313317 Compare June 25, 2026 12:50
@Mic92
Mic92 added this pull request to the merge queue Jun 25, 2026
@Mic92
Mic92 removed this pull request from the merge queue due to a manual request Jun 25, 2026
@Mic92
Mic92 force-pushed the property-testing branch from e044887 to 0b9858d Compare June 25, 2026 15:13
@Mic92
Mic92 enabled auto-merge June 25, 2026 15:32
@Mic92
Mic92 disabled auto-merge June 25, 2026 15:32
Mic92 and others added 5 commits June 25, 2026 15:34
PR #645 fixed --remove-rpath but --remove-needed has the same in-place
compaction and the same bug: DT_MIPS_RLD_MAP_REL stores the offset to
.rld_map relative to its own .dynamic slot, so when the slot moves the
value must be adjusted, and rewriteSections() does not run because no
section was replaced.

Factor the shared compact-and-adjust loop into compactDynamic() and use
it from both callers. The regression test recomputes the loader's
invariant from readelf output, so it does not need to execute the binary
and runs on any host with a MIPS toolchain.
Relocated sections are written into the reserved area at the start of the
file and inherit the permissions of the LOAD segment already covering it.
For a non-PIE executable that fits the relocation without growing the file
(e.g. linked with a large max-page-size), a writable section such as
.dynamic ends up read-only and the loader segfaults writing DT_DEBUG.

Make that segment writable. If it is executable, prefer to grow the file so
shiftFile splits the reserved area into its own R/W segment and avoids W+X;
fall back to marking the segment writable only when there is no room below
the load address to add pages.

Found by tests/property-rewrite.sh.
The existing fuzz harness feeds mostly-invalid bytes looking for crashes.
This adds the complementary property: applying patchelf operations to a
valid, runnable binary must leave it runnable.

It builds dynamic executables with randomized layout/link options (page
size, separate-code, relro, hash style, build-id, PIE), applies a random
sequence of rpath/needed/interpreter/replace-needed operations, and runs
the binary after each one. Dependencies are resolved via LD_LIBRARY_PATH so
rpath edits exercise the section rewrite without changing whether libs are
findable, and each case verifies the freshly built binary runs before
patching so a build hiccup is skipped rather than reported as a regression.
Add a Debian/glibc job for mips64le, which has no musl/Alpine image. It is test-only (no release artifact) and runs the suite under QEMU, exercising patchelf's MIPS-specific paths (DT_MIPS_RLD_MAP_REL, .MIPS.options, etc.). The property test uses a reduced ITERS there since QEMU emulation is slow.
The nix jobs (hydraJobs.release, tarball, win32/win64 cross) rebuild from
scratch on every run. hestia turns the GitHub Actions cache into a Nix
binary cache with no extra accounts or secrets, so later runs substitute
what earlier runs built.

The full closure is cached (no upstream filter): the org's Enterprise plan
is not bound by the public 10 GB quota, and a local mirror of the nixpkgs
paths is faster than round-tripping to cache.nixos.org.

A daily GC workflow keeps the default-branch scope from growing without
bound; PR-scoped caches die with their branch already.
@Mic92
Mic92 force-pushed the property-testing branch from 0b9858d to 9ef7d6b Compare June 25, 2026 15:39
@Mic92
Mic92 enabled auto-merge June 25, 2026 15:40
@Mic92
Mic92 added this pull request to the merge queue Jun 25, 2026
Merged via the queue into master with commit 708057b Jun 25, 2026
30 checks passed
@Mic92
Mic92 deleted the property-testing branch June 25, 2026 16:21
@domenkozar domenkozar mentioned this pull request Jun 26, 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.

1 participant