Skip to content

Add file-level scanner for Linux kernel module (.ko) metadata - #5249

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

Add file-level scanner for Linux kernel module (.ko) metadata#5249
OctavioValdiviaMendoza wants to merge 10 commits into
aboutcode-org:developfrom
OctavioValdiviaMendoza:feat/625-lkm-package-parser

Conversation

@OctavioValdiviaMendoza

@OctavioValdiviaMendoza OctavioValdiviaMendoza commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #625

This PR adds file-level scanning of metadata embedded in compiled Linux Kernel Module (.ko) files.

Implementation

A new LinuxKernelModuleScanner is implemented in scancode/plugin_lkm.py using ScanCode's file-level ScanPlugin architecture.

The scanner:

  • Is enabled with the --lkm option.
  • Uses pyelftools to open .ko files as ELF files.
  • Locates the .modinfo ELF section.
  • Parses its NUL-terminated key=value entries.
  • Preserves repeated fields such as author, alias, and firmware as lists.
  • Stores the extracted metadata in the file Resource's linux_kernel_module attribute.
  • Normalizes the .modinfo depends value into a simple list of required kernel-module names.

For example:

{
  "linux_kernel_module": {
    "license": ["GPL"],
    "author": ["Example Author"],
    "depends": ["video", "backlight"]
  }
}

Tests

Test coverage includes:

  • .modinfo extraction.
  • Repeated metadata values.
  • Required module-name parsing.
  • Unrelated files.
  • Invalid ELF files.
  • Plugin enablement and Resource attribute declaration.
  • End-to-end --lkm output.
  • Verification that no package_data is created.

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 10 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>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
@OctavioValdiviaMendoza OctavioValdiviaMendoza changed the title Add Package Parser for Linux Kernel Module (.ko) files Add file-level scanner for Linux kernel module (.ko) metadata Aug 6, 2026
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