Repository navigation
feat(binary-layout): admit ELF32 i386, ARM and MIPS layout profiles - #7052
Conversation
inspect_binary_layout refused every ELF32 object, so router and IoT firmware (ARM32, MIPS32) got no layout facts at all. The pwntools adapter now admits EXEC/DYN/REL objects in these profiles: ELF64 x86-64, ELF32 i386, ELF32 little-endian ARM and ELF32 little- or big-endian MIPS. Header fields are read in the declared byte order, the ELF32 header is bounds-checked at 52 bytes, and pwntools' own reported architecture, class and byte order must match the admitted profile. Other machines, classes and byte orders keep an unsupported_target refusal that names the admitted profiles. The output schema admits exactly those architecture combinations, and the Evidence subject now names the reported machine instead of always claiming x86_64. verify:binary:layout cross-compiles i386, ARM, MIPS and MIPSel executables and relocatable objects (never executed) and checks every section name, address, offset and size against GNU readelf through CLI and MCP. The real-binary-layout workflow installs those toolchains. Refs morluto#6934 Co-Authored-By: Claude Opus 5.5 <[email protected]>
--no-install-recommends skips the libc6-dev-*-cross packages the cross compilers only recommend, so the i686 fixture fell back to the host's /usr/include and failed to find bits/libc-header-start.h. Install the four target libc development packages explicitly. Refs morluto#6934 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The relocation reference check required a 24-byte Elf64_Sym entry, so every positive symbol reference in an ELF32 report was refused as unreadable output. Elf32_Sym is 16 bytes; take the minimum from the reported class. A 64-bit table with 16-byte entries is still refused. Refs morluto#6934 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The reviewed changes appear safe to merge, with the previous finding addressed and no new blocking issues found. SummaryAdds ELF32 i386, little-endian ARM, and little- or big-endian MIPS support to offline binary layout inspection.
Reviews (2) · Last reviewed commit: "test(binary-layout): compare ELF32 symbo..." · Reviewed by Greptile |
|
@salmanalmutairi1, thank you for extending offline binary layout inspection to the supported ELF32 i386, ARM and MIPS profiles. Reporting the target’s architecture in Evidence also makes those binary reports easier to interpret. Welcome to REA! |
Summary
Fixes #6934.
inspect_binary_layoutrefused every ELF32 object withunsupported_target, so ARM32 and MIPS32 router/IoT firmware got no layout facts. It now admits EXEC/DYN/REL objects in these profiles: ELF64 x86-64 (unchanged), ELF32 i386, ELF32 little-endian ARM and ELF32 little- or big-endian MIPS. Other machines, classes and byte orders still returnunsupported_target, and the message names the admitted profiles.Problem and expected behavior
bridge/pwntools/layout_impl.pyaccepted onlyEI_CLASS == ELFCLASS64,EI_DATA == ELFDATA2LSBande_machine == EM_X86_64, andbinaryLayoutSchemapinnedarchitecturetoEM_X86_64/ 64 / little. The rest of the adapter already goes through class- and byte-order-aware pyelftools structures (image.structs.Elf_Sym,Elf_Dyn, header sizes), so 32-bit and big-endian layouts need no other parsing change.Expected: an ELF32 ARM or MIPS executable returns the same layout report as an x86-64 one, with
architecturenaming its real machine, class and byte order.Change and scope
PROFILESmaps each admitted(e_machine, class bits, byte order)to the architecture pwntools must also report. The identification fields are read in the declared byte order, ELF32 headers are bounds-checked at 52 bytes, and pwntools' ownarch/bits/endianmust match the admitted profile after loading.architectureis a union of the exact admitted combinations, so a report such asEM_386/ 64 orEM_ARM/ big still fails validation.x86_64. It now follows the reported machine (x86_64,x86,arm,mips).verify:binary:layoutcross-compiles i386, ARM, MIPS and MIPSel executables and relocatable objects. They are never executed. The verifier compares section names, addresses, offsets and sizes with GNUreadelfthrough both CLI and MCP. It also compares every symbol value/size and every relocation offset, numeric type and symbol table/index reference, retaining table/entry identities and checking the oracle row counts. Thereal-binary-layoutworkflow installs the four cross toolchains.Not included: AArch64, ELF32 big-endian ARM, MIPS64/n32, x32, or any machine outside the list above. GOT/PLT maps and mitigation indicators still come from the unchanged upstream heuristics, and their completeness stays
unknown, as before.Follow the contribution scope. This widens target-format admission of an existing read-only offline operation. It adds no execution, injection or mutation authority. Whether widening
architectureneeds a maintainer scope decision is asked on #6934 and is still pending.Contract and boundary impact
PwntoolsLayoutProvider's Python adapter (layout_impl.py) owns target admission.binaryLayoutSchemaowns the output contract, andBinaryLayoutServicecomposes Evidence. No superseded path remains.architecturefield widens from one literal combination to five admitted combinations, and the tool description states the new profile.x86_64.Expected effects:
Evidence and regression coverage
src/domain/native/binaryLayout.test.ts: admits the four new combinations and rejects mismatched class/machine/byte-order combinations. It also accepts 16-byteElf32_Symentries for ELF32 relocations while still refusing undersized ELF32 entries and 16-byte entries in ELF64 reports.src/application/binaryDiagnostics/BinaryLayoutService.test.ts: the Evidence subject names the reported machine.scripts/verify-binary-layout.mjs: real ELF32 cases cross-checked againstreadelf. The existing AArch64 and coreunsupported_targetcases are kept.layout_impl.py:119-120refuses any object withEI_CLASS != 2before parsing, as quoted in inspect_binary_layout requires ELF64 LE; ELF32 targets get no layout profile and no named alternative #6934.inspect-binary-layout --jsonand MCP, that each cross-compiled fixture reportsarchitecture{EM_386, 32, little},{EM_ARM, 32, little},{EM_MIPS, 32, big}or{EM_MIPS, 32, little}and the expectedimage_type, and that every section's name, address, offset and size equals GNUreadelf -SW. A verbatim report excerpt was not captured from the CI log.unknownand not asserted.For evidence-bearing changes:
Validation performed
Review follow-up at
27dc69f93:npm run check, the pre-pushnpm run check:fast, Node syntax checking andgit diff --checkpassed on macOS (Node 24.22.1, npm 11.16.0). The new ELF32 symbol/relocation comparisons have not been run against the real provider: isolated Linux x64 setup was stopped after sustained dependency-download throttling, and dispatching the fork'sReal offline binary layoutworkflow was denied with HTTP 403. The successful real-provider run below covers the earlier1443a20revision.npx tsc -p . --noEmit(Windows 11, Node 24.18.0): passed.npm run test:local -- <17 binary-diagnostics source test files>: 231 passed, 2 skipped, 1 failed. The failure isByteEntropyService.test.ts"parent directory moves during streaming", which fails identically on the unchanged base on Windows (rename semantics) and is unrelated.npx oxlinton changed files: no new warnings compared with the base files.npm run verify:module-boundaries: passed.Pre-push hook (
typecheck,lint): passed.Real offline binary layoutworkflow on the fork (ubuntu-24.04, pinned pwntools 4.15.0 / pyelftools 0.33 / Unicorn 2.1.2):1443a20: passed. The verifier step took 232 s, covering the existing ELF64 cases and the eight ELF32 cases.b8426c9: the 20 existing ELF64 cases passed, then the first i686 report was refused asunreadable_outputbecause the relocation check required 24-byte (Elf64_Sym) symbol entries. This was fixed in1443a20, with regression cases inbinaryLayout.test.tsthat fail onb8426c9.ebaf7a4: the 20 existing ELF64 cases passed, then the i686 fixture failed to compile because--no-install-recommendsskipped the target libc headers. This was fixed inb8426c9.Not run locally:
npm run docs:checkand boundary tests (test:focused), because the Windows build needs native Windows artifacts absent from a source checkout.Compatibility, safety, and release
architecturewas alwaysEM_X86_64/ 64 / little will now also see the ELF32 combinations.Author readiness
Human owner: @salmanalmutairi1
Before merge
type(scope): outcome.