diff --git a/compliance-agent/src/pipeline/yocto_build.rs b/compliance-agent/src/pipeline/yocto_build.rs index 3a99d4f..771a636 100644 --- a/compliance-agent/src/pipeline/yocto_build.rs +++ b/compliance-agent/src/pipeline/yocto_build.rs @@ -19,7 +19,8 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use compliance_core::models::{ - CveAlert, InImage, InImageBasis, SbomEntry, VexAssessment, VexStatus, YOCTO_RECIPE_MANAGER, + CveAlert, InImage, InImageBasis, SbomEntry, VexAssessment, VexJustification, VexStatus, + YOCTO_RECIPE_MANAGER, }; use crate::pipeline::nvd_cpe::NvdCve; @@ -132,6 +133,13 @@ impl<'a> Built<'a> { let issue = self.checked.get(package)?.get(cve)?; let (status, justification) = match issue.status { CheckStatus::Unpatched => return None, + // Yocto's kernel CVE report (improve_kernel_cve_report.py) says + // Patched when the version is outside the affected range: not + // affected rather than fixed. + CheckStatus::Patched if issue.detail.as_deref() == Some("version-not-in-range") => ( + VexStatus::NotAffected, + Some(VexJustification::VulnerableCodeNotPresent), + ), CheckStatus::Patched => (VexStatus::Fixed, None), CheckStatus::Ignored => { yocto_inventory::status_statement(issue.detail.as_deref().unwrap_or("ignored"))? @@ -591,4 +599,53 @@ mod tests { // A recipe that is not a component of the scan gets nothing. assert!(built.unpatched_missing(&have, |_| false).is_empty()); } + + #[test] + fn the_kernel_report_filtered_by_compiled_files_settles_kernel_cves() { + // Yocto's improve_kernel_cve_report.py over a real scarthgap kernel + // (linux-yocto 6.6.151) with its compiled sources and the kernel + // CNA's data, trimmed to two CVEs of each verdict. + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../fixtures/yocto/linux-yocto.improved-cve-report.json"); + let checks = vec![crate::pipeline::yocto_cve_check::read(&path).unwrap()]; + let built = Built::new(&[], &checks); + let version = "6.6.151+git"; + let status = |cve: &str| { + built + .statements(&[], &[alert("linux-yocto", version, cve)]) + .first() + .map(|(_, v)| (v.status, v.justification)) + }; + // Its files are not compiled into this kernel. + assert_eq!( + status("CVE-2023-52586"), + Some(( + VexStatus::NotAffected, + Some(VexJustification::VulnerableCodeNotPresent) + )) + ); + // Withdrawn by the kernel's CNA. + assert_eq!( + status("CVE-2021-46907").map(|s| s.0), + Some(VexStatus::NotAffected) + ); + // Outside the affected versions: not affected, not "fixed". + assert_eq!( + status("CVE-2024-0053"), + Some(( + VexStatus::NotAffected, + Some(VexJustification::VulnerableCodeNotPresent) + )) + ); + assert_eq!( + status("CVE-2019-25160").map(|s| s.0), + Some(VexStatus::Fixed) + ); + assert_eq!( + status("CVE-2022-48669").map(|s| s.0), + Some(VexStatus::Fixed) + ); + // In range and not patched: open. + assert_eq!(status("CVE-2024-42067"), None); + } } diff --git a/compliance-agent/src/pipeline/yocto_inventory.rs b/compliance-agent/src/pipeline/yocto_inventory.rs index ede61f9..0fdf4e8 100644 --- a/compliance-agent/src/pipeline/yocto_inventory.rs +++ b/compliance-agent/src/pipeline/yocto_inventory.rs @@ -829,6 +829,8 @@ pub(crate) fn status_statement(status: &str) -> Option<(VexStatus, Option Some((VexStatus::NotAffected, None)), "not-applicable-platform" | "not-applicable-config" => Some(( VexStatus::NotAffected, Some(VexJustification::VulnerableCodeNotPresent), diff --git a/docs/guide/yocto.md b/docs/guide/yocto.md index a242c54..8cccdab 100644 --- a/docs/guide/yocto.md +++ b/docs/guide/yocto.md @@ -330,8 +330,10 @@ CVEs the recipes' patches fixed (*CVEs fixed* in the SPDX) are stated as | cve-check | VEX statement | |---|---| | Patched (also `fixed-version`, `cpe-stable-backport`, `backported-patch`) | fixed | +| Patched `version-not-in-range` | not affected (vulnerable code not present) | | Ignored `not-applicable-config`, `not-applicable-platform` | not affected (vulnerable code not present) | | Ignored `cpe-incorrect` | not affected (component not present) | +| Ignored `rejected` (withdrawn by its CNA) | not affected | | Ignored `disputed`, `upstream-wontfix`, `ignored` | under investigation, with the recipe's note | | Unpatched | none: the CVE stays open | @@ -343,6 +345,28 @@ thousands of CVEs for it. The build's SPDX and cve-check mark almost all of them as patched, so they arrive as **fixed**; the ones Yocto reports unpatched stay open. +**Kernel CVEs and the kernel configuration.** Many kernel CVEs concern code your +kernel configuration does not build. Yocto's own script +`scripts/contrib/improve_kernel_cve_report.py` (in OpenEmbedded-Core since +Scarthgap 5.0) checks each kernel CVE of the Linux kernel CNA against the files +your kernel actually compiled, and writes the cve-check report again with those +CVEs set to *Ignored, not-applicable-config*. Upload that report **instead of** +the image's cve-check report: + +```sh +git clone --depth 1 https://git.kernel.org/pub/scm/linux/security/vulns.git +python3 poky/scripts/contrib/improve_kernel_cve_report.py \ + --debug-sources-file tmp/pkgdata//debugsources/linux-yocto-debugsources.json.zstd \ + --datadir vulns \ + --old-cve-report tmp/deploy/images//.json \ + --new-cve-report .kernel-filtered.json +``` + +The debug-sources list is written by every build; no rebuild is needed. On a +Scarthgap `core-image-minimal` (linux-yocto 6.6.151) this set 2,230 of the +kernel's 22,001 CVEs to not applicable for the configuration and 337 to +rejected; the remaining unpatched ones stay open. + **On the run.** A file that is neither an image SPDX archive nor a cve-check report is listed under **Build-SPDX (Yocto-Image)** and skipped. So is a package the image lists without its document in the archive. A new upload starts a new diff --git a/fixtures/yocto/linux-yocto.improved-cve-report.json b/fixtures/yocto/linux-yocto.improved-cve-report.json new file mode 100644 index 0000000..094445f --- /dev/null +++ b/fixtures/yocto/linux-yocto.improved-cve-report.json @@ -0,0 +1,144 @@ +{ + "package": [ + { + "issue": [ + { + "description": "specific to ugidd, part of the old user-mode NFS server", + "detail": "not-applicable-config", + "id": "CVE-1999-0656", + "link": "https://nvd.nist.gov/vuln/detail/CVE-1999-0656", + "scorev2": "5.0", + "scorev3": "0.0", + "scorev4": "0.0", + "status": "Ignored", + "summary": "The ugidd RPC interface, by design, allows remote attackers to enumerate valid usernames by specifying arbitrary UIDs that ugidd maps to local user and group...", + "vector": "NETWORK", + "vectorString": "AV:N/AC:L/Au:N/C:P/I:N/A:N" + }, + { + "description": "Source code not compiled by config. {'drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c', 'drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c', 'drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c', 'drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys.h'}", + "detail": "not-applicable-config", + "id": "CVE-2023-52586", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2023-52586", + "scorev2": "0.0", + "scorev3": "7.8", + "scorev4": "0.0", + "status": "Ignored", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\ndrm/msm/dpu: Add mutex lock in control vblank irq\n\nAdd a mutex lock to control vblank ir...", + "vector": "LOCAL", + "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H" + }, + { + "description": "2.6.34 (1871c6)", + "detail": "fixed-version", + "id": "CVE-2010-0298", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2010-0298", + "scorev2": "6.5", + "scorev3": "0.0", + "scorev4": "0.0", + "status": "Patched", + "summary": "The x86 emulator in KVM 83 does not use the Current Privilege Level (CPL) and I/O Privilege Level (IOPL) in determining the memory access available to CPL3 c...", + "vector": "NETWORK", + "vectorString": "AV:N/AC:L/Au:S/C:P/I:P/A:P" + }, + { + "description": "Fixed from version 5.0", + "detail": "fixed-version", + "id": "CVE-2019-25160", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2019-25160", + "scorev2": "0.0", + "scorev3": "9.1", + "scorev4": "0.0", + "status": "Patched", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\nnetlabel: fix out-of-bounds memory accesses\n\nThere are two array out-of-bounds memory ac...", + "vector": "NETWORK", + "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:H" + }, + { + "description": "Rejected by CNA", + "detail": "rejected", + "id": "CVE-2019-25161", + "status": "Ignored", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\ndrm/amd/display: prevent memory leak\n\nIn dcn*_create_resource_pool the allocated memory ..." + }, + { + "description": "Rejected by CNA", + "detail": "rejected", + "id": "CVE-2021-46907", + "status": "Ignored", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\nKVM: VMX: Don't use vcpu->run->internal.ndata as an array index\n\n__vmx_handle_exit() use..." + }, + { + "description": "Backported in 6.6.3", + "detail": "cpe-stable-backport", + "id": "CVE-2021-47432", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2021-47432", + "scorev2": "0.0", + "scorev3": "5.5", + "scorev4": "0.0", + "status": "Patched", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\nlib/generic-radix-tree.c: Don't overflow in peek()\n\nWhen we started spreading new inode ...", + "vector": "LOCAL", + "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H" + }, + { + "description": "Backported in 6.6.23", + "detail": "cpe-stable-backport", + "id": "CVE-2022-48669", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2022-48669", + "scorev2": "0.0", + "scorev3": "5.5", + "scorev4": "0.0", + "status": "Patched", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\npowerpc/pseries: Fix potential memleak in papr_get_attr()\n\n`buf` is allocated in papr_ge...", + "vector": "LOCAL", + "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H" + }, + { + "description": "No CPE match", + "detail": "version-not-in-range", + "id": "CVE-2024-0000", + "status": "Patched", + "summary": "It's not safe to call nfsd_put once nfsd_last_thread has been called, as\n\nthat function will zero out the nn->nfsd_serv pointer.\n\nDrop the nfsd_put helper al..." + }, + { + "description": "No CPE match", + "detail": "version-not-in-range", + "id": "CVE-2024-0053", + "status": "Patched", + "summary": "nfsd: drop the nfsd_put helper\n\nIt's not safe to call nfsd_put once nfsd_last_thread has been called, as\nthat function will zero out the nn->nfsd_serv pointe..." + }, + { + "description": "Needs backporting (fixed from 6.6.160)", + "detail": "version-in-range", + "id": "CVE-2024-14040", + "status": "Unpatched", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\nnet: nexthop: Increase weight to u16\n\nIn CLOS networks, as link failures occur at variou..." + }, + { + "description": "Needs backporting (fixed from 6.6.160)", + "detail": "version-in-range", + "id": "CVE-2024-42067", + "link": "https://nvd.nist.gov/vuln/detail/CVE-2024-42067", + "scorev2": "0.0", + "scorev3": "7.8", + "scorev4": "0.0", + "status": "Unpatched", + "summary": "In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Take return from set_memory_rox() into account with bpf_jit_binary_lock_ro()\n\nset_m...", + "vector": "LOCAL", + "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H" + } + ], + "layer": "meta", + "name": "linux-yocto", + "products": [ + { + "cvesInRecord": "Yes", + "product": "linux_kernel" + } + ], + "version": "6.6.151+git" + } + ], + "version": "1" +}