feat(firmware): read the kernel version from outside the rootfs - #750
Merged
Conversation
Every identification pass (cve-bin-tool's own checkers, the ELF presence reader, the version-string supplement) reads only inside the chosen rootfs. Two firmware layouts put the kernel image outside it instead: an install ISO where the boot catalog and the install payload are sibling top-level trees, and an image where the kernel is an intermediate decompression stage on the way down to the rootfs rather than a file inside it. Either shape left the kernel entirely unidentified, so no kernel CVE could ever be matched regardless of index coverage. identify-kernel-version.py reads the whole extraction for the kernel's own two signatures only (a loadable module's vermagic, the kernel's boot banner) -- narrow by pattern, wide by directory scope, which keeps the identify-version-strings.py precision argument intact while still reaching a kernel that sits above or beside the rootfs. Candidates are ranked by evidence grade and support-file count so the answer is order-independent, unlike a depth-based pick which has no structural reason to favor one kernel image over another. Verified against two real firmware images with different signature shapes (one with loadable modules, one with the boot banner only): the kernel component is now identified in each, and the merged security report carries per-CVE findings against linux_kernel that were previously missing entirely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
identify-elf-presence.py,identify-version-strings.py) reads only inside the chosen rootfs (the parent of the shallowestetc). Two firmware layouts put the kernel image outside that directory entirely: an install ISO where the boot catalog and the install payload are sibling top-level trees, and an image where the kernel is an intermediate decompression stage on the way down to the rootfs rather than a file inside it. Either shape left the kernel unidentified, so no kernel CVE could ever be matched no matter how complete the CPE index is.docker/lib/identify-kernel-version.pyreads the whole extraction (not the rootfs) for the kernel's own two signatures only — a loadable module'svermagic=, and the kernel's ownLinux version ... #<n> <weekday>boot banner (both are cve-bin-tool's own patterns,cve_bin_tool/checkers/linux_kernel.py, adjusted for reading raw bytes instead of a pre-extracted string stream). Narrow by pattern, wide by directory scope — this keepsidentify-version-strings.py's closed-table precision argument intact while still reaching a kernel that sits above or beside the rootfs.identify-version-strings.py: that script's marker-stripping dedupe collapses different branches of the tree into the same key once its search directory widens past a single rootfs, which would make reading the kernel-bearing file a coin flip on walk order.identify-version-strings.py's output, so no change to the downstream merge/dedupe logic. Emitscpe:/a:linux:linux_kernel:<version>(the CPE 2.2 form cve-bin-tool's own scan output and the Dockerfile's kernel smoke test both use) —firmware-cpe-match.py's CPE parser only reads parta.linux_kernelthat were previously missing entirely.Test plan
tests/test-firmware-unpack.sh(184 assertions, 0 failed) — new section covers reading a signature outside the rootfs, evidence-grade ranking, the path-collision regressionidentify-version-strings.py's dedupe would have hit, order-independence ofchoose(), thecpe:/a:downstream contract via a synthetic CPE index fed throughfirmware-cpe-match.py, cap-forwarding, and a wiring guard confirming the pass is called with the whole extraction rather than the rootfspython3 -m py_compile docker/lib/identify-kernel-version.pyshellcheck --severity=warningon all three changed shell files (clean)