diff mbox series

[scarthgap,v2,2/8] cve-check: only apply CVE_STATUS to matching products

Message ID 20261201100231.3119168-3-peter.tatrai.ext@siemens.com
State New
Headers show
Series Scope global CVE exclusions by product | expand

Commit Message

P. Tatrai Dec. 1, 2026, 10:02 a.m. UTC
From: Peter Tatrai <peter.tatrai.ext@siemens.com>

Without product filtering, global CVE_STATUS entries are reported for
every recipe. The scarthgap SPDX 3.0 backport [1] and the follow-up that
exports all CVE_STATUS entries [2] also put those entries into the
SPDX/VEX output of unrelated recipes.

This is a partial backport of master commit
452e605b55ad61c08f4af7089a5a9c576ca28f7d. Only has_cve_product_match()
is picked unchanged. The rest of that commit refactors cve-check.bbclass
to pass per-CVE annotations around and changes get_patched_cves() to
return a dict, which is not applicable to scarthgap.

Master applies the match in its callers. Here it is applied once in
decode_cve_status(), so all existing tuple users get it, including
get_patched_cves(), cve-check, VEX and SPDX. Unlike master,
entries without a cpe: scope still apply when CVE_PRODUCT is empty,
so their existing behaviour does not change.

An empty result from decode_cve_status() now usually means the entry
is scoped to another product, which is not a problem. Drop the
per-CVE "Skipping ... missing or unknown CVE status" warnings that
exist only in scarthgap's VEX and SPDX code; they would fire for every
scoped global entry in every recipe. Invalid status details and
malformed cpe: scopes are still warned about by the parser.

[1] https://git.openembedded.org/openembedded-core/commit/?id=9c9b9545049a
[2] https://git.openembedded.org/openembedded-core/commit/?id=9a204670b1c0

AI-Generated: GitHub Copilot CLI, Claude Opus 5.5
Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com>
---
 meta/classes/vex.bbclass    |  1 -
 meta/lib/oe/cve_check.py    | 24 +++++++++++++++++++++++-
 meta/lib/oe/spdx30_tasks.py |  1 -
 3 files changed, 23 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes/vex.bbclass b/meta/classes/vex.bbclass
index 97213ea..3c44dbb 100644
--- a/meta/classes/vex.bbclass
+++ b/meta/classes/vex.bbclass
@@ -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,
diff --git a/meta/lib/oe/cve_check.py b/meta/lib/oe/cve_check.py
index c915ab8..6689d4a 100644
--- a/meta/lib/oe/cve_check.py
+++ b/meta/lib/oe/cve_check.py
@@ -267,13 +267,35 @@  def decode_cve_status_scoped(d, cve):
 
 def decode_cve_status(d, cve):
     """
-    Convert CVE_STATUS into status, detail and description.
+    Convert CVE_STATUS into status, detail and description, ignoring
+    entries scoped to a product not in CVE_PRODUCT.
     """
     status = decode_cve_status_scoped(d, cve)
     if not status:
         return ("", "", "")
+    # Unscoped entries keep applying 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
+
+    #if no match, return False
+    return False
+
 def extend_cve_status(d):
     # do this only once in case multiple classes use this
     if d.getVar("CVE_STATUS_EXTENDED"):
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index 0e9c6fa..539901f 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -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)