[![GitHub Actions status](https://github.com/evdenis/cvehound/workflows/test/badge.svg)](https://github.com/evdenis/cvehound/actions?query=workflow%3Atest)
[![Supported Versions of Python](https://img.shields.io/pypi/pyversions/cvehound.svg)](https://pypi.org/project/cvehound)
[![PyPI package version](https://img.shields.io/pypi/v/cvehound.svg)](https://pypi.org/project/cvehound)
# CVEhound
CVEhound is a tool for checking linux sources for known CVEs.
The tool is based on [coccinelle](https://coccinelle.gitlabpages.inria.fr/website/)
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](cvehound/cve) 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](cvehound/cve/CVE-2020-12912.cocci)), or for an absence of a fix (e.g. [CVE-2020-26088](cvehound/cve/CVE-2020-26088.cocci));
- **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 an information about what CVEs were fixed by kernel developers upto 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)](docs/LSS2021_CVEhound_en.pdf)
<p align="center">
<a href="https://www.youtube.com/watch?v=jIDnVeZNUA8">
<img src="https://img.youtube.com/vi/jIDnVeZNUA8/0.jpg" alt="Linux Security Summit 2021 Presentation"/>
</a>
</p>
[ZeroNights 2021 Presentation (RU)](docs/ZN2021_CVEhound_ru.pdf)
<p align="center">
<a href="https://www.youtube.com/watch?v=-QwLkpYzQIk">
<img src="https://img.youtube.com/vi/-QwLkpYzQIk/0.jpg" alt="ZeroNights 2021 Presentation"/>
</a>
</p>
### Found issues in stable trees
- CVE-2020-27825 fix [missing backports](https://lkml.org/lkml/2021/1/21/1278) for [5.4, 4.19, 4.14, 4.9, 4.4 kernels](https://www.spinics.net/lists/stable/msg440412.html)
- CVE-2021-4149 fix [missing backports](https://lore.kernel.org/stable/d1a3f31f-2205-6dce-0f33-6611972e48cd@gmx.com/T/#t) to [4.19, 4.14, 4.9 kernels](https://lore.kernel.org/stable/20220309064748.160978-1-denis.e.efremov@oracle.com/)
- CVE-2022-26490 fix [missing backports](https://lore.kernel.org/all/20220321174006.47972-1-denis.e.efremov@oracle.com/)
- CVE-2023-1989 fix missing backports for [6.1, 5.15, 5.10, 5.4, 4.19, 4.14 kernels](https://lore.kernel.org/stable/20230902102200.24474-1-efremov@linux.com/)
- Similar to CVE-2021-28660 [fix in r8188eu driver](https://lore.kernel.org/all/20220518070052.108287-1-denis.e.efremov@oracle.com/#r)
- Similar to CVE-2021-28660 [fix in rtl8723bs driver](https://lore.kernel.org/all/20220520035730.5533-1-efremov@linux.com/)
- Similar to CVE-2022-26490 [fix](https://lore.kernel.org/all/20221122004246.4186422-4-mfaltesek@google.com/) in [st-nci driver](https://lore.kernel.org/all/fc85ff14-70d6-0c3e-247d-eda2284a5f6b@oracle.com/)
- Security [regression CVE-2020-10781](https://lkml.org/lkml/2023/4/17/744)
- See [tests exceptions](https://github.com/evdenis/cvehound/blob/master/tests/test_01_on_branch.py#L7) for more examples
## Prerequisites
- Python 3 (>=3.5)
- pip (Python package manager)
- grep with pcre support (-P flag)
- coccinelle (>= 1.0.7)
Install prerequisites:
``` shell
# Ubuntu, coccinelle uses libpython2.7 internally
# Seems like some ppas mark libpython dependency as optional
$ sudo add-apt-repository ppa:npalix/coccinelle
$ sudo apt install python3-pip coccinelle libpython2.7
# Fedora
$ sudo dnf install python3-pip coccinelle
# macOS
$ brew install coccinelle
```
## Installation
To install the latest stable version just run the following command:
``` shell
$ python3 -m pip install --user cvehound
```
For development purposes you may install cvehound in "editable" mode
directly from the repository (clone it on your computer beforehand):
``` shell
$ pip install -e .
```
To update the cve rules from github repository:
``` shell
$ cvehound_update_rules
```
## How to use
The simplest way to start using CVEhound is to run the following command:
``` shell
$ cvehound --kernel ~/linux
Found: CVE-2020-27830
Found: CVE-2020-27152
Found: CVE-2020-29371
Found: CVE-2020-26088
```
where *dir* should point to linux kernel sources. CVEhound will check the
sources for all cve patterns that you can find in [cve dir](/cvehound/cve/).
To check the sources for particular CVEs one can use:
``` shell
$ 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
CWE: Improper Restriction of Operations within the Bounds of a Memory Buffer
FIX DATE: 2020-10-08 09:02:53
https://www.linuxkernelcves.com/cves/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()
CWE: Use of Uninitialized Resource
FIX DATE: 2020-08-21 16:52:53
https://www.linuxkernelcves.com/cves/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 metainformation in generated report is taken from linuxkernelcves.com
- `--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`, `--cwe` - will limit the scope of checked cves to the kernel files of
interest or specific CWE classes
- `--exploit` - check only for CVEs that are known to be exploitable (according to
the FSTEC BDU database)
## 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:
- [coccinelle](https://coccinelle.gitlabpages.inria.fr/website/) for the program matching engine
- [linuxkernelcves.com](https://linuxkernelcves.com/) for information about Linux CVEs
- [undertaker](https://vamos.informatik.uni-erlangen.de/trac/undertaker) for mapping kernel configs to .c files
- [sympy](https://www.sympy.org/) for the symbolic logic solver
Raw data
{
"_id": null,
"home_page": "http://github.com/evdenis/cvehound",
"name": "cvehound",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": null,
"keywords": "cve, linux, kernel, spatch, cve-scanning, coccinelle",
"author": "Denis Efremov",
"author_email": "efremov@linux.com",
"download_url": "https://files.pythonhosted.org/packages/e0/54/fdc7df3613ac9b2cd61597e00fb52ca0f10e089cf7ebe36a11026136fc11/cvehound-1.2.1.tar.gz",
"platform": null,
"description": "[![GitHub Actions status](https://github.com/evdenis/cvehound/workflows/test/badge.svg)](https://github.com/evdenis/cvehound/actions?query=workflow%3Atest)\n[![Supported Versions of Python](https://img.shields.io/pypi/pyversions/cvehound.svg)](https://pypi.org/project/cvehound)\n[![PyPI package version](https://img.shields.io/pypi/v/cvehound.svg)](https://pypi.org/project/cvehound)\n\n# CVEhound\n\nCVEhound is a tool for checking linux sources for known CVEs.\nThe tool is based on [coccinelle](https://coccinelle.gitlabpages.inria.fr/website/)\nrules and grep patterns. The tool checks sources for vulnerable\ncode patterns of known CVEs and missing fixes for them.\n\n- **What:** The tool tries to find \"unfixed\" code of known CVEs;\n- **How:** The tool uses [coccinelle/grep](cvehound/cve) 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](cvehound/cve/CVE-2020-12912.cocci)), or for an absence of a fix (e.g. [CVE-2020-26088](cvehound/cve/CVE-2020-26088.cocci));\n- **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 an information about what CVEs were fixed by kernel developers upto 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.\n\n### CVEHound: Audit Kernel Sources for Missing CVE Fixes\n\n[Linux Security Summit 2021 Presentation (EN)](docs/LSS2021_CVEhound_en.pdf)\n\n<p align=\"center\">\n <a href=\"https://www.youtube.com/watch?v=jIDnVeZNUA8\">\n <img src=\"https://img.youtube.com/vi/jIDnVeZNUA8/0.jpg\" alt=\"Linux Security Summit 2021 Presentation\"/>\n </a>\n</p>\n\n[ZeroNights 2021 Presentation (RU)](docs/ZN2021_CVEhound_ru.pdf)\n\n<p align=\"center\">\n <a href=\"https://www.youtube.com/watch?v=-QwLkpYzQIk\">\n <img src=\"https://img.youtube.com/vi/-QwLkpYzQIk/0.jpg\" alt=\"ZeroNights 2021 Presentation\"/>\n </a>\n</p>\n\n### Found issues in stable trees\n\n - CVE-2020-27825 fix [missing backports](https://lkml.org/lkml/2021/1/21/1278) for [5.4, 4.19, 4.14, 4.9, 4.4 kernels](https://www.spinics.net/lists/stable/msg440412.html)\n - CVE-2021-4149 fix [missing backports](https://lore.kernel.org/stable/d1a3f31f-2205-6dce-0f33-6611972e48cd@gmx.com/T/#t) to [4.19, 4.14, 4.9 kernels](https://lore.kernel.org/stable/20220309064748.160978-1-denis.e.efremov@oracle.com/)\n - CVE-2022-26490 fix [missing backports](https://lore.kernel.org/all/20220321174006.47972-1-denis.e.efremov@oracle.com/)\n - CVE-2023-1989 fix missing backports for [6.1, 5.15, 5.10, 5.4, 4.19, 4.14 kernels](https://lore.kernel.org/stable/20230902102200.24474-1-efremov@linux.com/)\n - Similar to CVE-2021-28660 [fix in r8188eu driver](https://lore.kernel.org/all/20220518070052.108287-1-denis.e.efremov@oracle.com/#r)\n - Similar to CVE-2021-28660 [fix in rtl8723bs driver](https://lore.kernel.org/all/20220520035730.5533-1-efremov@linux.com/)\n - Similar to CVE-2022-26490 [fix](https://lore.kernel.org/all/20221122004246.4186422-4-mfaltesek@google.com/) in [st-nci driver](https://lore.kernel.org/all/fc85ff14-70d6-0c3e-247d-eda2284a5f6b@oracle.com/)\n - Security [regression CVE-2020-10781](https://lkml.org/lkml/2023/4/17/744)\n - See [tests exceptions](https://github.com/evdenis/cvehound/blob/master/tests/test_01_on_branch.py#L7) for more examples\n\n## Prerequisites\n\n- Python 3 (>=3.5)\n- pip (Python package manager)\n- grep with pcre support (-P flag)\n- coccinelle (>= 1.0.7)\n\nInstall prerequisites:\n``` shell\n# Ubuntu, coccinelle uses libpython2.7 internally\n# Seems like some ppas mark libpython dependency as optional\n$ sudo add-apt-repository ppa:npalix/coccinelle\n$ sudo apt install python3-pip coccinelle libpython2.7\n\n# Fedora\n$ sudo dnf install python3-pip coccinelle\n\n# macOS\n$ brew install coccinelle\n```\n\n## Installation\n\nTo install the latest stable version just run the following command:\n\n``` shell\n$ python3 -m pip install --user cvehound\n```\n\nFor development purposes you may install cvehound in \"editable\" mode\ndirectly from the repository (clone it on your computer beforehand):\n\n``` shell\n$ pip install -e .\n```\n\nTo update the cve rules from github repository:\n\n``` shell\n$ cvehound_update_rules\n```\n\n## How to use\n\nThe simplest way to start using CVEhound is to run the following command:\n\n``` shell\n$ cvehound --kernel ~/linux\nFound: CVE-2020-27830\nFound: CVE-2020-27152\nFound: CVE-2020-29371\nFound: CVE-2020-26088\n```\n\nwhere *dir* should point to linux kernel sources. CVEhound will check the\nsources for all cve patterns that you can find in [cve dir](/cvehound/cve/).\nTo check the sources for particular CVEs one can use:\n\n``` shell\n$ cvehound --kernel ./linux --kernel-config --cve CVE-2020-27194 CVE-2020-29371\nChecking: CVE-2020-27194\nFound: CVE-2020-27194\nMSG: bpf: Fix scalar32_min_max_or bounds tracking\nCWE: Improper Restriction of Operations within the Bounds of a Memory Buffer\nFIX DATE: 2020-10-08 09:02:53\nhttps://www.linuxkernelcves.com/cves/CVE-2020-27194\nAffected Files:\n - linux/kernel/bpf/verifier.c: CONFIG_BPF & CONFIG_BPF_SYSCALL\n linux/.config: affected\nConfig: ./linux/.config affected\n\nChecking: CVE-2020-29371\nFound: CVE-2020-29371\nMSG: romfs: fix uninitialized memory leak in romfs_dev_read()\nCWE: Use of Uninitialized Resource\nFIX DATE: 2020-08-21 16:52:53\nhttps://www.linuxkernelcves.com/cves/CVE-2020-29371\nAffected Files:\n - linux/fs/romfs/storage.c: CONFIG_ROMFS_FS\n linux/.config: not affected\nConfig: ./linux/.config not affected\n```\n\nOther args:\n - `--report` - will produce json file with found CVEs\n Most of metainformation in generated report is taken from linuxkernelcves.com\n - `--kernel-config` or `--kernel-config <file>` - will infer the kernel configuration required to\n build the affected code (based on Kbuild/Makefiles, ifdefs are not checked) and\n check kernel .config file if there is one\n - `--files`, `--cwe` - will limit the scope of checked cves to the kernel files of\n interest or specific CWE classes\n - `--exploit` - check only for CVEs that are known to be exploitable (according to\n the FSTEC BDU database)\n\n## LICENSE\n\nPython code is licensed under GPLv3. All rules in cvehound/cve folder are licensed under GPLv2.\n\n## Acknowledgements\n\nI would like to thank the following projects and people behind them:\n - [coccinelle](https://coccinelle.gitlabpages.inria.fr/website/) for the program matching engine\n - [linuxkernelcves.com](https://linuxkernelcves.com/) for information about Linux CVEs\n - [undertaker](https://vamos.informatik.uni-erlangen.de/trac/undertaker) for mapping kernel configs to .c files\n - [sympy](https://www.sympy.org/) for the symbolic logic solver\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "A tool to check linux kernel source dump for known CVEs",
"version": "1.2.1",
"project_urls": {
"Homepage": "http://github.com/evdenis/cvehound"
},
"split_keywords": [
"cve",
" linux",
" kernel",
" spatch",
" cve-scanning",
" coccinelle"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7d8b2bb18a66c32d537abf0e4903beef2309fc91c59158d0fe4491b6fe07d921",
"md5": "a15c33523c3358400e1c8f456a255daa",
"sha256": "a174a7a96294dde8e66c0de421cd8371418e9bbb92979ebaff56644753e82274"
},
"downloads": -1,
"filename": "cvehound-1.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a15c33523c3358400e1c8f456a255daa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 1283287,
"upload_time": "2024-05-04T11:06:41",
"upload_time_iso_8601": "2024-05-04T11:06:41.248791Z",
"url": "https://files.pythonhosted.org/packages/7d/8b/2bb18a66c32d537abf0e4903beef2309fc91c59158d0fe4491b6fe07d921/cvehound-1.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e054fdc7df3613ac9b2cd61597e00fb52ca0f10e089cf7ebe36a11026136fc11",
"md5": "8e93b7570ce8a31af1d6be809616ceba",
"sha256": "3c6c0cb02e11d6862cb77764bae1b8545b4f8babdc950778f2a1edfda3d4339d"
},
"downloads": -1,
"filename": "cvehound-1.2.1.tar.gz",
"has_sig": false,
"md5_digest": "8e93b7570ce8a31af1d6be809616ceba",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 2949121,
"upload_time": "2024-05-04T11:06:44",
"upload_time_iso_8601": "2024-05-04T11:06:44.051603Z",
"url": "https://files.pythonhosted.org/packages/e0/54/fdc7df3613ac9b2cd61597e00fb52ca0f10e089cf7ebe36a11026136fc11/cvehound-1.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-04 11:06:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "evdenis",
"github_project": "cvehound",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "cvehound"
}