Skip to main content

GitHub Actions status Supported Versions of Python PyPI package version

CVEhound

CVEhound is a tool for checking Linux sources for known CVEs. The tool is based on coccinelle rules and grep patterns. The tool checks sources for vulnerable code patterns of known CVEs and missing fixes for them.

  • What: The tool tries to find "unfixed" code of known CVEs;
  • How: The tool uses coccinelle/grep rules with patterns that helps to detect known CVE bugs or their fixes. Thus, sources are checked either for a presence of "unfixed" code pieces (e.g. CVE-2020-12912), or for an absence of a fix (e.g. CVE-2020-26088);
  • Why: If you have a git log then it's easier to check what CVEs are fixed based on a git history. However, many vendors (samsung, huawei, various iot, routers manufacturers) publish kernel sources as archives without a development log. In most cases their kernels are based on LTS kernels, but versions are far from upstream. Linux version string from Makefile will only give you information about what CVEs were fixed by kernel developers up to this version. It will not help you to understand what fixes were backported by a vendor itself. In this case it's possible to apply the tool and check "missing" CVE fixes.

CVEHound: Audit Kernel Sources for Missing CVE Fixes

Linux Security Summit 2021 Presentation (EN)

Linux Security Summit 2021 Presentation

ZeroNights 2021 Presentation (RU)

ZeroNights 2021 Presentation

Found issues in stable trees

Installation

$ python3 -m pip install --user 'cvehound[spatch]'

That brings a prebuilt, tailored spatch along with the tool (cvehound-spatch), so there is nothing else to install and no coccinelle build to keep in step. It is used automatically unless you name another spatch explicitly.

Prerequisites: Python 3.11+, grep with PCRE support (-P), and diffutils (spatch renders what it matched by running diff).

The wheel covers Linux on x86_64 and aarch64, and macOS on arm64. Anywhere else, drop the [spatch] part and provide coccinelle (>= 1.1.0) yourself — apt install coccinelle, dnf install coccinelle, brew install coccinelle. A development install from a clone takes the extra too: pip install -e '.[spatch]'.

Updating rules and metadata

Detection rules and CVE metadata evolve much faster than the tool. To refresh both without upgrading cvehound:

$ cvehound update

Updates are downloaded from the project's rolling content-latest GitHub release, verified against a checksummed manifest, and installed atomically under ~/.local/share/cvehound/ — the installed package is never modified. cvehound update --check only reports whether an update is available (exit code 10 when one is, handy for cron), and cvehound --version shows exactly which rules and metadata are in use. If the downloaded content is missing or invalid, cvehound falls back to the rules and metadata bundled with the package.

The metadata location can also be pinned with --metadata <file> or the CVEHOUND_METADATA environment variable, and default CLI options can be set in /etc/cvehound.ini or ~/.config/cvehound.ini (see --config).

Which spatch runs is chosen the same way: --spatch <path> (or a spatch key in the config file), else the CVEHOUND_SPATCH environment variable, else the bundled cvehound-spatch package if it is installed, else whatever is on PATH. A binary you name explicitly is never silently replaced by a fallback — if it does not resolve, cvehound stops and says so.

How to use

The simplest way to start using CVEhound is to run the following command:

$ cvehound --kernel ~/linux
Found: CVE-2020-27830
Found: CVE-2020-27152
Found: CVE-2020-29371
Found: CVE-2020-26088

where dir should point to the Linux kernel sources. CVEhound will check the sources for all cve patterns that you can find in cve dir. To check the sources for particular CVEs one can use:

$ cvehound --kernel ./linux --kernel-config --cve CVE-2020-27194 CVE-2020-29371
Checking: CVE-2020-27194
Found: CVE-2020-27194
MSG: bpf: Fix scalar32_min_max_or bounds tracking
FIX DATE: 2020-10-08 09:02:53
https://www.cve.org/CVERecord?id=CVE-2020-27194
Affected Files:
 - linux/kernel/bpf/verifier.c: CONFIG_BPF & CONFIG_BPF_SYSCALL
   linux/.config: affected
Config: ./linux/.config affected

Checking: CVE-2020-29371
Found: CVE-2020-29371
MSG: romfs: fix uninitialized memory leak in romfs_dev_read()
FIX DATE: 2020-08-21 16:52:53
https://www.cve.org/CVERecord?id=CVE-2020-29371
Affected Files:
 - linux/fs/romfs/storage.c: CONFIG_ROMFS_FS
   linux/.config: not affected
Config: ./linux/.config not affected

