Skip to content

refactor(native): select ELF sections through the keyed owner - #10780

Merged
morluto merged 6 commits into
mainfrom
refactor/keyed-elf-sections
Nov 15, 2026
Merged

morluto merged 6 commits into
mainfrom
refactor/keyed-elf-sections

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Second Keyed<T> slice after #10740. ELF section lookups that kept the first of repeated declarations through sections.find(...) now go through src/domain/keyedCollection.ts. The owner gains the allKeyed selector and firstKeyed / lastKeyed selectors that require a stated precedence rule. A counted architecture guard stops new sections.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:

Problem and expected behavior

Trigger: an ELF shared object that declares two SHT_DYNSYM sections, or two SHT_GNU_VERNEED sections.

Before: inspect_native_exports read whichever section came first and reported complete exports and version names. ElfHardening already refused two SHT_DYNSYM sections as malformed for the same image, so the two tools disagreed.

After:

  • Two SHT_DYNSYM sections: the export parser refuses the image as malformed with ELF image has more than one SHT_DYNSYM, which matches ElfHardening.
  • Two SHT_GNU_VERNEED or SHT_GNU_VERDEF sections: the parser reads neither table and records a version_unresolved issue (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.
  • More than one SHT_GNU_VERSYM linked to the dynamic symbol table: versions become unknown and a version_unresolved issue 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 adds allKeyed (every declaration, in source order) and firstKeyed / lastKeyed. The last two take a non-empty precedence string that names the format rule.
  • src/native/exports/NativeExportParser.ts: SHT_DYNSYM, SHT_GNU_VERNEED, SHT_GNU_VERDEF and SHT_GNU_VERSYM are selected through the keyed owner, with the outcomes listed above.
  • src/native/hardening/ElfHardening.ts: SHT_DYNSYM is selected through uniqueKeyed, replacing a hand-written filter(...).length > 1. SHT_SYMTAB is selected through firstKeyed, because any symbol table shows the image is not stripped.
  • src/native/elf/ElfUnwindTables.ts: its named() helper is allKeyed. src/native/elf/KernelModuleParser.ts: the private sectionsNamed helper is deleted, and the first-section choice states the loader's rule (find_sec reads the first section with the name). Its existing duplicate limitation is unchanged.
  • scripts/verify/architecture-guards.mjs: a new counted section-first-match guard. Its baseline holds 5 sites in 4 files: GoBuildInfoSearch (PE characteristic heuristic), ManagedPeReader (RVA containment), nativeAotPe (one address containment, and the FROZEN_OBJECT_REGION lookup), and GuidanceAccess (guidance bundle sections, not a binary).

Not included:

  • The NativeAOT frozen-region lookup. Choosing a policy for a repeated FROZEN_OBJECT_REGION needs 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.
  • PE and Mach-O name lookups beyond those already moved in refactor(parsers): select once-only sections and JSON fields through one keyed owner #10740, and plist consumers (separate PR).

Contribution scope: ordinary refactor within existing boundaries; not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/keyedCollection.ts owns what a repeated key means; the ELF export, hardening, unwind and kernel-module parsers consume it. The private sectionsNamed helper 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_unresolved issues or a malformed refusal. NativeAOT reports gain the additive reason code ambiguous_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.ts covers a repeated SHT_DYNSYM (malformed refusal). It also covers a repeated SHT_GNU_VERNEED or SHT_GNU_VERDEF (issue, export kept, no version name) and two SHT_GNU_VERSYM sections linked to .dynsym (issue, version: "unknown"). Each fixture retypes or relinks a section header of the existing ELF fixture. keyedCollection.test.ts covers numeric keys, allKeyed, firstKeyed / lastKeyed, and the refusal of an empty precedence.

  • Base reproduction or other evidence: with main's NativeExportParser.ts restored, 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 than goBinaryImage.test.ts ran 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.ts after the review follow-up: 72 passed.

  • node scripts/verify/architecture-guards.mjs: passed with the seeded section-first-match baseline.

  • 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.ts passed 18/18 (with two new negative cases). node scripts/verify/architecture-guards.mjs --shrink-baselines passed and left the baseline unchanged.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T08:07:52.167444Z 4915a7a New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[High impact] Appears safe to merge; the remaining guard false positive is non-blocking.

Summary

This PR moves ELF section selection through keyedCollection and makes repeated once-only declarations explicit.

  • Binary readers can now state how repeated keys are chosen.
  • ELF exports flag repeated symbol and version tables.
  • ELF dependency reading refuses repeated dynamic headers.
  • ELF unwind ranges stay unresolved when their GOT source repeats.
  • ELF hardening and module readers state their section rules explicitly.
  • NativeAOT reports repeated frozen regions as ambiguous.
  • Mach-O readers refuse repeated fixup commands.
  • PE and Go readers keep their existing section choices explicit.

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]
Loading

Reviews (7) · Last reviewed commit: "fix(verify): count a filter index only o..." · Reviewed by Greptile

Comment thread scripts/verify/keyed-first-match.mjs Resolved
…10790)

* refactor(nativeaot): read neither of repeated frozen object regions through the keyed owner

* refactor(parsers): retire every first-match section lookup (#10793)

* fix(nativeaot): report an ambiguous frozen object region as partial (#10812)
… 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.
@morluto
morluto force-pushed the refactor/keyed-elf-sections branch from d1a105e to b173b5e Compare November 15, 2026 07:46
@morluto
morluto merged commit 5d5ab53 into main Nov 15, 2026
54 of 56 checks passed
@morluto
morluto deleted the refactor/keyed-elf-sections branch November 15, 2026 09:03
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant