Skip to content

Commit 8b90a51

Browse files
authored
Merge pull request aboutcode-org#1989 from ziadhany/linux-kernel
Collect existing fix commits for Linux Kernel
2 parents 71408a5 + 8b4bea6 commit 8b90a51

5 files changed

Lines changed: 694 additions & 0 deletions

File tree

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from vulnerabilities.pipelines.v2_importers import gitlab_importer as gitlab_importer_v2
5959
from vulnerabilities.pipelines.v2_importers import glibc_importer as glibc_importer_v2
6060
from vulnerabilities.pipelines.v2_importers import istio_importer as istio_importer_v2
61+
from vulnerabilities.pipelines.v2_importers import linux_kernel_importer as linux_kernel_importer_v2
6162
from vulnerabilities.pipelines.v2_importers import mattermost_importer as mattermost_importer_v2
6263
from vulnerabilities.pipelines.v2_importers import mozilla_importer as mozilla_importer_v2
6364
from vulnerabilities.pipelines.v2_importers import nginx_importer as nginx_importer_v2
@@ -118,6 +119,7 @@
118119
retiredotnet_importer_v2.RetireDotnetImporterPipeline,
119120
ubuntu_osv_importer_v2.UbuntuOSVImporterPipeline,
120121
alpine_linux_importer_v2.AlpineLinuxImporterPipeline,
122+
linux_kernel_importer_v2.LinuxKernelPipeline,
121123
github_importer.GitHubAPIImporterPipeline,
122124
gitlab_importer.GitLabImporterPipeline,
123125
github_osv.GithubOSVImporter,
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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 collections import defaultdict
10+
from pathlib import Path
11+
12+
from fetchcode.vcs import fetch_via_vcs
13+
from univers.version_range import GenericVersionRange
14+
15+
from vulnerabilities.importer import AdvisoryDataV2
16+
from vulnerabilities.importer import AffectedPackageV2
17+
from vulnerabilities.importer import PackageCommitPatchData
18+
from vulnerabilities.importer import PatchData
19+
from vulnerabilities.importer import ReferenceV2
20+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
21+
from vulnerabilities.pipes.advisory import classify_patch_source
22+
from vulnerabilities.utils import commit_regex
23+
from vulnerabilities.utils import cve_regex
24+
from vulnerabilities.utils import is_commit
25+
26+
27+
class LinuxKernelPipeline(VulnerableCodeBaseImporterPipelineV2):
28+
"""
29+
Pipeline to collect Linux Kernel Pipeline:
30+
"""
31+
32+
pipeline_id = "linux_kernel_cves_fix_commits"
33+
spdx_license_expression = "Apache-2.0"
34+
license_url = "https://github.com/nluedtke/linux_kernel_cves/blob/master/LICENSE"
35+
run_once = True
36+
37+
@classmethod
38+
def steps(cls):
39+
return (
40+
cls.clone,
41+
cls.extract_kernel_cve_fix_commits,
42+
cls.collect_and_store_advisories,
43+
cls.clean_downloads,
44+
)
45+
46+
def advisories_count(self):
47+
root = Path(self.vcs_response.dest_dir)
48+
return sum(1 for _ in root.rglob("data/*.txt"))
49+
50+
def clone(self):
51+
self.repo_url = "git+https://github.com/nluedtke/linux_kernel_cves"
52+
self.log(f"Cloning `{self.repo_url}`")
53+
self.vcs_response = fetch_via_vcs(self.repo_url)
54+
55+
def extract_kernel_cve_fix_commits(self):
56+
self.log(f"Processing linux kernel fix commits.")
57+
base_path = Path(self.vcs_response.dest_dir) / "data"
58+
59+
for file_path in base_path.rglob("*.txt"):
60+
if "_CVEs.txt" in file_path.name:
61+
continue
62+
63+
if "_security.txt" in file_path.name:
64+
self.parse_commits_file(file_path)
65+
66+
def collect_advisories(self):
67+
for (
68+
vulnerability_id,
69+
fixed_versions_commits,
70+
) in self.cve_to_fixed_versions_and_commits.items():
71+
references = []
72+
patches = []
73+
affected_packages = []
74+
75+
for fixed_version, commit_hash in fixed_versions_commits:
76+
patch_url = f"https://github.com/torvalds/linux/commit/{commit_hash}"
77+
if not commit_hash:
78+
continue
79+
80+
base_purl, patch_objs = classify_patch_source(
81+
url=patch_url,
82+
commit_hash=commit_hash,
83+
patch_text=None,
84+
)
85+
86+
for patch_obj in patch_objs:
87+
fixed_version_range = GenericVersionRange.from_versions([fixed_version])
88+
if isinstance(patch_obj, PackageCommitPatchData):
89+
fixed_commit = patch_obj
90+
affected_package = AffectedPackageV2(
91+
package=base_purl,
92+
fixed_by_commit_patches=[fixed_commit],
93+
fixed_version_range=fixed_version_range,
94+
)
95+
affected_packages.append(affected_package)
96+
elif isinstance(patch_obj, PatchData):
97+
patches.append(patch_obj)
98+
elif isinstance(patch_obj, ReferenceV2):
99+
references.append(patch_obj)
100+
101+
yield AdvisoryDataV2(
102+
advisory_id=vulnerability_id,
103+
references=references,
104+
affected_packages=affected_packages,
105+
patches=patches,
106+
url="https://github.com/nluedtke/linux_kernel_cves",
107+
)
108+
109+
def parse_commits_file(self, file_path):
110+
"""Extract CVE-ID and commit hashes from a text file"""
111+
self.cve_to_fixed_versions_and_commits = defaultdict(set)
112+
fixed_version = None
113+
with open(file_path, "r", encoding="utf-8") as f:
114+
for line in f:
115+
line = line.strip()
116+
117+
if not line:
118+
continue
119+
120+
if line.startswith("CVEs fixed in"):
121+
fixed_version = line.replace("CVEs fixed in", "").strip().rstrip(":")
122+
continue
123+
124+
parts = line.split(":", 2)
125+
126+
if len(parts) < 2:
127+
continue
128+
129+
cve_part = parts[0]
130+
commit_part = parts[1]
131+
132+
cve_match = cve_regex.search(cve_part)
133+
if not cve_match:
134+
continue
135+
136+
cve = cve_match.group(0)
137+
138+
sha1_match = commit_regex.search(commit_part)
139+
commit_hash = sha1_match.group(0) if sha1_match else None
140+
141+
if not commit_hash or not is_commit(commit_hash):
142+
continue
143+
144+
self.cve_to_fixed_versions_and_commits[cve].add((fixed_version, commit_hash))
145+
146+
def clean_downloads(self):
147+
"""Cleanup any temporary repository data."""
148+
if self.vcs_response:
149+
self.log("Removing cloned repository")
150+
self.vcs_response.delete()
151+
152+
def on_failure(self):
153+
"""Ensure cleanup is always performed on failure."""
154+
self.clean_downloads()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
pipeline.extract_kernel_cve_fix_commits()
28+
result = [adv.to_dict() for adv in pipeline.collect_advisories()]
29+
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)