Repository navigation
feat(elf): report a Linux kernel image's version banner and embedded build config - #9573
Conversation
…build config inspect_kernel_build_config and inspect-kernel-build-config read one local vmlinux, raw arm64 Image, gzip bzImage or zImage, or configs.ko and report its Linux version banner and the IKCONFIG .config embedded between IKCFG_ST and IKCFG_ED, without executing it. A config is present only when a gzip member ends exactly at IKCFG_ED, passes its CRC-32 and ISIZE checks and parses as .config text; framing that fails is reported malformed, never absent. bzImage gzip payloads are inflated within a budget and other codecs are named as unsupported, using codec detection now shared with the kernel module parser. The config search, inflate sizes and option counts are bounded, scans honor cancellation, and target-derived text is marked untrusted.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR adds kernel-image inspection to the CLI and MCP for caller-selected local files. The reviewed snapshot still needs the custom-version fix and corrected input-bound documentation before merging. FindingsFix with agent prompt### Issue 1
src/native/elf/KernelBuildConfig.ts:undefined-526
`parseBannerText` cuts a release token at characters such as `@` or `:`. For `Linux version 6.6.0@vendor (builder@host) (gcc) #1`, it reports `version: "6.6.0"` and loses both `builder` and `compiler`. Custom kernel release suffixes can contain these characters, so analysts receive incomplete build details even though the full banner was found.
Read the full version token before splitting the following groups, and update `bannerAgrees` to accept the same token.
### Issue 2
docs/guides/native/kernel-build-config.md:44-45
The guide still says inflation stops at the first `IKCFG_ED`, but the latest change passes the remaining image to `inflateGzipMember` and checks for the marker at the decoded member's end. The new stored-block test intentionally accepts an earlier marker inside the member. Users are therefore promised an input boundary the parser no longer enforces.
Update the guide, specification, and parser comments to describe the current bounds. The documentation rule requires guides to describe existing behavior and limitations; this requirement must be satisfied before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["CLI or MCP request"] --> B["Shared input checks"]
B --> C["Stable regular-file read"]
C --> D{"Image format"}
D -->|"ELF or raw image"| E["Search file bytes"]
D -->|"gzip bzImage"| F["Inflate within payload budget"]
F --> G["Search inflated bytes"]
D -->|"Other compressed stream"| H["Unsupported result"]
E --> I["Read banner and check config member"]
G --> I
I --> J["Filter and page config entries"]
J --> K["Check report and attach Evidence"]
H --> K
Reviews (4) · Last reviewed commit: "fix(elf): frame kernel configs by gzip m..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c950b3a0b
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When FHCRC is set, compare the low 16 bits of the header CRC-32 before inflating, so a damaged header no longer yields a present config or an inflated bzImage payload.
Codec detection now reads the same payload_offset/payload_length slice that is inflated, so bytes past a short payload cannot name its codec.
A damaged or cut-off deflate stream between IKCFG_ST and IKCFG_ED was skipped and could end as an absent config with complete coverage. It is now malformed with config_gzip_invalid, and a later valid config still wins.
Config text is read one line at a time instead of split into an array, and a quoted value is validated before it is decoded once. The 4096-character string cap is removed: Kconfig has no such limit and max_config_bytes already bounds every line, so a long CONFIG_EXTRA_FIRMWARE list is no longer reported as malformed.
The parser ran synchronously, so an abort raised during parsing could not change the signal before it returned. Inflation now runs on the zlib thread pool and each scan yields to the event loop once per MiB, so the existing cancellation checks observe a real abort.
Budget failures are now KernelBuildConfigBudgetFailure with a knob field, and the provider builds its recovery advice from that field instead of searching the diagnostic message for an option name.
The documentation guide assigns analyst workflows to docs/guides/<domain>/. Move the guide there, place its navigation and directory entries in the Native binaries group, and update links from the docs index, CLI guide, spec and authored skill. The public /kernel-build-config route is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28346f526a
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A config made of one long quoted value never reached the per-line yield, so the control-byte check, value validation and SHA-256 ran in one synchronous block. Each now works one MiB window per event-loop turn, and the line patterns match only a bounded name prefix instead of the whole value.
Entry names and values were V8 slices of the whole decoded config, so a one-entry page kept the full text alive. Entries in the returned page are now standalone copies, so retained memory follows the page size.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c08819d160
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
IKCFG_ST, IKCFG_ED and banner searches used one Buffer.indexOf over the rest of the image, so a large image with no marker never yielded. They now search overlapping one MiB windows and yield after each window without a match.
# Conflicts: # src/contracts/native/binaryDiagnosticsToolContracts.ts # src/contracts/toolEffects.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 209b4d9f2f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8f5f19de6
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b7a588bfd
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { codec: "lzma", magic: Buffer.from([0x5d, 0x00, 0x00]) }, | ||
| { codec: "xz", magic: Buffer.from([0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]) }, | ||
| { codec: "lzo", magic: Buffer.from([0x89, 0x4c, 0x5a]) }, | ||
| { codec: "lz4", magic: Buffer.from([0x02, 0x21, 0x4c, 0x18]) }, |
There was a problem hiding this comment.
Recognize framed LZ4 streams before scanning the file
For an Image.lz4 using the standard LZ4 frame signature (04 22 4d 18), this table recognizes only the legacy signature, so parseKernelBuildConfig searches the compressed bytes as an uncompressed image. In an isolated source-parser probe, a frame generated by LZ4F_compressFrame from an image containing a valid IKCFG returned an absent config with complete coverage, while the original image returned present. Recognize the standard frame signature as lz4 too, so these files produce the advertised unsupported-codec result rather than negative evidence about their compressed contents.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
|
|
||
| /** Matches a Kconfig `int` or `hex` value as written to `.config`. */ | ||
| export const KERNEL_BUILD_CONFIG_NUMBER = | ||
| /^(?:-?(?:0|[1-9][0-9]*)|0[xX][0-9A-Fa-f]+)$/u; |
There was a problem hiding this comment.
Accept Kconfig hex values without a 0x prefix
When an embedded config contains a valid hex assignment without the optional 0x prefix, such as CONFIG_PAGE_OFFSET=C0000000, this expression rejects it. Consequently, classifyValue makes parseConfigText reject the entire CRC-valid config as config_text_invalid, even when the caller requests an unrelated option. Accept the unprefixed hex spelling while preserving its source text; this shared matcher also gates KernelBuildConfigService.valueAgrees, so the service currently rejects the same valid representation.
AGENTS.md reference: AGENTS.md:L97-L97
Useful? React with 👍 / 👎.
| compiler: string | null; | ||
| } | null => { | ||
| let rest = text.slice(BANNER_PREFIX.length); | ||
| const version = /^[0-9][0-9A-Za-z.+_~-]*/u.exec(rest)?.[0]; |
There was a problem hiding this comment.
Custom kernel versions are shortened
parseBannerText cuts a release token at characters such as @ or :. For Linux version 6.6.0@vendor (builder@host) (gcc) #1, it reports version: "6.6.0" and loses both builder and compiler. Custom kernel release suffixes can contain these characters, so analysts receive incomplete build details even though the full banner was found.
Read the full version token before splitting the following groups, and update bannerAgrees to accept the same token.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/native/elf/KernelBuildConfig.ts
Line: 526
Comment:
**Custom kernel versions are shortened**
`parseBannerText` cuts a release token at characters such as `@` or `:`. For `Linux version 6.6.0@vendor (builder@host) (gcc) #1`, it reports `version: "6.6.0"` and loses both `builder` and `compiler`. Custom kernel release suffixes can contain these characters, so analysts receive incomplete build details even though the full banner was found.
Read the full version token before splitting the following groups, and update `bannerAgrees` to accept the same token.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| - The member trailer ends exactly at the first `IKCFG_ED` after the gzip | ||
| header. Inflation reads only the bytes up to that marker. |
There was a problem hiding this comment.
Guide promises outdated read bounds
The guide still says inflation stops at the first IKCFG_ED, but the latest change passes the remaining image to inflateGzipMember and checks for the marker at the decoded member's end. The new stored-block test intentionally accepts an earlier marker inside the member. Users are therefore promised an input boundary the parser no longer enforces.
Update the guide, specification, and parser comments to describe the current bounds. The documentation rule requires guides to describe existing behavior and limitations; this requirement must be satisfied before merging.
Context Used: Documentation (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/guides/native/kernel-build-config.md
Line: 44-45
Comment:
**Guide promises outdated read bounds**
The guide still says inflation stops at the first `IKCFG_ED`, but the latest change passes the remaining image to `inflateGzipMember` and checks for the marker at the decoded member's end. The new stored-block test intentionally accepts an earlier marker inside the member. Users are therefore promised an input boundary the parser no longer enforces.
Update the guide, specification, and parser comments to describe the current bounds. The documentation rule requires guides to describe existing behavior and limitations; this requirement must be satisfied before merging.
**Context Used:** Documentation ([source](https://github.com/morluto/rea/blob/main/docs))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
When triaging a Linux kernel image or firmware dump, the first questions are usually which kernel version it is and how it was configured (SELinux, module signing, debug options). The answers sit in the
Linux versionbanner and, when the kernel was built withCONFIG_IKCONFIG, in the gzip.configframed byIKCFG_STandIKCFG_ED. Getting them today means a Linux host andscripts/extract-ikconfig, or a booted system's/proc/config.gz.This adds
inspect_kernel_build_config(CLIinspect-kernel-build-config). It reads one localvmlinuxELF, raw arm64Image, x86bzImage/zImagewith a gzip payload, orconfigs.komodule, and reports the banner and the parsed config options, with an optional exactnamefilter and paging. No issue is linked. This is a proposed new read-only capability.Problem and expected behavior
Use case: an analyst has a kernel image from a device or distribution package and wants its version and selected config options without booting it or using a Linux host.
Observable outcome:
bannerreports theLinux versionstring withversion,builderandcompilersplit out, orabsent/unknownfor what was searched.configispresentonly for a complete, CRC-checked gzip member framed byIKCFG_STandIKCFG_EDwhose text is.configgrammar. Each option has aname, akind(y,m,number,string,not_set) and avalue, withoption_count,matched_countand the requested page.Image.gz, areunsupportedwith the codec named.IKCFG_EDand a member whoseFHCRCheader checksum fails, aremalformed, cut-off members areincomplete, and decoys that use up the search budget giveconfig_search_exhausted. None of these is reported as an absent config.Change and scope
Parsing lives in
src/native/elf/KernelBuildConfig.ts, with the report schema insrc/domain/native/kernelBuildConfig.ts. The compression-magic detection the kernel module parser already had moves intosrc/native/elf/KernelCompressionCodec.ts, so both readers share it.KernelModuleParser.tschanges only to import it. The tool is registered through the existing binary-diagnostics composition, CLI command table, capability declarations and MCP server, like the other native inspection tools. Docs: a newdocs/guides/native/kernel-build-config.mdguide with nav and index entries, a spec underdocs/specs/native/kernel-build-config/, and lines in the authored skill reference.Bounded by default: the file is limited by
max_file_bytes(64 MiB, 512 MiB max), an IKCFG member to 4 MiB of output, a bzImage payload to 128 MiB, 16384 options and 256 entries per page. One search tries at most 16 candidates and inflates at most four timesmax_config_bytesacross them. Each candidate's inflate input ends at its closingIKCFG_ED. Parsing is asynchronous: inflation runs on the zlib thread pool and the scans yield once per MiB, so a cancellation raised during parsing is observed. String values have no length cap beyondmax_config_bytes, as in Kconfig.Not included: decompressing xz, lz4, lzma, zstd, bzip2 or lzo payloads, comparing the config with a source tree, or evaluating Kconfig dependencies.
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
src/native/elf/and report schema insrc/domain/native/, exposed through the binary-diagnostics service. Shared codec detection is extracted from the existing kernel module parser.inspect-kernel-build-configcommand andinspect_kernel_build_configtool. The MCP input requires an absolute path, matching the other local path tools.kernel-build-confignormalized result. Banner text and config values are marked as target-derived and untrusted. Locations name their offset space (fileorinflated_payload).docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): authored skill reference lines, the new guide and its nav and index entries, and the spec. No build output is committed. The## Nativeentry indocs/specs/README.mdmay conflict textually with my other open native-spec PRs; the entries are independent.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/native/elf/KernelBuildConfig.test.ts(decoys, budgets, truncation, bzImage payloads, cancellation), schema tests, service tests, a filesystem boundary test, an MCP boundary test, a CLI acceptance test, and the shared codec and module parser tests.mainthere is no command that reads a kernel banner or embedded config. On this commit I rannode scripts/rea.mjs inspect-kernel-build-config <file> --name CONFIG_SECURITY_SELINUX --jsonon Alpine'slinux-virt6.12.115-r0 x86_64 package, which is built withCONFIG_IKCONFIG=m:boot/vmlinuz-virt(bzImage): the gzip payload at file offset 17092 (11,761,928 bytes) inflates to 39,203,748 bytes. The banner ispresentwith version6.12.115-0-virtand builderbuildozer@build-3-22-x86_64. The config isabsentwith complete coverage, as expected forCONFIG_IKCONFIG=m.lib/modules/6.12.115-0-virt/kernel/kernel/configs.ko: the config ispresentwith 4707 options. That equals theCONFIG_*=and# CONFIG_* is not setlines in the package's ownboot/config-6.12.115-0-virt, and the reportedsha256(d8c7cf26...7683) equals the sha256 of that shipped file.CONFIG_SECURITY_SELINUXcomes back asnot_set, matching that file.--jsonresult forconfigs.kowith--name CONFIG_SECURITY_SELINUX.{ "banner": { "status": "absent" }, "payload": { "container": "file", "status": "uncompressed" }, "config": { "status": "present", "option_count": 4707, "matched_count": 1, "sha256": "d8c7cf26a199df3d39df4c97ff033f6553bc0d5ea529fe82e07cfe9b30e37683", "entries": [ { "name": "CONFIG_SECURITY_SELINUX", "kind": "not_set", "value": null, "trust": "target-derived-untrusted" } ] }, "coverage": { "status": "complete", "examined_bytes": 43863, "examined_entries": 4707 } }Image,vmlinuxELF withCONFIG_IKCONFIG=y, or device firmware kernel was tested against real output; those paths are covered by synthetic fixtures. The real-kernel check is not committed as a script.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
For evidence-bearing changes:
Validation performed
Latest review follow-up: 35 kernel-config source tests and check:fast passed. Validation uses constructed artifacts; no real-target/provider verification was run for this follow-up.
Long kernel config names:
npm run test:local -- src/native/elf/KernelBuildConfig.test.ts src/application/binaryDiagnostics/KernelBuildConfigService.test.ts src/domain/native/kernelBuildConfig.test.tspassed (51 tests), andnpm run check:fastpassed. Synthetic long disabled and assigned names failed before the fix and pass after it; real-kernel verification was not performed.Run on this commit on macOS with Node 24.22.1:
npx --no-install vitest runon the ten changed test files: 247 passed.Compatibility, safety, and release
Author readiness
Human owner: @mvanhorn
Before merge
type(scope): outcome.AI was used for assistance.