Other args:

  • --report - will produce json file with found CVEs Most of the metainformation in the generated report is taken from kernel.org vulns.git and CIP kernel-sec. Rules that could not be checked are listed separately under errors (a rule that blew its time budget, a spatch failure, a rule needing a newer spatch), so an empty results can be told apart from a scan that did not finish
  • --kernel-config or --kernel-config <file> - will infer the kernel configuration required to build the affected code (based on Kbuild/Makefiles, ifdefs are not checked) and check kernel .config file if there is one. Files the parser can't map to CONFIG_ options are reported as unknown and counted as affected
  • --check-strict - with --kernel-config, report only CVEs whose affected files are enabled in the .config. A CVE is dropped only when the evaluation explicitly rules every affected file out (e.g. the option is disabled, or the file belongs to another architecture); files unknown to the Kbuild parser are still reported with a warning
  • --arch - kernel architecture to analyze (x86, arm64, ...; ARCH spellings like x86_64 are normalized to the arch/ source directory). Defaults to the architecture from the .config banner, or x86
  • --files - will limit the scope of checked cves to the kernel files of interest
  • --exploit - check only for CVEs that are known to be exploitable (according to the CISA Known Exploited Vulnerabilities catalog)
  • --sandbox - auto (default), off, or strict. Confines the scan with Landlock and seccomp so a detection rule cannot reach past the tree it is scanning: the kernel tree is read-only, your home directory and the network are unreachable, and only a temp directory is writable. auto falls back to an unconfined scan when the kernel cannot do it (Landlock needs 5.13+, enabled at boot) and says so under --verbose; strict refuses to scan instead. $CVEHOUND_SANDBOX sets the default.
  • --zygote - auto (default), off, or on. Runs spatch as one warm server per worker, forking a fresh process per rule, instead of starting spatch once per rule. auto uses it when the installed cvehound-spatch says it can (the wheel records what it was built with); any other spatch keeps one process per rule. Every rule still runs in its own process, so this changes what a scan costs, never what it finds.
  • --cache[=DIR] - reuse parsed C between rules that target the same file, kept in DIR (bare --cache puts it under the cvehound cache directory, keyed by the spatch that wrote it). Off by default, and worth understanding before turning on: it costs roughly 310 MB per kernel tree scanned, and a first scan of today's rule set is marginally slower with it, because only about a fifth of the parses repeat. It pays off when you scan the same tree more than once (a rescan is ~25% faster) or when running thousands of rules, where the repeats dominate. Nothing shrinks the cache on its own, so cvehound evicts least-recently-used entries past a few GB, and --cache-clear empties it.

Contributing

Development Setup

The project uses uv for dependency and environment management.

# Install uv (once, globally)
$ curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone and create the dev environment
$ git clone https://github.com/evdenis/cvehound.git
$ cd cvehound
$ uv sync                         # creates .venv and installs dev deps

# Install pre-commit hooks
$ uv run pre-commit install

# Run all linters, formatters, and type checks
$ uv run pre-commit run --all-files

# Run the test suite
$ uv run pytest

The project uses:

  • uv for dependency and environment management
  • ruff for linting and formatting
  • ty (beta) for static type checking — replaces mypy; version is pinned via uv.lock
  • pre-commit for automated code quality checks

Writing CVE Detection Rules

If you'd like to contribute new CVE detection rules, please see our comprehensive guides:

Templates:

  • contrib/template.cocci - Enhanced template with examples and comments
  • contrib/blank.cocci - Minimal template for new rules

If you use a coding agent, the repository ships a write-cve-rule skill in .agents/skills/ (picked up by OpenAI Codex, and by Claude Code via .claude/skills/). It drives the workflow above and runs .agents/skills/write-cve-rule/scripts/validate-rule.sh, which you can also call by hand — see AGENTS.md.

License

Python code is licensed under GPLv3. All rules in cvehound/cve folder are licensed under GPLv2.

Acknowledgements

I would like to thank the following projects and people behind them:

Release files for cvehound 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cvehound 1.6.1
File Size Uploaded
cvehound-1.6.1.tar.gz 1.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for cvehound 1.6.1
File Interpreter ABI Platform
cvehound-1.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 3.7 MB

Release files / cvehound-1.6.1.tar.gz

Download URL cvehound-1.6.1.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
3ee656245349aa1497ffd315f5fcd87508705de445f88de4e0693d7337890405
BLAKE2b-256 checksum
How to use checksums
8f4fec378bb610b6a2db4f90efa1c8530a556aec333e6796b0a1584abdeddff9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cvehound-1.6.1-py3-none-any.whl

Download URL cvehound-1.6.1-py3-none-any.whl
Size 1.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4cacad1b565e20487582ca432852ec8263042ac8eb2d85aab3a8d14c8d7eb0fa
BLAKE2b-256 checksum
How to use checksums
b40f6f47ae006dc28b1947a2eabee0d89a7adcedf57258c8c07530131dd597b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

1.7.0

2 release files

This release

1.6.1 This release

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page