bd_kernel_vulns - Script to process the Linux Kernel in a BD project to assess vulns applicability based on supplied list of kernel source files (or folders)
Project description
Black Duck SCA Kernel Vulnerability Processor - bd_kernel_vulns.py v1.1.0
Project Status and Support
This script (bd_kernel_vulns.py) is provided under the MIT license.
It is an open-source utility and does not extend the licensed functionality of Black Duck Software. It is provided "as-is," without warranty or liability.
For comments or issues, please raise a GitHub issue here. Black Duck Support cannot provide assistance for this OSS utility. Users are encouraged to engage with the authors to address any identified issues.
Overview
This script is for licensed users of Black Duck Software only. You will need access to a Black Duck SCA server and an API key to use it.
bd_kernel_vulns is a utility designed to filter and remediate vulnerabilities associated with 'Linux Kernel' components within a Black Duck SCA project version.
It works by accepting a file containing a list of your compiled kernel source files (or folders). Vulnerabilities that reference a kernel source file but do not match any of the files/folders in your supplied list will be automatically marked as remediated in Black Duck.
The default kernel component is Linux Kernel; us the argument --kernel_comp_name NAME to specify a different component for processing. Other components in the project will not be processed.
The default remediation status is NOT_AFFECTED. For Black Duck server versions older than 2025.1, vulnerabilities will be marked as IGNORED instead, as the NOT_AFFECTED remediation status was introduced in the 2025.1 release.
Installation
You have a few options for installing bd_kernel_vulns:
Recommended: Install via pip
- Create a Python virtual environment (recommended):
python3 -m venv venv_bd_kernel_vulns source venv_bd_kernel_vulns/bin/activate # On Windows: .\venv_bd_kernel_vulns\Scripts\activate
- Install the package:
pip3 install bd_kernel_vulns --upgrade
Install from Source (Local Build)
- Clone the repository:
git clone https://github.com/blackducksoftware/bd_kernel_vulns.git cd bd_kernel_vulns
- Create a Python virtual environment (recommended, see above).
- Build the utility:
python3 -m build
- Install the package:
pip3 install dist/bd_kernel_vulns-1.0.X-py3-none-any.whl --upgrade
(Replace1.0.Xwith the actual version number from the built wheel file).
Run Directly from Cloned Repository
- Clone the repository:
git clone https://github.com/blackducksoftware/bd_kernel_vulns.git cd bd_kernel_vulns
- Ensure prerequisite packages are installed:
The required packages are listed in
pyproject.toml. You can install them using:pip3 install -r requirements.txt
(It's highly recommended to do this within a virtual environment).
Prerequisites
Before running this utility, ensure you have:
- Black Duck SCA server 2024.1 or newer.
- Black Duck SCA API Access: A user account with either
Global Project Managerroles orProject BOM Managerroles for the target project. - Python 3.10 or newer.
How to Run
As an Installed Package
- Activate your virtual environment where the utility was installed (if you created one).
- Run the utility:
bd-kernel-vulns [OPTIONS]
From a Cloned Repository
- Activate your virtual environment where dependency packages were installed (if you created one).
- Run the utility:
python3 PATH_TO_REPOSITORY/run.py [OPTIONS]
(ReplacePATH_TO_REPOSITORYwith the actual path to your clonedbd_kernel_vulnsdirectory).
As a Python Function
You can also integrate this utility into another Python program:
from bd_kernel_vulns import main as bdkv_main
bdkv_main.process_kernel_vulns(
blackduck_url="YOUR_BLACKDUCK_URL",
blackduck_api_token="YOUR_API_TOKEN",
kernel_source_file="PATH_TO_KERNEL_SOURCE_LIST.txt",
project="YOUR_BLACKDUCK_PROJECT_NAME",
version="YOUR_BLACKDUCK_PROJECT_VERSION_NAME",
# Optional parameters:
logger=None, # e.g., logging.getLogger(__name__)
blackduck_trust_cert=True,
remediation_status='NOT_AFFECTED',
remediation_justification='NO_CODE',
source_file_names_only=False
)
Interactive UI Mode
If --project, --version, or --kernel_source_file are omitted from the command line, a graphical dialog will be shown to collect the missing values before processing begins. This requires a desktop environment and the PyQt6 package.
- Project / Version selector — shown when
-p/-vare not supplied. Lists all projects on the server; selecting a project loads its versions. A filter box is available for both lists. - Kernel source file selector — shown when
-kis not supplied. Opens a standard file-browser dialog to choose the kernel source list file.
All dialogs can be cancelled to abort the run without error.
Command Line Arguments
usage: bd-kernel-vulns [-h] [--blackduck_url BLACKDUCK_URL] [--blackduck_api_token BLACKDUCK_API_TOKEN]
[--blackduck_trust_cert] [-p PROJECT] [-v VERSION] [-k KERNEL_SOURCE_FILE]
[--folders] [--kernel_comp_name KERNEL_COMP_NAME]
[--remediation_status {REMEDIATION_COMPLETE,NOT_AFFECTED,MITIGATED,DUPLICATE,IGNORED,PATCHED,NEW,UNDER_INVESTIGATION,NEEDS_REVIEW,AFFECTED,REMEDIATION_REQUIRED}]
[--remediation_justification {NO_COMPONENT,NO_CODE,NOT_CONTROLLED,NOT_EXECUTED,ALREADY_MITIGATED,MITIGATION,NO_FIX_PLANNED,NONE_AVAILABLE,VENDOR_FIX,WORKAROUND}]
[--source_file_names_only]
Mark kernel vulnerabilities not within a custom kernel as remediated.
optional arguments:
-h, --help show this help message and exit
REQUIRED arguments:
--blackduck_url BLACKDUCK_URL
Black Duck server URL (REQUIRED, can also use BLACKDUCK_URL env var)
--blackduck_api_token BLACKDUCK_API_TOKEN
Black Duck API token (REQUIRED, can also use BLACKDUCK_API_TOKEN env var)
OPTIONAL arguments (UI dialog shown if omitted):
-p PROJECT, --project PROJECT
Black Duck project name. If omitted, a project/version selector dialog is shown.
-v VERSION, --version VERSION
Black Duck project version name. If omitted, a project/version selector dialog is shown.
-k KERNEL_SOURCE_FILE, --kernel_source_file KERNEL_SOURCE_FILE
Path to a file containing a list of source files (or folders) within your kernel, one per line.
If omitted, a file browser dialog is shown.
OPTIONAL arguments:
--blackduck_trust_cert
Trust the Black Duck server certificate without validation (can use BLACKDUCK_TRUST_CERT env var)
--folders Treat the supplied list in --kernel_source_file as kernel source folders (default is source files).
--kernel_comp_name KERNEL_COMP_NAME
Alternate name for the kernel component (default: 'Linux Kernel').
--remediation_status {REMEDIATION_COMPLETE,NOT_AFFECTED,MITIGATED,DUPLICATE,IGNORED,PATCHED,NEW,UNDER_INVESTIGATION,NEEDS_REVIEW,AFFECTED,REMEDIATION_REQUIRED}
Vulnerability Remediation Status to apply (Default: NOT_AFFECTED).
--remediation_justification {NO_COMPONENT,NO_CODE,NOT_CONTROLLED,NOT_EXECUTED,ALREADY_MITIGATED,MITIGATION,NO_FIX_PLANNED,NONE_AVAILABLE,VENDOR_FIX,WORKAROUND}
Vulnerability Remediation Justification (Default: NO_CODE). Only applied if remediation_status
is 'NOT_AFFECTED' or 'AFFECTED'.
--source_file_names_only
Match only source file names from vulnerabilities against the supplied list, ignoring folder paths.
(Default is to match full folder paths, e.g., 'scripts/mod/file2alias.c'. Use with caution
as this can lead to incorrect matches if files with the same name exist in different modules).
--debug Enable debug logging output.
--logfile LOGFILE Write log output to the specified file.
Remediation Status Logic
The utility automatically applies the default remediation status NOT_AFFECTED (with justification NO_CODE). However, if the connected Black Duck server version is prior to 2025.1.0, the script will automatically change the remediation status to IGNORED because NOT_AFFECTED is not available in older versions.
Defining Kernel Source Files and Folders
The --kernel_source_file argument requires a text file where each line specifies a kernel source file or folder.
-
For Source Files (default behavior):
- Each line should include the full path of the source file, ending with the correct extension (e.g.,
scripts/mod/file2alias.c). - Use forward slashes (
/) as folder separators. - Use the
--source_file_names_onlyoption to match only the base file name, ignoring the full path. Use this option with caution, as it can lead to false positives if different kernel modules contain files with the same name.
- Each line should include the full path of the source file, ending with the correct extension (e.g.,
-
For Source Folders (
--foldersoption):- Each line should contain a kernel source folder (e.g.,
scripts,mod, orscripts/mod). - Leading and trailing
/separators are not required. - A vulnerability referencing a file like
scripts/mod/file2alias.cwill match against the foldersscripts,mod, orscripts/modif they are in your supplied list.
- Each line should contain a kernel source folder (e.g.,
Obtaining Kernel Source File Lists
Here are methods to generate the kernel_source_file list for your specific kernel build:
From a Running Linux Image
You can use lsmod and modinfo to report compiled objects in your running kernel:
lsmod | while read module otherfields
do
modinfo $module | grep '^filename:' | sed -e 's/filename: *//g' -e 's/\.ko\.zst/.c/g'
done > kfiles.lst
From a Yocto Build
The bd_scan_yocto_via_sbom utility is the recommended way to scan Yocto projects. Its --process_kernel_vulns option directly calls this utility to filter kernel vulnerabilities.
If you prefer to use bd_kernel_vulns directly on a Yocto project:
- Locate the modules image archive file for your specific build (usually under
poky/build/tmp/deploy/images/).- Example filename:
modules--6.12.31+git0+f2f3b6cbd9_fee8195f84-r0-qemux86-64-20250608200614.tgz
- Example filename:
- Extract the list of modules from the archive:
tar tf YOUR_MODULES_ARCHIVE_FILE.tgz | grep '.ko$' | sed -e 's/\.ko$/.c/g' > kfiles.lst
From a Buildroot Build
- Locate the Kernel Build Directory:
- Example:
<buildroot_root_directory>/output/build/linux-<kernel_version>/
- Example:
- Identify Compiled Object Files (
.ofiles):find <buildroot_root_directory>/output/build/linux-<kernel_version>/ -name "*.o" | sed -e 's/\.o$/.c/g' > kfiles.lst
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bd_kernel_vulns-1.1.0.tar.gz.
File metadata
- Download URL: bd_kernel_vulns-1.1.0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65bd2d5d5867bed3a162ca2a61f02e5cb96e15b423dd67428da25f693b289aa4
|
|
| MD5 |
3bf26c362723305035a787de217ca893
|
|
| BLAKE2b-256 |
2d7de4b6031ef6e1641161933f94eb9e8ef985bddeb37b3eba83335efc81d8af
|
Provenance
The following attestation bundles were made for bd_kernel_vulns-1.1.0.tar.gz:
Publisher:
publish_pypi.yaml on blackducksoftware/bd_kernel_vulns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_kernel_vulns-1.1.0.tar.gz -
Subject digest:
65bd2d5d5867bed3a162ca2a61f02e5cb96e15b423dd67428da25f693b289aa4 - Sigstore transparency entry: 1189543267
- Sigstore integration time:
-
Permalink:
blackducksoftware/bd_kernel_vulns@44d091cd15f4c627e7e96c08ef0dd3b860300d68 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/blackducksoftware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yaml@44d091cd15f4c627e7e96c08ef0dd3b860300d68 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bd_kernel_vulns-1.1.0-py3-none-any.whl.
File metadata
- Download URL: bd_kernel_vulns-1.1.0-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48718026368919fea01b00a5ad94e5c3e13abd4e50e3a2f67ce328485a92aee8
|
|
| MD5 |
4329286470399c29787aabe353751b42
|
|
| BLAKE2b-256 |
b06c66072e0af7a808bd9075334640d97b8f129ac7cb828302690b0a80e8a7d1
|
Provenance
The following attestation bundles were made for bd_kernel_vulns-1.1.0-py3-none-any.whl:
Publisher:
publish_pypi.yaml on blackducksoftware/bd_kernel_vulns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_kernel_vulns-1.1.0-py3-none-any.whl -
Subject digest:
48718026368919fea01b00a5ad94e5c3e13abd4e50e3a2f67ce328485a92aee8 - Sigstore transparency entry: 1189543269
- Sigstore integration time:
-
Permalink:
blackducksoftware/bd_kernel_vulns@44d091cd15f4c627e7e96c08ef0dd3b860300d68 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/blackducksoftware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yaml@44d091cd15f4c627e7e96c08ef0dd3b860300d68 -
Trigger Event:
release
-
Statement type: