Skip to content

feat(elf): decode ksymtab strings/CRCs and extended modversions - #14394

Open
saariuslystoned wants to merge 3 commits into
morluto:mainfrom
saariuslystoned:feat/kernel-module-ksymtab-extver
Open

saariuslystoned wants to merge 3 commits into
morluto:mainfrom
saariuslystoned:feat/kernel-module-ksymtab-extver

Conversation

@saariuslystoned

Copy link
Copy Markdown
Contributor

Summary

Extend inspect_kernel_module (inspect-kernel-module) to decode __ksymtab_strings, __kcrctab / __kcrctab_gpl CRC arrays, and CONFIG_EXTENDED_MODVERSIONS (__version_ext_names + __version_ext_crcs) in strictly additive, bounded fashion while preserving full backward compatibility with existing schemas, reports, and tests.

Problem and expected behavior

Previously in src/native/elf/KernelModuleParser.ts:

  • Export symbol metadata only listed __ksymtab* section locations without decoding exported symbol/namespace strings in __ksymtab_strings or u32 CRC arrays in __kcrctab / __kcrctab_gpl.
  • Module version CRCs only decoded classic __versions, leaving CONFIG_EXTENDED_MODVERSIONS (__version_ext_names paired 1:1 with __version_ext_crcs) unparsed and unreported.

Expected behavior:

  • Applicable ET_REL kernel modules decode __ksymtab_strings (NUL-terminated symbol/namespace strings), __kcrctab and __kcrctab_gpl (u32 CRC arrays in ELF byte order, explicitly left unpaired from strings because struct kernel_symbol PREL32 vs pointer relocations are not resolved), and extended_versions (__version_ext_names paired 1:1 with u32 CRCs in __version_ext_crcs).
  • Truncated, misaligned, empty-name, unterminated, single-section-only, or count-mismatched sections fail cleanly with typed section/entry status + reason codes and set partial coverage with explicit limitations instead of silently dropping or crashing.
  • Inline decoded strings larger than MAX_KERNEL_MODULE_RAW_BYTES (4096) omit inline text (null + omitted: true) while preserving raw_sha256 and bytes. All decoded entries are bounded by max_entries (examined_entries).
  • Unsupported compressed containers and non-ET_REL targets set extended_versions: null (with ksymtab: null). Schema additions on ksymtabSchema and kernelModuleSchema remain .exactOptional() for backward compatibility with existing callers/fixtures.

Change and scope

  • Domain (src/domain/native/kernelModule.ts): Added KERNEL_MODULE_CRC32_ENTRY_BYTES = 4, crc32Hex, typed section/entry reason enums and Zod schemas (ksymtabStringEntrySchema, ksymtabStringsSchema, kcrctabEntrySchema, kcrctabSectionSchema, extendedVersionSectionMetaSchema, extendedVersionEntrySchema, extendedVersionsSchema), and strictly additive .exactOptional() properties (ksymtab.strings, ksymtab.kcrctab, ksymtab.kcrctab_gpl, extended_versions). Updated max_entries input schema description.
  • Parser (src/native/elf/KernelModuleParser.ts): Implemented parseKsymtabStrings, parseKcrctabSection, and parseExtendedVersions using bounded BinaryReader slice reads; handled duplicate/empty/unterminated/misaligned/mismatch conditions and trailing NUL padding in __version_ext_names; updated limitations (including explicit struct kernel_symbol PREL32 vs pointer relocation caveat and extended modversions missing-half / malformed / omitted-text notes) and partial coverage checks.
  • Provider & Application (src/native/elf/KernelModuleProvider.ts, src/application/binaryDiagnostics/KernelModuleService.ts): Updated max_entries remediation text, validation range overlap checks, evidence normalization consistency guards, and backward-compatible examined_entries sum.
  • Contracts & Docs (src/contracts/native/binaryDiagnosticsToolContracts.ts, docs/kernel-modules.md, docs/getting-started/cli.md, docs/reference/supported-targets.md, .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md, .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md): Documented the additive fields, schema caveats, and updated tool summary.
  • Synthetic clean-room fixtures & tests: Updated src/native/elf/KernelModule.fixture.ts with crc32Array, extendedVersionSections, section flags, and optional custom section inputs (default fixture output unchanged), and added coverage across unit, service, filesystem boundary, MCP, and CLI acceptance tests.

Not included:

  • Resolving ELF relocations against struct kernel_symbol entries (PREL32 vs pointer layouts) to map individual __ksymtab* slots back to __ksymtab_strings / __kcrctab*; explicitly documented in limitations.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/native/elf/KernelModuleParser.ts (static ELF .ko parser) and src/domain/native/kernelModule.ts (kernelModuleSchema); KernelModuleService.ts consumes these directly with no duplicated parsing.
  • Contribution scope fit and linked maintainer decision: Bounded strictly additive enhancement to the existing inspect_kernel_module static ELF analyzer (not applicable for new execution/injection scope).
  • CLI and MCP/tool-catalog contract: inspect_kernel_module tool contract and rea inspect-kernel-module CLI retain backward compatibility; new fields (ksymtab.strings, ksymtab.kcrctab, ksymtab.kcrctab_gpl, extended_versions) are strictly additive and .exactOptional() on kernelModuleSchema / ksymtabSchema. Verified via tests/boundary/mcp/kernelModuleMcp.test.ts, tests/boundary/mcp/advertisedDialect.test.ts, tests/acceptance/kernelModuleCli.test.ts, and src/contracts/tupleSchemaParity.test.ts.
  • Provider, bridge, target-format, or platform compatibility: Built-in pure TypeScript BinaryReader ELF inspection; no external binaries or target execution.
  • Evidence, artifact, provenance, or reconstruction contract: Preserves observed vs omitted values (raw_sha256 retained), section metadata (offset, size, section_name, section_index, count), typed malformed reasons, coverage.status, and limitations.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: Authored instructions updated in .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md; .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md regenerated via node scripts/generate-cursor-plugin-skill.mjs; npm run metadata:check and npm run docs:check pass.

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:
    • src/domain/native/kernelModule.test.ts: schema validation for ksymtab strings/kcrctab*, extended_versions, legacy schema compatibility, and fixed MAX_INSPECT_KERNEL_MODULE_ENTRIES parity.
    • src/native/elf/KernelModuleParser.test.ts: LE & BE __ksymtab_strings (empty entries, unterminated trailing string, omitted >4096-byte strings), __kcrctab / __kcrctab_gpl (u32 alignment errors, empty section), CONFIG_EXTENDED_MODVERSIONS paired entries, trailing NUL padding, count mismatch, single-section-only (missing_names / missing_crcs), unterminated/empty names, oversized extended name omission, non-ET_REL null behavior, and max_entries budget boundary.
    • src/application/binaryDiagnostics/KernelModuleService.test.ts: validation & consistency invariants across new sections, omitted oversized entries, malformed reports, and preserved backward compatibility when optional fields are absent.
    • tests/boundary/filesystem/kernelModule.test.ts, tests/boundary/mcp/kernelModuleMcp.test.ts, tests/acceptance/kernelModuleCli.test.ts: end-to-end service, MCP stdio schema/result parity, and CLI JSON output + resource_constraint (max_entries) verification using synthetic ELF .ko fixtures.

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

All checks ran cleanly on HEAD 742612d66a5a680d27f60b77e5dcece15b6430e6 (no code/doc changes modified by lint-staged):

  • npm run format:check — passed (exit 0, 8823 files checked)
  • npm run check:fast — passed (exit 0: turbo typecheck + lint 2/2, verify:architecture-guards 3113 source files)
  • npm run verify:test-discovery — passed (exit 0, 3899 test and spec files)
  • npm run metadata:check — passed (exit 0)
  • npm run docs:check — passed (exit 0: docs:check:built 6/6, tests/conformance/readmeConsistency.test.ts 8/8)
  • npx vitest run src/domain/native/kernelModule.test.ts src/native/elf/KernelModuleParser.test.ts src/application/binaryDiagnostics/KernelModuleService.test.ts tests/boundary/filesystem/kernelModule.test.ts tests/boundary/filesystem/elfStableReportFinalization.test.ts tests/boundary/providers/nativeArtifactFinalization.test.ts tests/boundary/mcp/kernelModuleMcp.test.ts tests/acceptance/kernelModuleCli.test.ts tests/boundary/mcp/advertisedDialect.test.ts tests/acceptance/nativeElfFrameAllowanceMcp.test.ts tests/acceptance/tools/localToolContracts.test.ts src/contracts/tupleSchemaParity.test.ts — passed (12 test files, 193/193 tests passed, 0 skipped, 0 failed)

Compatibility, safety, and release

  • Breaking changes or migration steps: None; all added fields are strictly additive and .exactOptional() on ksymtabSchema and kernelModuleSchema.
  • Real Hopper/Ghidra, browser, or OS coverage: Not applicable (pure static ELF parser tested with synthetic clean-room .ko objects across LE/BE and CLI/MCP boundaries).
  • Security, privacy, process, or containment review: Bounded reads/entry budgets enforced; synthetic clean-room fixtures only; zero private paths, credentials, or vendor .ko blobs.

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.

Author checklist (completed by the PR author before requesting review)

  • 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.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T22:05:16.043800Z
We couldn’t complete this review. Comment @codex review to try again.
742612d 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 Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no new actionable issue remains from this review.

Summary

Extends kernel-module inspection with export strings, export CRC arrays, and paired extended modversions.

  • The inspector reports exported strings and CRCs as separate section entries.
  • Extended modversion names and CRCs appear together in kernel-module reports.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Selected file] --> B{Container and ELF type}
  B -->|Compressed or not ET_REL| C[Explicit unsupported or not-applicable report]
  B -->|ET_REL| D[Read module sections]
  D --> E[Decode strings and CRCs within shared entry budget]
  E --> F[Keep ranges, hashes, reasons and omissions]
  F --> G[Check report and child ranges]
  G --> H[CLI and MCP Evidence]
Loading

Reviews (2) · Last reviewed commit: "fix(elf): charge mismatched modversions,..." · Reviewed by Greptile

Comment thread src/native/elf/KernelModuleParser.ts Resolved
Comment thread src/native/elf/KernelModuleParser.ts Resolved
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 26, 2026

This branch has not been deployed

No deployments
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