Add Package Parser for Linux Kernel Module (.ko) files - #5249
Open
OctavioValdiviaMendoza wants to merge 7 commits into
Open
Add Package Parser for Linux Kernel Module (.ko) files#5249OctavioValdiviaMendoza wants to merge 7 commits into
OctavioValdiviaMendoza wants to merge 7 commits into
Conversation
…ata using .modinfo section found in ELF files to yield the module macros
…s that are now passed to PackageData
…y DependecyPackage and PAckageData are structured correctly
Add Linux Kernel Module package parser Add support for parsing Linux Kernel Module (.ko) files. Add pyelftools as a runtime dependency for reading ELF .modinfo sections, register the new handler, and add unit tests.
…km.py Add self to AUTHORS.rst Signed-off-by: diana-galeana <162429082+diana-galeana@users.noreply.github.com>
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.
Fixes #625
This PR implements support for extracting package metadata from compiled Linux Kernel Module (
.ko) files (issue #625).Implementation
A new
LinuxKernelModuleHandlerhas been added inpackagedcode/lkm.pyusing the existingDatafileHandlerarchitecture.This implementation takes a different approach from the reference implementation:
https://github.com/nexB/scancode-toolkit-contrib/blob/7c5c115a8c3144f60269cfaf2f59b1b639c120aa/src/sourcecode/kernel.py
Rather than scanning the entire binary with regular expressions, the handler opens the module as an ELF file using
pyelftools, locates the.modinfosection, and parses its NUL-terminatedkey=valueentries. This metadata is generated from theMODULE_*macros defined ininclude/linux/module.hand provides the package information embedded in compiled kernel modules.The handler normalizes common metadata into
PackageData, including:Partyobjects)Module dependencies listed in the
dependsfield are parsed intoDependentPackageobjects with runtime scope.Metadata that is not currently represented by the
PackageDatamodel (such asvermagic,srcversion,firmware,alias,softdep, and any additional.modinfokeys) is preserved inextra_data. Repeated metadata entries are also preserved where applicable.If a file is not a valid ELF file or does not contain a
.modinfosection, the handler returns no package data without failing the scan.Tests
Test coverage includes:
.kofile recognition.modinfometadata extractionPartyobjectsextra_data.modinfosectionTasks