Skip to content

feat(elf): decode FDO packaging and dlopen note metadata - #7237

Merged
morluto merged 6 commits into
morluto:mainfrom
AniketR10:feat/elf-fdo-notes
Nov 19, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
AniketR10:feat/elf-fdo-notes

Conversation

@AniketR10

@AniketR10 AniketR10 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7235

inspect-elf-notes decoded only GNU notes. FDO notes, which declare a binary's package and its optional dlopen libraries, came back as type_name: "unknown" with a hash only, because their descriptors exceed the 64-byte hex preview. This PR names and decodes both FDO note kinds.

Problem and expected behavior

readelf -n /usr/bin/ls prints FDO_PACKAGING_METADATA with {"type":"rpm","name":"coreutils",…}. On main, REA reports the same note as owner: "FDO", type_name: "unknown", descriptor.hex: null, gnu: null.

Expected: the package and dlopen JSON defined by the UAPI package metadata and dlopen metadata specifications appears in the result. A malformed descriptor stays visible with a reason and does not fail the inspection.

Change and scope

  • elfNoteTypeName(owner, type) in src/domain/native/elfNotes.ts replaces the GNU-only gnuNoteTypeName. A type number is named only within its owner's namespace: FDO 0xcafe1a7e → fdo_packaging_metadata, FDO 0x407c0c0a → fdo_dlopen_metadata.
  • Entries retain the FDO declaration, diagnostic, or raw descriptor facts. Packaging is a JSON object and dlopen metadata is an array of JSON objects. The reader requires strict UTF-8, a NUL terminator, NUL padding, exact numbers, and unique object keys.
  • Equivalent declarations share a decode by descriptor range and type. The first budget tracks distinct source bytes and the second tracks each admitted JSON projection.
  • The reader admits at most 64 KiB of distinct descriptor bytes and 64 KiB of projected JSON per report. Over-budget metadata remains undecoded with an issue.
  • When metadata is decoded, a limitation states that it is the producer's declaration, not verified against a package database or loaded libraries.

Metadata keeps the producer’s keys. Key-specific validation is outside this change.

Contribution scope: not applicable. This is static parsing of bytes the existing operation already reads.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ElfNoteParser produces the decoded FDO facts; the domain contract owns owner-scoped type naming. The superseded gnuNoteTypeName is removed. ElfNotesService validation is unchanged, and no other consumer reads note type names.
  • Contribution scope fit and linked maintainer decision: not applicable (existing read-only operation).
  • CLI and MCP/tool-catalog contract: additive. Two type_name enum values and a nullable fdo entry field; the tool description mentions FDO metadata.
  • Provider, bridge, target-format, or platform compatibility: none; portable TypeScript parser.
  • Evidence, artifact, provenance, or reconstruction contract: descriptor hash and location are unchanged; decoded metadata is labeled as a producer declaration.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none committed; the skill reference was edited in .agents/skills/.

Expected effects:

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

    • ElfNoteParser.test.ts: both note kinds across PT_NOTE and SHT_NOTE, each malformed case (no terminator, data after terminator, invalid UTF-8, invalid JSON, wrong top-level shape for each kind), unknown FDO types staying undecoded, and one descriptor range shared by a PT_NOTE packaging note and an SHT_NOTE dlopen note decoding per type (from Greptile review), and the shared 64 KiB decode allowance: its boundary, distinct notes sharing it, and a PT_NOTE/SHT_NOTE repeat charged once (from Codex reviews).
    • elfNotes.test.ts: owner-scoped naming.
    • elfNotesCli.test.ts: public CLI output validated against the published contract.
  • Base reproduction or other evidence (executed): a local sweep called parseElfNotes on 5,276 ELF files from /usr/bin and /usr/lib64 on Fedora 44 x86_64. It decoded 9,294 fdo_packaging_metadata and 166 fdo_dlopen_metadata entries with no issue. The same 5,276 files parsed before and after the change. The 129 files that failed before still fail, with the existing note-alignment and entry-budget errors, unchanged by this PR.

  • User-visible CLI output: rea inspect-elf-notes /usr/bin/ls --json now reports, for both tables:

    { "owner": "FDO", "type_name": "fdo_packaging_metadata",
      "fdo": { "metadata": { "type": "rpm", "name": "coreutils", "version": "9.10-5.fc44",
               "architecture": "x86_64", "osCpe": "cpe:/o:fedoraproject:fedora:44" }, "issue": null } }

    A real dlopen note (libnss_myhostname.so.2) decodes to [{"feature":"idn","description":"Support for internationalized domain names","priority":"suggested","soname":["libidn2.so.0"]}].

  • Remaining proof gaps: only checked against Fedora-produced notes. No big-endian or ELF32 binaries carrying FDO notes were available, though the FDO decoder does not depend on byte order.

