@@ -141,7 +141,6 @@ python do_generate_vex () {
for cve_id in (d.getVarFlags("CVE_STATUS") or {}):
mapping, detail, description = decode_cve_status(d, cve_id)
if not mapping or not detail:
- bb.warn(f"Skipping {cve_id} — missing or unknown CVE status")
continue
cve_data[cve_id] = {
"abbrev-status": mapping,
@@ -227,22 +227,84 @@ def convert_cve_version(version):
def decode_cve_status(d, cve):
"""
- Convert CVE_STATUS into status, detail and description.
+ Convert a matching CVE_STATUS into status, detail and description.
+
+ Keep the Scarthgap tuple API for cve-check and existing SPDX consumers.
"""
- status = d.getVarFlag("CVE_STATUS", cve)
+ status = decode_cve_status_scoped(d, cve)
if not status:
return ("", "", "")
+ # Scarthgap applies unscoped statuses even when CVE_PRODUCT is empty.
+ unscoped = status["vendor"] == status["product"] == "*"
+ if not unscoped and not has_cve_product_match(status, d.getVar("CVE_PRODUCT") or ""):
+ return ("", "", "")
+ return (status["mapping"], status["detail"], status["description"])
+
+
+def has_cve_product_match(detailed_status, products):
+ """
+ Check product/vendor match between detailed_status from decode_cve_status and a string of
+ products (like from CVE_PRODUCT)
+ """
+ for product in products.split():
+ vendor = "*"
+ if ":" in product:
+ vendor, product = product.split(":", 1)
+
+ if (vendor == detailed_status["vendor"] or detailed_status["vendor"] == "*") and \
+ (product == detailed_status["product"] or detailed_status["product"] == "*"):
+ return True
- status_split = status.split(':', 1)
- detail = status_split[0]
- description = status_split[1].strip() if (len(status_split) > 1) else ""
+ #if no match, return False
+ return False
+
+def decode_cve_status_scoped(d, cve):
+ """
+ Convert CVE_STATUS into status, vendor, product, detail and description.
+ """
+ status = d.getVarFlag("CVE_STATUS", cve)
+ if not status:
+ return {}
+
+ status_split = status.split(':', 4)
+ status_out = {}
+ status_out["detail"] = status_split[0]
+ product = "*"
+ vendor = "*"
+ description = ""
+ if len(status_split) >= 4 and status_split[1].strip() == "cpe":
+ # Both vendor and product are mandatory if cpe: present, the syntax is then:
+ # detail: cpe:vendor:product:description
+ vendor = status_split[2].strip()
+ product = status_split[3].strip()
+ description = status_split[4].strip()
+ elif len(status_split) >= 2 and status_split[1].strip() == "cpe":
+ # Malformed CPE
+ bb.warn(
+ 'Invalid CPE information for CVE_STATUS[%s] = "%s", not setting CPE'
+ % (cve, status)
+ )
+ else:
+ # Other case: no CPE, the syntax is then:
+ # detail: description
+ description = status.split(':', 1)[1].strip() if (len(status_split) > 1) else ""
+
+ status_out["vendor"] = vendor
+ status_out["product"] = product
+ status_out["description"] = description
+
+ detail = status_out["detail"]
status_mapping = d.getVarFlag("CVE_CHECK_STATUSMAP", detail)
if status_mapping is None:
- bb.warn('Invalid detail "%s" for CVE_STATUS[%s] = "%s", fallback to Unpatched' % (detail, cve, status))
+ bb.warn(
+ 'Invalid detail "%s" for CVE_STATUS[%s] = "%s", fallback to Unpatched'
+ % (detail, cve, status)
+ )
status_mapping = "Unpatched"
+ status_out["mapping"] = status_mapping
- return (status_mapping, detail, description)
+ return status_out
def extend_cve_status(d):
# do this only once in case multiple classes use this
@@ -470,7 +470,6 @@ def _get_cves_info(d):
for cve_id in (d.getVarFlags("CVE_STATUS") or {}):
mapping, detail, description = oe.cve_check.decode_cve_status(d, cve_id)
if not mapping or not detail:
- bb.warn(f"Skipping {cve_id} — missing or unknown CVE status")
continue
yield cve_id, mapping, detail, description
patched_cves.discard(cve_id)
@@ -11,6 +11,54 @@ from oeqa.utils.commands import bitbake, get_bb_vars
class CVECheck(OESelftestTestCase):
+ def test_scoped_status(self):
+ import bb
+ from oe.cve_check import decode_cve_status, extend_cve_status, get_patched_cves
+ from unittest.mock import patch
+
+ d = bb.data.init()
+ cve = "CVE-2020-0001"
+ d.setVarFlag("CVE_CHECK_STATUSMAP", "fixed-version", "Patched")
+ d.setVarFlag("CVE_CHECK_STATUSMAP", "ignored", "Ignored")
+ d.setVarFlag("CVE_STATUS", cve, "fixed-version: cpe:oracle:berkeley_db: Fixed: see upstream")
+ for product, expected in (
+ ("oracle:berkeley_db", ("Patched", "fixed-version", "Fixed: see upstream")),
+ ("other:berkeley_db", ("", "", "")),
+ ("oracle:zlib", ("", "", "")),
+ ("zlib:zlib oracle:berkeley_db", ("Patched", "fixed-version", "Fixed: see upstream")),
+ ):
+ with self.subTest(product=product):
+ d.setVar("CVE_PRODUCT", product)
+ self.assertEqual(decode_cve_status(d, cve), expected)
+ with patch("oe.patch.src_patches", return_value=[]):
+ self.assertEqual(get_patched_cves(d), {cve} if expected[0] else set())
+
+ d.setVar("CVE_PRODUCT", "zlib")
+ d.setVarFlag("CVE_STATUS", cve, "ignored: Existing unscoped reason: unchanged")
+ self.assertEqual(decode_cve_status(d, cve),
+ ("Ignored", "ignored", "Existing unscoped reason: unchanged"))
+ d.setVar("CVE_STATUS_GROUPS", "SCOPED_GROUP")
+ d.setVar("SCOPED_GROUP", cve)
+ d.setVarFlag("SCOPED_GROUP", "status", "ignored: cpe:*:zlib: Matching group")
+ extend_cve_status(d)
+ self.assertEqual(decode_cve_status(d, cve), ("Ignored", "ignored", "Matching group"))
+ d.setVar("CVE_PRODUCT", "glibc")
+ self.assertEqual(decode_cve_status(d, cve), ("", "", ""))
+
+ def test_scoped_status_spdx(self):
+ import bb
+ import oe.spdx30_tasks
+ from unittest.mock import patch
+
+ d = bb.data.init()
+ d.setVar("CVE_PRODUCT", "zlib:zlib")
+ d.setVarFlag("CVE_CHECK_STATUSMAP", "ignored", "Ignored")
+ d.setVarFlag("CVE_STATUS", "CVE-2020-0001", "ignored: cpe:*:berkeley_db: Not zlib")
+ d.setVarFlag("CVE_STATUS", "CVE-2020-0002", "ignored: cpe:*:zlib: Matches zlib")
+ with patch("oe.patch.src_patches", return_value=[]):
+ self.assertEqual(list(oe.spdx30_tasks._get_cves_info(d)),
+ [("CVE-2020-0002", "Ignored", "ignored", "Matches zlib")])
+
def test_version_compare(self):
from oe.cve_check import Version