Skip to content

Commit 57f23f2

Browse files
committed
Add support for collecting Linux kernel commits
Add a test for the Linux kernel Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 6255cb2 commit 57f23f2

File tree

5 files changed

+2587
-0
lines changed

5 files changed

+2587
-0
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from vulnerabilities.pipelines.v2_importers import github_osv_importer as github_osv_importer_v2
5454
from vulnerabilities.pipelines.v2_importers import gitlab_importer as gitlab_importer_v2
5555
from vulnerabilities.pipelines.v2_importers import istio_importer as istio_importer_v2
56+
from vulnerabilities.pipelines.v2_importers import linux_kernel_importer as linux_kernel_importer_v2
5657
from vulnerabilities.pipelines.v2_importers import mattermost_importer as mattermost_importer_v2
5758
from vulnerabilities.pipelines.v2_importers import mozilla_importer as mozilla_importer_v2
5859
from vulnerabilities.pipelines.v2_importers import nginx_importer as nginx_importer_v2
@@ -100,6 +101,7 @@
100101
epss_importer_v2.EPSSImporterPipeline,
101102
nginx_importer_v2.NginxImporterPipeline,
102103
mattermost_importer_v2.MattermostImporterPipeline,
104+
linux_kernel_importer_v2.LinuxKernelPipeline,
103105
nvd_importer.NVDImporterPipeline,
104106
github_importer.GitHubAPIImporterPipeline,
105107
gitlab_importer.GitLabImporterPipeline,
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
from pathlib import Path
10+
11+
from fetchcode.vcs import fetch_via_vcs
12+
13+
from vulnerabilities.importer import AdvisoryData
14+
from vulnerabilities.importer import AffectedPackageV2
15+
from vulnerabilities.importer import PackageCommitPatchData
16+
from vulnerabilities.importer import PatchData
17+
from vulnerabilities.importer import ReferenceV2
18+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
19+
from vulnerabilities.pipes.advisory import classify_patch_source
20+
from vulnerabilities.utils import commit_regex
21+
from vulnerabilities.utils import cve_regex
22+
from vulnerabilities.utils import get_advisory_url
23+
from vulnerabilities.utils import is_commit
24+
25+
26+
class LinuxKernelPipeline(VulnerableCodeBaseImporterPipelineV2):
27+
"""
28+
Pipeline to collect Linux Kernel Pipeline:
29+
"""
30+
31+
pipeline_id = "linux_kernel_cves_fix_commits"
32+
spdx_license_expression = "Apache-2.0"
33+
license_url = "https://github.com/nluedtke/linux_kernel_cves/blob/master/LICENSE"
34+
importer_name = "linux_kernel_cves_fix_commits"
35+
qualified_name = "linux_kernel_cves_fix_commits"
36+
37+
@classmethod
38+
def steps(cls):
39+
return (
40+
cls.clone,
41+
cls.collect_and_store_advisories,
42+
cls.clean_downloads,
43+
)
44+
45+
def advisories_count(self):
46+
root = Path(self.vcs_response.dest_dir)
47+
return sum(1 for _ in root.rglob("data/*.txt"))
48+
49+
def clone(self):
50+
self.repo_url = "git+https://github.com/nluedtke/linux_kernel_cves"
51+
self.log(f"Cloning `{self.repo_url}`")
52+
self.vcs_response = fetch_via_vcs(self.repo_url)
53+
54+
def collect_advisories(self):
55+
self.log(f"Processing linux kernel fix commits.")
56+
base_path = Path(self.vcs_response.dest_dir) / "data"
57+
for file_path in base_path.rglob("*.txt"):
58+
if "_CVEs.txt" in file_path.name:
59+
continue
60+
61+
if "_security.txt" in file_path.name:
62+
patches = []
63+
affected_packages = []
64+
references = []
65+
for vulnerability_id, commit_hash in self.parse_commits_file(file_path):
66+
patch_url = f"https://github.com/torvalds/linux/commit/{commit_hash}"
67+
if not commit_hash:
68+
continue
69+
70+
base_purl, patch_objs = classify_patch_source(
71+
url=patch_url,
72+
commit_hash=commit_hash,
73+
patch_text=None,
74+
)
75+
76+
for patch_obj in patch_objs:
77+
if isinstance(patch_obj, PackageCommitPatchData):
78+
fixed_commit = patch_obj
79+
affected_package = AffectedPackageV2(
80+
package=base_purl,
81+
fixed_by_commit_patches=[fixed_commit],
82+
)
83+
affected_packages.append(affected_package)
84+
elif isinstance(patch_obj, PatchData):
85+
patches.append(patch_obj)
86+
elif isinstance(patch_obj, ReferenceV2):
87+
references.append(patch_obj)
88+
89+
advisory_url = get_advisory_url(
90+
file=file_path,
91+
base_path=self.vcs_response.dest_dir,
92+
url="https://github.com/nluedtke/linux_kernel_cves/blob/master/",
93+
)
94+
95+
yield AdvisoryData(
96+
advisory_id=vulnerability_id,
97+
references_v2=references,
98+
affected_packages=affected_packages,
99+
patches=patches,
100+
url=advisory_url,
101+
)
102+
103+
def parse_commits_file(self, file_path):
104+
"""Extract CVE-ID and commit hashes from a text file"""
105+
with open(file_path, "r", encoding="utf-8") as f:
106+
for line in f:
107+
parts = line.strip().split(":", 2)
108+
109+
if len(parts) < 2:
110+
continue
111+
112+
cve_part = parts[0]
113+
commit_part = parts[1]
114+
115+
cve_match = cve_regex.search(cve_part)
116+
if not cve_match:
117+
continue
118+
119+
cve = cve_match.group(0)
120+
121+
sha1_match = commit_regex.search(commit_part)
122+
commit_hash = sha1_match.group(0) if sha1_match else None
123+
124+
if not commit_hash or not is_commit(commit_hash):
125+
continue
126+
127+
yield cve, commit_hash
128+
129+
def clean_downloads(self):
130+
"""Cleanup any temporary repository data."""
131+
if self.vcs_response:
132+
self.log("Removing cloned repository")
133+
self.vcs_response.delete()
134+
135+
def on_failure(self):
136+
"""Ensure cleanup is always performed on failure."""
137+
self.clean_downloads()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
import os
11+
from pathlib import Path
12+
from unittest.mock import Mock
13+
14+
import pytest
15+
16+
from vulnerabilities.pipelines.v2_importers.linux_kernel_importer import LinuxKernelPipeline
17+
from vulnerabilities.tests import util_tests
18+
19+
TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "linux_kernel"
20+
21+
22+
@pytest.mark.django_db
23+
def test_linux_kernel_advisories():
24+
expected_file = os.path.join(TEST_DATA, "expected-linux-kernel-advisory.json")
25+
pipeline = LinuxKernelPipeline()
26+
pipeline.vcs_response = Mock(dest_dir=TEST_DATA)
27+
result = [adv.to_dict() for adv in pipeline.collect_advisories()]
28+
util_tests.check_results_against_json(result, expected_file)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
CVEs fixed in 3.12:
3+
CVE-2013-4511: 201f99f170df14ba52ea4c52847779042b7a623b uml: check length in exitcode_proc_write()
4+
CVE-2013-4512: 201f99f170df14ba52ea4c52847779042b7a623b uml: check length in exitcode_proc_write()
5+
CVE-2013-4513: c2c65cd2e14ada6de44cb527e7f1990bede24e15 staging: ozwpan: prevent overflow in oz_cdev_write()
6+
CVE-2013-4514: b5e2f339865fb443107e5b10603e53bbc92dc054 staging: wlags49_h2: buffer overflow setting station name
7+
CVE-2013-4515: 8d1e72250c847fa96498ec029891de4dc638a5ba Staging: bcm: info leak in ioctl
8+
CVE-2013-4516: a8b33654b1e3b0c74d4a1fed041c9aae50b3c427 Staging: sb105x: info leak in mp_get_count()
9+
CVE-2013-6383: f856567b930dfcdbc3323261bf77240ccdde01f5 aacraid: missing capable() check in compat ioctl
10+
11+
CVEs fixed in 3.12.1:
12+
CVE-2013-4348: cec64fecff2eff7dd701b883ed3f5f6faf1aab92 net: flow_dissector: fail on evil iph->ihl
13+
14+
CVEs fixed in 3.12.2:
15+
CVE-2013-2929: 9d4dd888b4b5799ecadfb0d8c9adda7a76779806 exec/ptrace: fix get_dumpable() incorrect tests
16+
CVE-2013-2930: 539ddb09c46389cc22d35543e40ccde2c2e20244 perf/ftrace: Fix paranoid level for enabling function tracer
17+
CVE-2013-4345: 8ea7fffd97835f4e3ffd5f757df152a79835f65f crypto: ansi_cprng - Fix off by one error in non-block size request
18+
CVE-2013-6378: 0f6ff65ed8d3630118c3149a4fbc493dd3b8fdc4 libertas: potential oops in debugfs
19+
CVE-2013-6380: 12cc2209deeda65c963c84a5e6aaf0c39aca8e6d aacraid: prevent invalid pointer dereference
20+
CVE-2013-7026: dd272212175ad47ee84cf38e9d5f99502df2d930 ipc,shm: fix shm_file deletion races
21+
22+
CVE-2024-26791: (unk) btrfs: dev-replace: properly validate device names
23+
CVE-2024-26793: (unk) gtp: fix use-after-free and null-ptr-deref in gtp_newlink()
24+
CVE-2024-26797: (unk) drm/amd/display: Prevent potential buffer overflow in map_hw_resources
25+
CVE-2024-26798: (unk) fbcon: always restore the old font data in fbcon_do_set_font()
26+
CVE-2024-26802: (unk) stmmac: Clear variable when destroying workqueue
27+
CVE-2024-26803: (unk) net: veth: clear GRO when clearing XDP even when down
28+
CVE-2024-26804: (unk) net: ip_tunnel: prevent perpetual headroom growth
29+
CVE-2024-26806: (unk) spi: cadence-qspi: remove system-wide suspend helper calls from runtime PM hooks
30+
CVE-2024-26808: (unk) netfilter: nft_chain_filter: handle NETDEV_UNREGISTER for inet/ingress basechain
31+
CVE-2024-26809: (unk) netfilter: nft_set_pipapo: release elements in clone only from destroy path

0 commit comments

Comments
 (0)