Skip to content

Add Package Parser for Linux Kernel Module (.ko) files - #5249

Open
OctavioValdiviaMendoza wants to merge 7 commits into
aboutcode-org:developfrom
OctavioValdiviaMendoza:feat/625-lkm-package-parser
Open

Add Package Parser for Linux Kernel Module (.ko) files#5249
OctavioValdiviaMendoza wants to merge 7 commits into
aboutcode-org:developfrom
OctavioValdiviaMendoza:feat/625-lkm-package-parser

Conversation

@OctavioValdiviaMendoza

Copy link
Copy Markdown

Fixes #625

This PR implements support for extracting package metadata from compiled Linux Kernel Module (.ko) files (issue #625).

Implementation

A new LinuxKernelModuleHandler has been added in packagedcode/lkm.py using the existing DatafileHandler architecture.

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 .modinfo section, and parses its NUL-terminated key=value entries. This metadata is generated from the MODULE_* macros defined in include/linux/module.h and provides the package information embedded in compiled kernel modules.

The handler normalizes common metadata into PackageData, including:

  • package name (derived from the module filename)
  • license
  • description
  • version
  • authors (converted into Party objects)

Module dependencies listed in the depends field are parsed into DependentPackage objects with runtime scope.

Metadata that is not currently represented by the PackageData model (such as vermagic, srcversion, firmware, alias, softdep, and any additional .modinfo keys) is preserved in extra_data. Repeated metadata entries are also preserved where applicable.

If a file is not a valid ELF file or does not contain a .modinfo section, the handler returns no package data without failing the scan.

Tests

Test coverage includes:

  • .ko file recognition
  • .modinfo metadata extraction
  • dependency parsing
  • package construction
  • conversion of authors into Party objects
  • preservation of unmapped metadata in extra_data
  • handling of repeated metadata fields
  • invalid ELF files
  • ELF files without a .modinfo section
  • handler registration

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass
  • Commits are in a uniquely named feature branch and have no merge conflicts 📁
  • Updated CHANGELOG.rst (if applicable)
  • Updated documentation pages (if applicable)

OctavioValdiviaMendoza and others added 7 commits July 21, 2026 12:15
…ata using .modinfo section found in ELF files to yield the module macros
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Package parser for LKMs

2 participants