Boundary regressions: malformed input (each spec violation is kept, with a reason) and capacity (decoding shares the existing text budget and is cached per range). No lifecycle stages 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

  • npm run test:local -- src/native/elf/ElfNoteParser.test.ts src/domain/native/elfNotes.test.ts src/native/elf/ElfNotesProvider.test.ts src/application/binaryDiagnostics/ElfNotesService.test.ts: 67 passed on d83cf88; the shared-descriptor regression failed on b8cd950
  • npm run test:focused -- tests/acceptance/elfNotesCli.test.ts tests/boundary/mcp/elfNotesMcp.test.ts tests/boundary/filesystem/elfNotes.test.ts: 15 passed on b8cd950, including MCP advertisement; the CLI and MCP files (13 tests) passed again on d83cf88
  • npm run check:fast: typecheck and lint passed; it passed again as the pre-push hook on the pushed commit
  • npm run docs:check: passed (rerun on d83cf88)
  • On b8cd950 the tests above ran before the pre-commit formatter (oxfmt) reformatted the staged files; the 91f7791 runs include that formatting.
  • Host ELF sweep repeated on 91f7791 (5,276 files: 9,324 packaging and 208 dlopen entries) on 47c7c61 (5,268 files: 9,058 packaging and 208 dlopen entries), and on d83cf88 (5,341 files: 9,316 packaging and 208 dlopen entries). Every FDO entry decoded with no issue; the file sets differ by find ordering.
  • Heap check with dense [{},{},…] dlopen descriptors: on 91f7791 a 16 MiB descriptor added about 790 MiB of heap and took 5.3 s; on 47c7c61 16 MiB and 64 MiB descriptors add about 0 MiB and finish in 44 ms and 134 ms. With max_entries: 256, 255 distinct 64 KiB notes (15.9 MiB file) added about 700 MiB of heap in 4.6 s on 47c7c61, and about 0 MiB in 100 ms on d83cf88.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Additive output; existing type_name values and fields are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Real Fedora 44 ELF files were swept as described above.
  • Package or release metadata impact: none.
  • Secure resource bounds come from the file and note text limits, descriptor decode and projection ceilings, and the Evidence JSON depth allowance. The reader is passive.

The current-base refresh at 980e23fdab uses exact JSON and complete descriptor framing. It caps both cumulative descriptor decoding and cumulative projected JSON. Repeated descriptors reuse a decode but each emitted representation consumes projection allowance. Oversized, imprecise, duplicate-key, and wrong-shape descriptors retain raw note Evidence. The refresh passed 323 source tests with one skip and 70 compiled tests, including the four previously failing files. Typecheck, lint, and docs checks passed.

At 8194a6eca7, the compiled desktop heap test imports the shared depth checker. The stale import failed before the change. Afterward, 157 focused tests passed, including all five heap tests, with one host-ELF skip.

Author readiness

Human owner: @AniketR10

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

Name FDO notes within their owner's namespace: type 0xcafe1a7e is
fdo_packaging_metadata and 0x407c0c0a is fdo_dlopen_metadata. One
elfNoteTypeName(owner, type) replaces the GNU-only gnuNoteTypeName.

Each entry gains an fdo field next to gnu. metadata holds the descriptor's
JSON object (packaging) or array (dlopen) when it is NUL-terminated UTF-8
JSON followed only by NUL padding; otherwise metadata is null and issue
names the broken rule, without failing the inspection. Each descriptor
range is decoded once and its retained JSON text is charged to the shared
note text budget per repeated entry. A limitation marks the metadata as a
producer declaration.

Fixes morluto#7235
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-19T05:38:33.098981Z 8194a6e 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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The follow-up appears safe to merge.

Summary

Adds decoded FDO package and optional-library declarations to ELF note reports while preserving raw note facts when decoding is refused. The latest push updates the heap tests to use the shared JSON depth helper.

  • ELF note entries now show decoded package and dlopen declarations.
  • Desktop and recorded-state JSON checks now use one shared depth walker.

Reviews (6) · Last reviewed commit: "test(desktop): exercise the shared JSON ..." · Reviewed by Greptile

Comment thread src/native/elf/ElfNoteParser.ts Resolved
The FDO decode cache was keyed by descriptor range only, but the note
type selects the required JSON shape. Overlapping PT_NOTE and SHT_NOTE
tables can give one descriptor range a packaging note and a dlopen note,
and the second reused the first note's verdict. Include the type name in
the key.

Refs morluto#7235

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91f7791328

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/elf/ElfNoteParser.ts Resolved
The FDO decoder charged only descriptor source bytes before JSON.parse,
but a dense JSON value such as [{},{},...] decodes to about 50 times its
source size in heap before the service and Evidence copy it again. A
16 MiB descriptor took about 790 MiB of heap; one near the default
64 MiB file budget could exhaust the Node heap. Leave descriptors above
64 KiB undecoded with an issue naming the limit; real FDO notes are a
few hundred bytes.

Refs morluto#7235

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47c7c61520

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/elf/ElfNoteParser.ts Resolved
The 64 KiB FDO decode bound applied to each descriptor, so raising
max_entries to 256 admitted 256 distinct dense 64 KiB notes: a 16 MiB
file added about 700 MiB of heap before Evidence copied it again.
Charge each distinct descriptor's size to one 64 KiB allowance per
report; a range repeated by another table reuses its decode, and notes
past the allowance keep their entry with an issue.

Refs morluto#7235

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d83cf887c1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/native/elf/ElfNoteParser.ts Resolved
Comment thread src/native/elf/ElfNoteParser.ts Resolved
Refresh the contributor decoder against the current ELF note reader. Preserve raw descriptor evidence on refusal and bound exact JSON decoding and retained copies.
Comment thread src/domain/desktop/stateFormats.ts Resolved
@morluto
morluto enabled auto-merge (squash) November 19, 2026 05:36
@morluto
morluto merged commit dd1bb43 into morluto:main Nov 19, 2026
57 checks passed
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Decode FDO packaging and dlopen metadata in inspect-elf-notes

2 participants