Repository navigation
feat(native): report binary hardening for ELF, PE and Mach-O - #8524
Conversation
Documents inspect_binary_hardening and its CLI equivalent, including per-property states, supporting evidence, read budgets, and one report per Mach-O slice. Explains that missing protection imports remain unknown, signature presence does not establish validity, and hardened runtime requires inspect_signature. Adds hardening links throughout the documentation. The supplied diff also removes the advanced CodeQL workflow and configuration, along with snapshot-binding mismatch guidance.
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; the local-symbol false positive is fixed. SummaryAdds
Reviews (19) · Last reviewed commit: "fix(native): ignore STB_LOCAL undefined ..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 628dd00064
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…dening rows Run the shared range checks for ELF, read imports from the dynamic tables rather than section metadata, and keep an unresolved symbol count apart from an absent table. Check every Mach-O command before building rows and retain only the offsets the rows need. Make the verifier's readelf output wide, check the emitted format before parsing Mach-O, and place the sources before the libraries in the link.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac82932e07
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A segment with a section count its cmdsize cannot hold passed the hardening reader and could enable restrict_segment. Move the size, section count and file range checks to a shared admission that readMachoImage and the hardening reader both use, and pin the ELF load-size case with a regression test.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c4959ac11
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ty ELF interpreters Segment admission never checked each section's payload range, so a file-backed section past the slice still produced rows. Decode sections with the section header owner and mark the slice malformed when a payload leaves it; zero-fill and empty sections own no file bytes and are exempt. admitInterp accepted a NUL first byte in a longer extent, which counted an empty interpreter as PIE evidence. It now requires a nonempty path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KuWHGvzJkrhCqjtEHUwqyH
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1bd079f589
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use the IMAGE_GUARD_CF_INSTRUMENTED flag that guardFlagRecord already decodes instead of masking the raw GuardFlags word a second time.
…g-inspection # Conflicts: # docs/index.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12c6226434
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The hardening reader mapped DT_STRTAB, DT_SYMTAB and hash tables through the one PT_LOAD containing the table's first address. A second PT_LOAD starting inside the table could map the rest of it from other file bytes and the reader still reported parsed import evidence. Cap each mapping at the next PT_LOAD that starts inside it, reject a requested range that crosses that boundary, and stop hash reads at the same limit, matching the conflicting-mapping refusal in readElfSymbols.
The hardening reader dropped any note table whose bytes another table already covered. A covering SHT_NOTE can hold a non-GNU note whose descriptor is itself a complete GNU property note, while PT_NOTE names that inner note directly. Walking only the outer stream missed the GNU marker and reported CET disabled. Drop an alias only when it starts and ends on boundaries of admitted tables, which are note boundaries of the walked streams. Any other covered alias leaves the feature rows unknown, as a partial overlap already does.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afe6f7cf04
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The Mach-O stack protector scan returned as soon as it found an undefined ___stack_chk_fail, so a later undefined symbol whose n_strx lay outside the string table was never checked. The same damaged table parsed or failed as malformed depending only on record order. Keep the match and finish the bounded record walk. Records after the match are only checked against the string table bounds, so their names are not read or charged to the scan budget. The ELF reader already admits its whole symbol table before matching names.
The hardening reader treated every PT_LOAD that starts inside a table, or that also contains the table's address, as a conflicting mapping. A load with the same address-to-file translation names the same file bytes, so tables it overlaps still have one interpretation, and the canonical ElfLoadMap already merges such spans. Treat equivalent loads as one interpretation. A load with a different translation, or the zero-filled tail of an equivalent load, still ends the usable range, so a remapped table is still rejected.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e1c82adc4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… unknown A section and a program header that share endpoints were treated as one note stream even when their effective note alignments differed. Walking the same bytes at 4 and 8 can frame different notes, so dropping the second table could hide a GNU property word and report CET or BTI as disabled. Require matching effective alignment at both endpoints, and no alignment change inside the covered span, before treating a table as an alias. Otherwise mark the feature rows unknown. The fixture's .note.gnu.property section now declares the class's note alignment, as toolchains emit it.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f07dcdb88
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Move the Mach-O fixed uint32 command layouts out of MachoCommandNames into domain/apple/machoLoadCommands so there is one owner of those offsets. MachoCommandNames and the hardening reader now both decode through it; the hardening reader keeps its own bounds and import policy.
A common definition sets N_UNDF|N_EXT like an import but stores its allocation size in n_value. An object holding only `int __stack_chk_fail;` therefore reported stack_protector: enabled. Require a zero n_value before an undefined external counts as an import, for both nlist widths.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a7e0c13a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The binary hardening verifier started its probes and compiler drivers with raw spawnSync, which bypassed the src/process/ supervision that AGENTS.md requires. Every launch now goes through createVerifierCommands, and the temporary root is removed only after the owner closes cleanly.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
SIGINT or SIGTERM ended Node before withVerifierCleanup ran, so detached compiler trees and the temporary root could outlive the verifier. The verifier now turns those signals into an abort that every owned command receives, so cleanup closes the owner and removes the root before exit.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
… a command Only the owned commands read the interruption signal, so a SIGINT or SIGTERM during the final cleanup or between commands was recorded and then dropped, and the verifier exited 0. After cleanup settles, the verifier now throws the interruption reason. A failure the operation or its cleanup already raised still leaves first and is not replaced.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Resolve the docs/index.md guide table conflict by keeping main's rows, including the new wxapkg link, and re-adding the Binary hardening link.
|
Hey @mvanhorn, thanks for the PR! This addition looks good to me. What's left: it has merge conflicts with main in |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
The hardening reader turned every malformed status from the shared encryption reader into an unknown `encrypted` row, so a short LC_ENCRYPTION_INFO_64 or an encrypted range past the slice still left the slice parsed with a full report. Only two conflicting encryption commands stay an unknown row now. Any other encryption defect fails the slice like other structural command failures.
|
Merged main in eaabca0, which clears the |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
A local undefined __stack_chk_fail or __memcpy_chk is never resolved against another object, so it does not establish an external import. Skip STB_LOCAL bindings when reading protector signs, and give the fixture's positive symbols STB_GLOBAL binding.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
gensokyo-dev
left a comment
There was a problem hiding this comment.
Verified head 401b6e76c combined with current main ec3410998 on Linux x64, Node 24.22.1 / npm 11.16.0. No additional production changes were needed.
The two remaining review findings are already addressed: readCommandFacts frames all Mach-O commands but retains only restriction/signature offsets and one symbol-table command; ELF undefined-import scanning consumes readElfSymbol (including its binding and section facts), rather than re-decoding the layout. The obsolete retained-command array and parallel ELF symbol decoder are absent.
Executed verification:
- 253 tests passed across 12 source files covering hardening, shared ELF/Mach-O/PE parsers and consumers.
- 171 tests passed across public CLI/MCP, filesystem and stable-reader boundaries (4 files).
- The real compiler/readelf verifier passed all 10 ELF variants: PIE/non-PIE, full/partial/no RELRO, stack protector, executable stack, build ID, dynamic linking and two dependencies. Native Mach-O tooling is unavailable on this Linux host; PE coverage here is fixture-based.
- Public CLI against
/usr/bin/ls(SHA-256cb30d69b24245bf2ecdc9e7f53bbad19159999970b6d82c0c00c7d32d9e37aa4) returned 10 evidence-bearing rows in 4,457 bytes, matching the inspected ELF facts: PIE/NX, partial RELRO and imported stack-protector/fortify markers. Elapsed 1.744s, user/system CPU 1.789/0.159s, sampled peak process-family RSS 208 MiB (200ms samples; includes startup; not a before/after speed or token claim). - Single-thread syntax lint of all 54 changed TS/MJS files passed (0 errors, 91 warnings).
Resource limitation: the full check:fast invocation was stopped at the explicit 4 GiB process-family RSS guard (sample 4.10 GiB), before OOM. It is not a full local static-check pass; focused lint passed after inspecting the stopped task. Build plus boundary verification peaked at 2.12 GiB. Existing head CI remains the full-suite evidence. No Windows or real macOS run was performed here.
gensokyo-dev
left a comment
There was a problem hiding this comment.
Automated verification under the user-authorized gensokyo-dev account: reviewed the shared parser ownership and bounded fact collection; 253 source and 171 public/boundary tests plus 10 real compiler/readelf variants passed. The package.json change only adds the opt-in hardening verifier command; no dependency or install-hook change. Full verification and local resource-stop limitations are recorded in my preceding review. This is an agent review, not an author human-readiness attestation.
|
Measurement correction (no production change): the earlier profiler recorded final
The hardening rerun again inspected the unchanged system |
|
@gensokyo-dev thanks for merging this - glad REA can now report PIE, NX and RELRO across ELF, PE and Mach-O with inspect_binary_hardening instead of needing a separate tool per format. |
Summary
REA can report ELF mitigations today only through caller-supplied pwntools on Linux x64, and it has no equivalent for PE or Mach-O.
MH_PIEandDllCharacteristicsare not read anywhere. Checking one binary's hardening means installing a separate tool per format.This adds
inspect_binary_hardeningandrea inspect-binary-hardening, a built-in read of headers, program tables and imports. It works on any host, reports each universal Mach-O slice separately, and never runs the target. No issue is linked. This is a proposed new read-only tool.Problem and expected behavior
Use case: an analyst triaging a binary wants one answer for PIE, NX, RELRO, stack protector, and the format's other mitigations, with evidence for each row.
Observable outcome:
enabled,disabled,partial,unknownornot_applicable, a confidence, a basis sentence and a file location.__stack_chk_failimport in a static or stripped image leavesstack_protectorunknown, because the absence does not establish that canaries are off.PT_LOAD,PT_INTERPor section past EOF, an empty or unterminatedPT_INTERP, a truncated Mach-O command, a Mach-O segment that fails size, section count or file range admission, or signature data outside the slice returns no partial report, so rows that look complete cannot come from a damaged image. Debug-only ELF files whosePT_LOADsizes exceed the file may be reported as malformed. That is from reading the code, not a run.DT_SYMTABandDT_STRTAB.SHT_DYNSYMonly supplies a count when it agrees with those tables, and withoutDT_SYMTABthe import rows areunknown.Change and scope
Readers live in
src/native/hardening/, one each for ELF, PE and Mach-O, withBinaryHardeningProvider.tsabove them.src/domain/native/binaryHardening.tsowns the report and its allowances. The tool is registered in the existing binary diagnostics group.These changes reach existing owners:
src/domain/elfHashSymbolCount.tsmoves ELF hash-table symbol counting out ofsrc/flutter/DartElf.tsso both readers share one bounded walk. An emptyDT_GNU_HASHnow returns an indeterminate count instead ofsymoffset, because undefined imports can extend past it.DartElfreports that as a failure instead of reading a short table.src/domain/peOptionalHeader.tsandsrc/domain/binaryTarget.tsexpose PE fields that hardening needs.src/native/metadata/andsrc/native/elf/ElfNoteParser.tsexpose section and note facts.src/domain/elfProgramHeader.tsgains a sharedadmitElfLoadSegment, used byElfImageand the hardening reader.src/domain/apple/machoLoadCommands.tsandsrc/artifacts/apple/MachoLoadCommandReader.tssharereadMachoLinkeditDataCommand.src/domain/apple/machoSegmentHeader.tsgainsadmitMachoSegmentCommand, andreadMachoImagenow shares that admission with the same messages and check order.GNU property notes are found by owner and type, not section name, so a renamed
SHT_NOTEcannot hide CET flags. Overlapping note tables that leave uncovered bytes make the rowunknown. Sectionless ELF reads validate the complete span against file-backed mappings, and hash reads resolve their mapping once.Not included: running the target, kernel or runtime mitigation state, source fortification analysis, or a score.
native.hardeningon the audit tool can point here later, but this PR does not depend on it.Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
src/native/hardening/readers over existing native metadata owners.inspect_binary_hardeningtool andinspect-binary-hardeningcommand. Catalog, README and localized README counts are updated.DartElfkeeps its contract except for the emptyDT_GNU_HASHcase above.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): additive tool count and onepackage.jsonverifier script. No build output is committed.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/native/hardening/andsrc/domain/,DartElftests, CLI acceptance tests and MCP boundary tests.npm run verify:binary-hardeningcompiles real ELF targets with zig and inspects them without running them, reads macOS system binaries and checks a PE fixture.docs/verification/binary-hardening-2026-10-31.mdholds the record.rea inspect-binary-hardening ... --jsonon this commit. The demo below is a rendered walkthrough of these results, not a screen recording.readelfwas not available, so ELF rows were not compared with it. The compilers here did not emit an ELF with an undefined dynamic__stack_chk_failor an executablePT_GNU_STACK, sostack_protectorenabled and NX disabled on ELF are covered by fixtures. PE rows come from a built fixture, not a Windows toolchain.hardened_runtimestaysunknownfrom this reader;inspect_signatureowns that fact.docs/verification/binary-hardening-2026-10-31.mdpredates a later verifier change (readelf --wide, link order, emitted format checks), and those Linux paths have not been run:readelf, GNU ld, and Linux gcc and clang are absent on this macOS host. Separately, zig-built x86_64 and aarch64 ELFs with real undefined__stack_chk_failand__memcpy_chkreportedenabled.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
For evidence-bearing changes:
Demo
Validation performed
Run on this commit on macOS with Node 24.22.1 and npm 11.16.0:
npm run test:localon the changed source tests: 231 passed, plus 517 on theMachoImageconsumers.npm run test:focusedon the changed acceptance and boundary tests: 177 passed.npm run verify:binary-hardening: passed.typecheck,lint,lint:typed(0 errors),format:check,metadata:check,verify:architecture-guards,verify:test-discovery,knip:productionanddocs:check: passed.npm run checkstops atknipon one unused exported type atsrc/process/DarwinHelperCache.ts:465. This PR does not touch that file, and it failed the same way onmainin this environment.Compatibility, safety, and release
DartElfnow fails rather than readingsymoffsetentries on an emptyDT_GNU_HASH.package.jsonscript. No new runtime dependency.Author readiness
Human owner: @mvanhorn
Before merge
type(scope): outcome.AI was used for assistance.