Skip to content

fix(node-sea): bound ELF note scans by the notes a carrier holds - #8031

Merged
morluto merged 1 commit into
morluto:mainfrom
Dragolone:fix/node-sea-elf-note-budget
Nov 4, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
Dragolone:fix/node-sea-elf-note-budget

Conversation

@Dragolone

Copy link
Copy Markdown
Contributor

Summary

Artifact classification runs the embedded Node SEA probe on every ELF root (inspect_artifact / inspect-artifact, through embeddedProbes.nodeSea()). locateElfNotes in src/artifacts/nodeSea/NodeSeaLocation.ts scans each PT_NOTE program header (up to 4,096) on its own, with one awaited 12-byte read per note header. Program headers that declare the same note bytes therefore rescan those bytes once per header, so the work grows as headers × notes rather than with the file size.

A 294,976-byte ELF64 with 4,096 PT_NOTE headers over the same 64 KiB of zero bytes (5,461 empty notes) makes locateNodeSea take 208 s on main. With this change it takes 277 ms.

Node finds the blob by walking PT_NOTE segments and returning the first NODE_SEA_BLOB note (deps/postject/postject-api.h#L127-L167 at v24.10.0). An ELF note entry is a 12-byte header followed by its padded name and descriptor, and the scanner already rejects entries shorter than 12 bytes. So tables that do not overlap can hold at most fileSize / 12 notes in total.

No issue is linked. I searched open and closed PRs and issues for "node sea note", "PT_NOTE", "locateNodeSea", "NodeSeaLocation", "node sea quadratic" and "note table". Only #7000 (the original reader) and unrelated ELF note PRs came up. The one open PR touching Node SEA files, #7177, edits docs/node-sea.md elsewhere; it already conflicts with main in other files, and this branch adds no conflict with it.

Problem and expected behavior

Input main With this change
4,096 PT_NOTE headers over 5,461 empty notes (295 KB) 208,177 ms, undefined 277 ms, undefined (classified as a plain ELF)
64 headers over 5,461 empty notes (69 KB) 3,242 ms, undefined 61 ms, undefined
64 headers over a NODE_SEA_BLOB note followed by 341 empty notes (7.8 KB) 215 ms, {carrier:"elf", blobOffset:3676, blobLength:48} 9 ms, fails closed: "Node SEA ELF note tables declare more notes than the file holds"

Expected: the note scan is bounded by the file size, not by headers × notes.

Change and scope

  • locateElfNotes now gives every note table of a carrier one shared budget of floor(fileSize / 12) note headers. The same budget covers the SHT_NOTE fallback, which only runs when no program-header table is readable, so the two never scan the same file.
  • When the budget runs out:
    • without a confirmed blob, the table is treated as unreadable, the existing opaque path, and the file keeps its native classification;
    • with a confirmed blob, the probe fails closed with the new NODE_SEA_ELF_NOTES_REPEATED message. This matches the existing rule that a blob found beside an unreadable note table fails closed (NODE_SEA_ELF_TABLE_TRUNCATED).
  • docs/node-sea.md describes the bound.

ELFs whose note tables do not overlap, which covers all normal files, cannot reach the budget and are unchanged. A carrier that repeats note tables far enough to exceed the budget is crafted. Node would still run it, but REA now reports a format failure for it instead of the blob.

Not included: a single very large PT_NOTE table full of empty notes is still read one 12-byte header at a time. That cost is linear in the table size, not headers × notes.

Contribution scope: a robustness fix in an existing reader; a maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: locateElfNotes / scanElfNoteTable in src/artifacts/nodeSea/NodeSeaLocation.ts.
  • Contribution scope fit and linked maintainer decision: in scope; not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. The new failure message appears only for carriers that exceed the note budget.
  • Provider, bridge, target-format, or platform compatibility: none for real carriers.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none; docs/node-sea.md updated.

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

  • Test added: src/artifacts/NodeSeaArtifactReader.test.ts, "reads repeated PT_NOTE declarations at most once per note the file holds".
    • It uses a small repeatedNoteElf builder with 64 PT_NOTE headers.
    • It counts FileHandle.read calls rather than wall-clock time, so the result is deterministic.
    • It also checks that the confirmed-blob case fails closed with NODE_SEA_ELF_NOTES_REPEATED.
  • Base reproduction: executed. With NodeSeaLocation.ts and NodeSeaBlob.ts reverted to main, the test fails with expected 21890 to be less than or equal to 711 (read calls).
  • Timings in the table come from calling locateNodeSea on the generated files on macOS arm64 with Node 24.22.1.
  • Remaining proof gaps:
    • No real Node SEA ELF carrier was available, and the Docker/postject lane (npm run verify:node-sea) was not run. The CLI acceptance test, which builds a blob with the local Node, passes.
    • As a sanity check, locateNodeSea still returns undefined for 300 real Android NDK .so files.

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

  • npx vitest run src/artifacts/NodeSeaArtifactReader.test.ts:
    • with the two source files reverted to main: 1 failed, 41 passed;
    • with the fix: 42 passed.
  • With the fix:
    • NodeSeaArtifactReader.test.ts, nodeSea/NodeSeaBlob.test.ts and ArtifactEmbeddedFormatProbes.test.ts: 65 passed;
    • EmbeddedArtifactExtraction.test.ts, ArtifactGraphConstruction.test.ts, ElfNoteParser.test.ts, tests/boundary/filesystem/artifactComparisonNodeSea.test.ts and artifactProvider.extractionAdmission.test.ts: 139 passed, 1 skipped.
  • After npm run compile, tests/acceptance/nodeSeaCli.test.ts, tests/boundary/mcp/nodeSeaMcp.test.ts and tests/acceptance/artifactComparisonNodeSea.test.ts: 11 passed.
  • npx tsc --noEmit: 0 errors.
  • npx oxlint on the changed files: 0 errors. The complexity, max-depth and max-lines warnings are the same as on main.
  • npx oxfmt --check on the changed files: clean.
  • npm run verify:module-boundaries: passed.
  • node scripts/check-doc-facts.mjs: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for real carriers. A crafted carrier whose note tables exceed the budget fails closed when a blob is found.
  • Real Hopper/Ghidra, browser, or OS coverage: no real Node SEA ELF carrier (see proof gaps).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: removes a headers × notes scan that a small crafted ELF could trigger during classification.

Author readiness

Human owner: @Dragolone

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

Artifact classification probes every ELF root for a Node SEA note. Each
PT_NOTE program header was scanned on its own, one read per note, so
headers that declare the same note bytes multiplied the work: a 295 KB
ELF with 4,096 such headers kept inspect-artifact busy for about three
and a half minutes.

Every note header takes at least 12 bytes, so disjoint tables hold at
most one note per 12 file bytes. The scan now stops there. Past that
count the remaining tables are unreadable: an ELF without a confirmed
blob keeps its native classification, and a confirmed blob fails closed.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T13:21:30.515085Z
We couldn’t complete this review. Comment @codex review to try again.
9d89d63 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Bounds ELF note-header reads with one shared budget of floor(fileSize / 12).

  • ELF note scans share a file-sized limit across tables.

Acknowledged behavior:

  • Dragolone explicitly accepts native classification when the budget runs out before a blob is confirmed, and a format failure afterward, for crafted overlapping note tables.
  • Dragolone explicitly defers batching reads within one large note table because that work is already linear.

Supersession could not be checked on GitHub because authentication was unavailable. Local history contains no later change.

Reviews (1) · Last reviewed commit: "fix(node-sea): bound ELF note scans by t..." · Reviewed by Greptile

@morluto
morluto merged commit 1f8084c into morluto:main Nov 4, 2026
41 checks passed
@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