Skip to content

feat(elf): inspect Linux kernel module metadata - #7010

Merged
morluto merged 4 commits into
morluto:mainfrom
mvanhorn:fix/kernel-module-modinfo
Oct 24, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
mvanhorn:fix/kernel-module-modinfo

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Linux kernel modules (.ko) carry their identity in ELF sections: .modinfo key/value strings, __versions symbol CRCs, and an appended PKCS#7 signature trailer. REA admits relocatable ELF but had no static reader for this metadata. This adds inspect-kernel-module (CLI) and inspect_kernel_module (MCP) for ELF32/ELF64 ET_REL modules, read without loading the module or opening a disassembler. No related issue; this is a new static inspection within existing native authority.

Problem and expected behavior

An analyst triaging a driver today needs modinfo, readelf and a separate signature script. Expected: REA reports ordered .modinfo entries with duplicates preserved (alias, softdep, parm), __versions CRCs, presence of .gnu.linkonce.this_module and __ksymtab, .init.text/.exit.text sizes, and the signature trailer's module_signature fields with the PKCS#7 byte range and SHA-256.

Change and scope

src/native/elf/KernelModuleParser.ts reads section headers through the shared ELF reader, decodes .modinfo and __versions for both word sizes and byte orders, and parses the ~Module signature appended~ trailer. A missing section is observed absence when section names are known.

gzip, xz and zstd containers are reported unsupported with external_decompression as the next probe; neither this tool nor extract_artifact decodes those codecs. Malformed headers and exhausted entry budgets return no partial success. Not included: decoding struct module, validating the signature or certificate chain. AI was used for assistance.

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: native ELF inspection (src/native/elf/) and the binary diagnostics service.
  • Contribution scope fit and linked maintainer decision: static format inspection of a local file within existing native authority; separate scope decision not applicable.
  • CLI and MCP/tool-catalog contract: new inspect-kernel-module command and inspect_kernel_module tool.
  • Provider, bridge, target-format, or platform compatibility: portable TypeScript, no provider; runs on any supported Node host.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence carries artifact SHA-256, section locations and hashes, and the signature byte range.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged; reads a stable regular file.
  • 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): catalog builder entry, a capability row in each translated README (as in feat(pe): inspect import and delay-load tables #6509), and authored skill guidance in .agents/skills/reverse-engineer-anything/. No committed build outputs.

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: src/native/elf/KernelModuleParser.test.ts (ELF32/ELF64, both byte orders, duplicate keys, __versions layouts, signature trailers, compressed containers, truncation and budgets), kernelModule.test.ts, KernelModuleService.test.ts, BinaryDiagnosticsCancellation.test.ts, tests/acceptance/kernelModuleCli.test.ts, tests/boundary/mcp/kernelModuleMcp.test.ts, tests/boundary/filesystem/kernelModule.test.ts, and the shared path-admission, tool-contract and stable-artifact lists. Fixtures are synthetic; no binaries are committed.
  • Base reproduction or other evidence: the released CLI has no kernel module reader. Executed against Debian 13 arm64 vfat.ko and btrfs.ko (not committed) and compared with modinfo output.
  • User-visible CLI/MCP output (if applicable): see below.
  • Remaining proof gaps: ELF32 and big-endian modules were exercised with synthetic fixtures only. Signatures are located and hashed, not verified.
$ rea inspect-kernel-module vfat.ko --json | jq ...
modinfo: 8 entries   versions: 68 CRCs   this_module: present
signature: PKCS#7  sig_len 263

$ rea inspect-kernel-module btrfs.ko --json | jq ...
modinfo: 13 entries (duplicate softdep and alias preserved)   versions: 575 CRCs

$ rea inspect-kernel-module vfat.ko.xz --json | jq ...
applicability: unsupported   compression: xz
next_probe: external_decompression

modinfo vfat.ko and modinfo btrfs.ko list the same keys and values in the same order.

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

Head 2cb558d21 on main d361c53c5; macOS arm64, Node 26.5.0, npm 12.2.0:

  • npx --no-install vitest run src/application/binaryDiagnostics/BinaryDiagnosticsCancellation.test.ts src/application/binaryDiagnostics/KernelModuleService.test.ts src/contracts/toolEffects.test.ts src/domain/native/kernelModule.test.ts src/native/elf/KernelModuleParser.test.ts tests/acceptance/kernelModuleCli.test.ts tests/acceptance/localPathAdmissionCli.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/kernelModule.test.ts tests/boundary/mcp/kernelModuleMcp.test.ts tests/process-global/stableArtifactConsumers.test.ts - passed.
  • Real Debian 13 vfat.ko, btrfs.ko and vfat.ko.xz inspected as shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; new command and tool only.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS arm64 with Linux arm64 module inputs; no provider involved.
  • Package or release metadata impact: none beyond the generated catalogs.
  • Security, privacy, process, or containment review: the module is never loaded; reads are bounded and malformed input fails closed.

Author readiness

Human owner: @mvanhorn

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

Demo

demo

Adds inspect-kernel-module and inspect_kernel_module for ELF32/ELF64
ET_REL Linux kernel modules, read statically without executing them.
Reports ordered .modinfo entries with duplicates preserved, __versions
symbol CRCs, the presence of .gnu.linkonce.this_module and __ksymtab,
.init.text and .exit.text sizes, and an appended module signature
trailer with its PKCS#7 byte range and SHA-256. gzip, xz and zstd
containers are reported unsupported with external decompression as the
next probe. Malformed headers and exhausted entry budgets return no
partial success.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

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-24T13:26:03.631376Z
We couldn’t complete this review. Comment @codex review to try again.
2cb558d 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.

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; both numbered previous findings are fixed.

Summary

Adds static Linux kernel-module inspection through CLI and MCP, with ordered metadata, symbol CRCs, section facts, and signature ranges and hashes.

  • REA reports Linux kernel-module metadata from ELF files.
  • The same kernel-module inspection is available in the CLI and MCP.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI or MCP] --> B[KernelModuleService]
  B --> C[KernelModuleProvider]
  C --> D[Stable regular-file read]
  D --> E[KernelModuleParser]
  E --> F[Metadata and explicit limitations]
  F --> B
  B --> G[Validated Evidence]
Loading

Reviews (4) · Last reviewed commit: "fix: resolve merge integration errors" · Reviewed by Greptile

Comment thread src/native/elf/KernelModuleParser.ts Resolved
Comment thread src/domain/native/kernelModule.ts Resolved
mvanhorn and others added 2 commits October 24, 2026 06:41
Charge listed __ksymtab* sections against max_entries, omit section names
longer than 256 bytes with ksymtab_name_exceeds_limit, and aggregate the
non-file-backed limitation so repeated huge names cannot inflate Evidence.
Use fixedTupleSchema for the signature pad bytes with projection parity
tests, and assert the late-cancellation reason and retained observation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe
Comment thread src/server/createServer.ts Resolved
Comment thread src/application/CapabilityInventory.ts Resolved
@greptile-apps

This comment has been minimized.

@morluto
morluto merged commit dba8a31 into morluto:main Oct 24, 2026
44 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@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.

2 participants