Skip to content

fix(elf): reject tables inside the declared ELF header - #10133

Merged
morluto merged 1 commit into
morluto:mainfrom
rudycelekli:fix/elf-declared-header-overlap
Nov 11, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
rudycelekli:fix/elf-declared-header-overlap

Conversation

@rudycelekli

Copy link
Copy Markdown

Summary

ELF admission treated only the class minimum (52 or 64 bytes) as the header. A larger e_ehsize still let the program or section table start inside that declared header, so those header bytes were parsed as table entries. Notes already rejected the same overlap. No open issue matches this.

Problem and expected behavior

Smallest trigger: ELF64 with e_ehsize 80 and e_phoff 64 (or ELF32 with e_ehsize 64 and e_phoff 52), and a nonzero table count. gABI says e_ehsize is the header's size in bytes and e_phoff / e_shoff are the tables' file offsets, so a table must not start before e_ehsize.

Previously parseBinaryTarget admitted that file. It now returns file_format_rejected with ELF program header table overlaps the fixed header or the section equivalent. A declared header that ends at or before the table offset is still admitted. Tables with a zero count are unchanged.

Change and scope

tableFailure compares the table offset with the admitted header.headerSize (e_ehsize) instead of the class minimum. readElfFixedHeader already requires that size to be at least the class minimum and no larger than the file. The same check already exists for note tables in ElfNoteParser.

Not included: note-owner byte matching, compressed section-name alignment, and any change to PE or Mach-O.

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

  • Semantic owner and earliest changed stage: validateElfDeclaredRanges / readElfTableDeclarations in src/domain/elfDeclaredRanges.ts. Native section, hardening, export, initializer, and kernel-module readers consume this admission. Note parsing already used header.headerSize. No path was removed.
  • Contribution scope fit and linked maintainer decision: ordinary malformed-ELF fix inside existing admission. Maintainer scope decision: not applicable.
  • CLI and MCP/tool-catalog contract: none. The existing file_format_rejected reason string is reused. No tool schema change.
  • Provider, bridge, target-format, or platform compatibility: ELF32 and ELF64, both endiannesses. A spec-valid image whose tables start at or after e_ehsize is unchanged. Images whose tables start inside a larger declared header are now rejected.
  • Evidence, artifact, provenance, or reconstruction contract: none. Rejection happens before provider admission.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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: tests/boundary/filesystem/elfDeclaredRanges.test.ts covers ELF32/ELF64 and both endiannesses. A program table inside e_ehsize, a section table inside e_ehsize (program count 0), and an extended header whose section table starts after e_ehsize are all asserted.
  • Base reproduction or other evidence: base 0909d89c966c30955fd0906b622ff25f3700789f. With src/domain/elfDeclaredRanges.ts stashed, the new cases received { ok: true } instead of the overlap rejection (4 failed, 15 existing tests passed). With the fix restored, the same file passed 19/19.
  • User-visible CLI/MCP output (if applicable): not exercised. Public opening goes through parseBinaryTarget, which is what the regression calls. The reason text is the existing overlap sentence.
  • Remaining proof gaps: no real-world ELF with e_ehsize larger than the class minimum was available. npm run test:focused does not reach Vitest on this machine (see validation).

Format-assumption boundary regression: the malformed overlap is paired with an extended header whose table starts after e_ehsize, and existing truncation cases in the same file still pass. Lifecycle regressions: not applicable; no process, file ownership, or cleanup change.

For evidence-bearing changes:

  • 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

  • git stash push -- src/domain/elfDeclaredRanges.ts then node scripts/run-exact-tests.mjs run tests/boundary/filesystem/elfDeclaredRanges.test.ts — exit 1. 4 failed, 15 passed. Each new case failed with expected { ok: false, ... overlaps the fixed header } received { ok: true }.
  • git stash pop then the same Vitest command — exit 0. 19 passed.
  • npm run test:focused -- tests/boundary/filesystem/elfDeclaredRanges.test.ts — exit 1 before Vitest. metadata:check throws The property 'options.mode' must be one of: 'strip'. Received 'transform' under Node.js v26.12.1. This happened with the production change stashed and does not depend on the diff. The command above is the Vitest step that focused mode runs after that prerequisite.
  • npx oxfmt src/domain/elfDeclaredRanges.ts tests/boundary/filesystem/elfDeclaredRanges.test.ts — exit 0. No further diff.
  • npm run check:fast — exit 0. typecheck and lint, 2 successful. About 2m17s.
  • gh search prs --repo morluto/rea "e_ehsize OR ehsize OR \"overlaps the fixed header\" OR \"declared ELF header\"" — no matches. Dedup TSVs had no matching open PR, open issue, or recent merge.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for a spec-valid ELF. A file whose program or section table starts before its declared e_ehsize was previously admitted and is now file_format_rejected. That file was already rejected by ELF note admission.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Header admission does not call those providers.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: offline parse rejection only. No new process, network, or file write in the product path. The test writes a temporary ELF under the existing temp-directory helper.

Author readiness

Human owner: @rudycelekli

  • 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.

Prepared with AI assistance. Human ownership declarations remain pending.

Admission compared table offsets with the class minimum, so a larger e_ehsize still parsed those header bytes as program or section entries.

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T18:32:21.904518Z f395187 PR opened
ℹ️ 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.

@morluto
morluto merged commit 4505477 into morluto:main Nov 11, 2026
30 of 44 checks passed
@morluto morluto mentioned this pull request Nov 12, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants