Repository navigation
refactor(native): select ELF sections through the keyed owner - #10780
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
[High impact] Appears safe to merge; the remaining guard false positive is non-blocking. SummaryThis PR moves ELF section selection through
The previous-review ancestry checks failed, so this review covered the full PR. Source checks and small guard examples were checked; the full test suite was not rerun. No new security finding was established. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Parsed declarations] --> B[keyedBy]
B --> C[uniqueKeyed]
B --> D[allKeyed]
B --> E[firstKeyed or lastKeyed]
C --> F{Repeated key?}
F -->|No| G[Read the selected declaration]
F -->|Yes| H[Refuse or report unknown data]
D --> I[Keep every matching declaration]
E --> J[Apply the stated precedence rule]
Reviews (7) · Last reviewed commit: "fix(verify): count a filter index only o..." · Reviewed by Greptile |
… the keyed owner (#10847) * refactor(native): select the GOT base and dependency segments through the keyed owner resolveGotBase selects the SHT_DYNAMIC section and the allocated .got.plt/.got sections with uniqueKeyed, so a repeat leaves the GOT base unknown instead of taking the first match; elfDependencies reads PT_LOAD segments through the same keyed program table as PT_DYNAMIC. A new keyed-first-match guard recognizes a find/findLast or filter-then-[0] whose predicate compares a key field, whatever the table is called; existing matches are baselined. The unwind fixture can declare PT_DYNAMIC headers and repeated .dynamic/.got.plt sections. * test(native): pin the PT_DYNAMIC path and destructured keyed lookups The keyed-first-match guard moves to scripts/verify/keyed-first-match.mjs with focused tests, and now recognizes a destructured key in any position and a destructured filter predicate. The single PT_DYNAMIC unwind test declares .dynamic as SHT_PROGBITS so only the program header supplies DT_PLTGOT, and asserts the resolved ranges. * fix(macho): refuse repeated chained-fixup and dyld-info tables (#10850) parseMachoLayout kept the last LC_DYLD_CHAINED_FIXUPS range and merged the rebase/bind streams of every LC_DYLD_INFO(_ONLY) command. A repeat now refuses the slice as malformed. NativeMachoInspection's chained import-name reader already declined repeated LC_DYLD_CHAINED_FIXUPS; that rule is now covered by a test.
d1a105e to
b173b5e
Compare
Summary
Second
Keyed<T>slice after #10740. ELF section lookups that kept the first of repeated declarations throughsections.find(...)now go throughsrc/domain/keyedCollection.ts. The owner gains theallKeyedselector andfirstKeyed/lastKeyedselectors that require a stated precedence rule. A counted architecture guard stops newsections.find(lookups.Refs the W7 duplicate-key workstream (structural audit report 06, finding 5). #10740 (the owner) is merged.
This PR also carries collapsed stacked PRs:
FROZEN_OBJECT_REGIONkeeps the directory and reads neither region (was: directory treated as absent).status: "partial"with the newNativeAotReasoncodeambiguous_frozen_object_region(coordinator-approved additive contract change). A missing frozen region stayscomplete.sections.findlookup is retired and the guard baseline reaches zero.PT_DYNAMICheaders (elfDependenciesrefuses;resolveGotBaseleaves the GOT base unknown) and repeatedLC_DYLD_CHAINED_FIXUPScommands (refused) are selected throughuniqueKeyed; the guard now also coversprograms.findandcommands.find.Problem and expected behavior
Trigger: an ELF shared object that declares two
SHT_DYNSYMsections, or twoSHT_GNU_VERNEEDsections.Before:
inspect_native_exportsread whichever section came first and reported complete exports and version names.ElfHardeningalready refused twoSHT_DYNSYMsections as malformed for the same image, so the two tools disagreed.After:
SHT_DYNSYMsections: the export parser refuses the image as malformed withELF image has more than one SHT_DYNSYM, which matchesElfHardening.SHT_GNU_VERNEEDorSHT_GNU_VERDEFsections: the parser reads neither table and records aversion_unresolvedissue (Version requirements: the ELF declares 2 sections of this type, so none was read). A repeated definition table also clears requirement names, following the existing rule that an unread definition table may replace any requirement index.SHT_GNU_VERSYMlinked to the dynamic symbol table: versions becomeunknownand aversion_unresolvedissue is recorded.Images with one section of each type behave exactly as before.
Change and scope
src/domain/keyedCollection.ts: keys may be strings or numbers (TableKey), so ELF section types are keyed directly. It addsallKeyed(every declaration, in source order) andfirstKeyed/lastKeyed. The last two take a non-emptyprecedencestring that names the format rule.src/native/exports/NativeExportParser.ts:SHT_DYNSYM,SHT_GNU_VERNEED,SHT_GNU_VERDEFandSHT_GNU_VERSYMare selected through the keyed owner, with the outcomes listed above.src/native/hardening/ElfHardening.ts:SHT_DYNSYMis selected throughuniqueKeyed, replacing a hand-writtenfilter(...).length > 1.SHT_SYMTABis selected throughfirstKeyed, because any symbol table shows the image is not stripped.src/native/elf/ElfUnwindTables.ts: itsnamed()helper isallKeyed.src/native/elf/KernelModuleParser.ts: the privatesectionsNamedhelper is deleted, and the first-section choice states the loader's rule (find_secreads the first section with the name). Its existing duplicate limitation is unchanged.scripts/verify/architecture-guards.mjs: a new countedsection-first-matchguard. Its baseline holds 5 sites in 4 files:GoBuildInfoSearch(PE characteristic heuristic),ManagedPeReader(RVA containment),nativeAotPe(one address containment, and theFROZEN_OBJECT_REGIONlookup), andGuidanceAccess(guidance bundle sections, not a binary).Not included:
FROZEN_OBJECT_REGIONneeds a decision on how a partial summary reports it, so it stays counted in the baseline.ElfInitializers.findSections, which matches by type or by name prefix and is not a keyed lookup.Contribution scope: ordinary refactor within existing boundaries; not applicable.
Contract and boundary impact
Semantic owner and earliest changed stage:
src/domain/keyedCollection.tsowns what a repeated key means; the ELF export, hardening, unwind and kernel-module parsers consume it. The privatesectionsNamedhelper is removed.Contribution scope fit and linked maintainer decision: W7 plan, duplicate-key owner; not applicable.
CLI and MCP/tool-catalog contract: no schema change. Export inventories for ELF images with repeated once-only sections now carry
version_unresolvedissues or a malformed refusal. NativeAOT reports gain the additive reason codeambiguous_frozen_object_region(from fix(nativeaot): report an ambiguous frozen object region as partial #10812).Provider, bridge, target-format, or platform compatibility: ELF images with one section per type are unchanged.
Evidence, artifact, provenance, or reconstruction contract: unchanged.
Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Launch or attach to a process.
Inject instrumentation or run scripts/code.
Change process memory, registers, files, or configuration.
Contact network services.
Recover protected code or work around protections.
Documentation or usability only; no target interaction.
Not sure yet; investigation or maintainer guidance needed.
Evidence and regression coverage
Tests added or updated:
NativeExportParser.test.tscovers a repeatedSHT_DYNSYM(malformed refusal). It also covers a repeatedSHT_GNU_VERNEEDorSHT_GNU_VERDEF(issue, export kept, no version name) and twoSHT_GNU_VERSYMsections linked to.dynsym(issue,version: "unknown"). Each fixture retypes or relinks a section header of the existing ELF fixture.keyedCollection.test.tscovers numeric keys,allKeyed,firstKeyed/lastKeyed, and the refusal of an empty precedence.Base reproduction or other evidence: with main's
NativeExportParser.tsrestored, all four new export tests fail (4 failed, 68 passed).User-visible CLI/MCP output (if applicable): shown in the problem section.
Remaining proof gaps: no real-world binary with repeated once-only ELF sections was examined; the fixtures are synthetic.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:focused -- src/domain/keyedCollection.test.ts src/native/exports/NativeExportParser.test.ts src/native/elf/ElfUnwindTables.test.ts src/native/elf/KernelModuleParser.test.ts src/native/hardening/BinaryHardeningParsers.test.ts tests/boundary/filesystem/elfUnwindRanges.test.ts tests/boundary/filesystem/kernelModule.test.ts tests/boundary/go/goBinaryImage.test.ts: 8 files, 377 tests passed before rebasing onto main; after the rebase the 7 files other thangoBinaryImage.test.tsran again, 264 tests passed.The same export test file run against the unfixed parser: 2 failed, 68 passed.
npm run test:focused -- src/native/exports/NativeExportParser.test.tsafter the review follow-up: 72 passed.node scripts/verify/architecture-guards.mjs: passed with the seededsection-first-matchbaseline.npm run check:fast: typecheck and lint passed.Review follow-up (4915a7a): the keyed-first-match guard now matches parentheses from the
filter(call to its[0], so a[0]inside the predicate or the map callback is not counted.npm run test:focused -- tests/boundary/filesystem/keyedFirstMatchGuard.test.tspassed 18/18 (with two new negative cases).node scripts/verify/architecture-guards.mjs --shrink-baselinespassed and left the baseline unchanged.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.