feat(yocto): Yocto's own cve-check verdicts join the scan (#150)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m26s
CI / Check (pull_request) Successful in 16m38s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m26s
CI / Check (pull_request) Successful in 16m38s
With INHERIT += "cve-check" a build writes <image>.json next to the image: per recipe the CVEs NVD records for it, each Patched, Ignored (with the CVE_STATUS reason) or Unpatched. It is uploaded as a build output like the image SPDX; the scan tells the two apart by content. - pipeline::yocto_cve_check reads the report (size-capped). - Built takes the reports: Yocto's verdict on an alert's CVE comes first (Patched is fixed, Ignored as the reason maps, the same table as the recipes' CVE_STATUS; the note is kept), then the SPDX's fixed list, then the recipe in the tree. - CVEs cve-check found unpatched that the NVD match missed are added as alerts on the scan's recipe components, with NVD's description and score from the report. The fixture is a trimmed copy of a real scarthgap 5.0.21 report for core-image-minimal (glibc, busybox and zlib with every status). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e637964c02
commit
009ad2042a
6 files changed
+762
-21
No files matched your search
@@ -55,6 +55,7 @@ pub mod variants;
|
||||
pub mod vendor;
|
||||
pub mod vex_lifecycle;
|
||||
pub mod yocto_build;
|
||||
pub mod yocto_cve_check;
|
||||
pub mod yocto_inventory;
|
||||
pub mod yocto_pins;
|
||||
pub mod yocto_spdx;
|
||||
@@ -559,8 +559,8 @@ impl PipelineOrchestrator {
|
||||
}
|
||||
// What the build installed, from its image SPDX: joined with the
|
||||
// inventory by recipe name, the build's version and image marking win.
|
||||
let built_images = self.read_build_outputs(repo, &repo_id, scan_run_id).await;
|
||||
let built = crate::pipeline::yocto_build::Built::new(&built_images);
|
||||
let (built_images, cve_checks) = self.read_build_outputs(repo, &repo_id, scan_run_id).await;
|
||||
let built = crate::pipeline::yocto_build::Built::new(&built_images, &cve_checks);
|
||||
let yocto_entries = built.merge(yocto_inventory::entries(
|
||||
&yocto.recipes,
|
||||
&declarations,
|
||||
@@ -721,6 +721,22 @@ impl PipelineOrchestrator {
|
||||
.await;
|
||||
}
|
||||
}
|
||||
// What the build's cve-check found unpatched and the match above did
|
||||
// not (another version range, a CPE NVD's API matches differently).
|
||||
let missing = built.unpatched_missing(&cve_alerts, |name| {
|
||||
sbom_entries
|
||||
.iter()
|
||||
.any(|e| e.package_manager == YOCTO_RECIPE_MANAGER && e.name == name)
|
||||
});
|
||||
for (name, version, cves) in missing {
|
||||
cve_alerts.extend(crate::pipeline::cve::record_nvd(
|
||||
&repo_id,
|
||||
&mut sbom_entries,
|
||||
&name,
|
||||
&version,
|
||||
cves,
|
||||
));
|
||||
}
|
||||
|
||||
self.match_advisories(&repo_id, &mut sbom_entries, &mut cve_alerts)
|
||||
.await;
|
||||
@@ -2629,17 +2645,27 @@ impl PipelineOrchestrator {
|
||||
/// The recipes, images and package groups of a Yocto layer tree. A parser
|
||||
/// that failed, a tree with no layer, or recipes the parser could not read
|
||||
/// are recorded on the run.
|
||||
/// The images the target's build outputs describe
|
||||
/// ([`crate::pipeline::yocto_spdx`]). One that cannot be read is noted on
|
||||
/// the run (and skipped), and so are packages the archive lists in an
|
||||
/// image without their documents.
|
||||
/// What the target's build outputs say: the images their SPDX archives
|
||||
/// describe ([`crate::pipeline::yocto_spdx`]) and their cve-check reports
|
||||
/// ([`crate::pipeline::yocto_cve_check`]), told apart by content. One
|
||||
/// that cannot be read is noted on the run (and skipped), and so are
|
||||
/// packages an archive lists in an image without their documents.
|
||||
async fn read_build_outputs(
|
||||
&self,
|
||||
repo: &RepoView,
|
||||
repo_id: &str,
|
||||
scan_run_id: &str,
|
||||
) -> Vec<crate::pipeline::yocto_spdx::BuiltImage> {
|
||||
) -> (
|
||||
Vec<crate::pipeline::yocto_spdx::BuiltImage>,
|
||||
Vec<crate::pipeline::yocto_cve_check::CveCheck>,
|
||||
) {
|
||||
/// One build output, read as what it is.
|
||||
enum Read {
|
||||
Images(Vec<crate::pipeline::yocto_spdx::BuiltImage>),
|
||||
Check(crate::pipeline::yocto_cve_check::CveCheck),
|
||||
}
|
||||
let mut images = Vec::new();
|
||||
let mut checks = Vec::new();
|
||||
for path in &repo.build_outputs {
|
||||
let name = path
|
||||
.file_name()
|
||||
@@ -2647,16 +2673,31 @@ impl PipelineOrchestrator {
|
||||
.unwrap_or_default();
|
||||
let file = path.clone();
|
||||
let id = repo_id.to_string();
|
||||
let read = tokio::task::spawn_blocking(move || {
|
||||
let read = tokio::task::spawn_blocking(move || -> Result<Read, String> {
|
||||
let mut head = [0u8; 512];
|
||||
let n = {
|
||||
use std::io::Read as _;
|
||||
std::fs::File::open(&file)
|
||||
.and_then(|mut f| f.read(&mut head))
|
||||
.map_err(|e| e.to_string())?
|
||||
};
|
||||
if crate::pipeline::yocto_cve_check::is_cve_check(&head[..n]) {
|
||||
return crate::pipeline::yocto_cve_check::read(&file)
|
||||
.map(Read::Check)
|
||||
.map_err(|e| e.to_string());
|
||||
}
|
||||
crate::pipeline::yocto_spdx::read_archive(
|
||||
&file,
|
||||
&id,
|
||||
crate::pipeline::yocto_spdx::ReadLimits::default(),
|
||||
)
|
||||
.map(Read::Images)
|
||||
.map_err(|e| e.to_string())
|
||||
})
|
||||
.await;
|
||||
match read {
|
||||
Ok(Ok(read)) => images.extend(read),
|
||||
Ok(Ok(Read::Images(read))) => images.extend(read),
|
||||
Ok(Ok(Read::Check(check))) => checks.push(check),
|
||||
Ok(Err(e)) => {
|
||||
tracing::warn!(scan_run_id, file = %name, error = %e, "build output not read");
|
||||
self.skip_stage(
|
||||
@@ -2666,7 +2707,8 @@ impl PipelineOrchestrator {
|
||||
SkipCode::ArtifactNotIngested,
|
||||
format!(
|
||||
"{name} was not read as a Yocto image SPDX archive \
|
||||
(<image>.spdx.tar.zst): {e}"
|
||||
(<image>.spdx.tar.zst) or cve-check report \
|
||||
(<image>.json): {e}"
|
||||
),
|
||||
)
|
||||
.about(name),
|
||||
@@ -2698,7 +2740,7 @@ impl PipelineOrchestrator {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
images
|
||||
(images, checks)
|
||||
}
|
||||
|
||||
async fn yocto_recipes(&self, tree: &std::path::Path, scan_run_id: &str) -> Inventory {
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
//!
|
||||
//! The build also says which CVEs its patches fixed; those become `fixed`
|
||||
//! VEX statements on the matching alerts, ahead of what the recipes state.
|
||||
//! Its cve-check report ([`crate::pipeline::yocto_cve_check`]), when it was
|
||||
//! uploaded too, goes first: Yocto's verdict on every CVE it looked at, and
|
||||
//! the CVEs it found unpatched that NVD's match here did not.
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||
|
||||
@@ -19,6 +22,8 @@ use compliance_core::models::{
|
||||
CveAlert, InImage, InImageBasis, SbomEntry, VexAssessment, VexStatus, YOCTO_RECIPE_MANAGER,
|
||||
};
|
||||
|
||||
use crate::pipeline::nvd_cpe::NvdCve;
|
||||
use crate::pipeline::yocto_cve_check::{CheckStatus, CheckedIssue, CveCheck};
|
||||
use crate::pipeline::yocto_inventory::{self, CpeProduct, NvdQuery, Recipe};
|
||||
use crate::pipeline::yocto_spdx::BuiltImage;
|
||||
|
||||
@@ -31,12 +36,26 @@ pub struct Built<'a> {
|
||||
images: BTreeSet<String>,
|
||||
/// The CVEs fixed per recipe name.
|
||||
fixed: HashMap<String, BTreeSet<&'a str>>,
|
||||
/// Yocto's cve-check verdicts per recipe name, by CVE.
|
||||
checked: HashMap<&'a str, HashMap<&'a str, &'a CheckedIssue>>,
|
||||
/// The version cve-check names each recipe at.
|
||||
checked_versions: BTreeMap<&'a str, &'a str>,
|
||||
}
|
||||
|
||||
impl<'a> Built<'a> {
|
||||
/// Gather `images` (from one or more build-output archives).
|
||||
pub fn new(images: &'a [BuiltImage]) -> Self {
|
||||
/// Gather `images` (from one or more build-output archives) and the
|
||||
/// cve-check reports `checks`.
|
||||
pub fn new(images: &'a [BuiltImage], checks: &'a [CveCheck]) -> Self {
|
||||
let mut built = Self::default();
|
||||
for package in checks.iter().flat_map(|c| &c.packages) {
|
||||
built
|
||||
.checked_versions
|
||||
.insert(package.name.as_str(), package.version.as_str());
|
||||
let issues = built.checked.entry(package.name.as_str()).or_default();
|
||||
for issue in &package.issues {
|
||||
issues.insert(issue.id.as_str(), issue);
|
||||
}
|
||||
}
|
||||
for image in images {
|
||||
built.images.insert(image.image.clone());
|
||||
for entry in &image.entries {
|
||||
@@ -60,7 +79,81 @@ impl<'a> Built<'a> {
|
||||
|
||||
/// Whether the build listed nothing.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.components.is_empty()
|
||||
self.components.is_empty() && self.checked.is_empty()
|
||||
}
|
||||
|
||||
/// The CVEs cve-check found unpatched that `alerts` do not have, per
|
||||
/// recipe and version (the built one where the build lists the recipe),
|
||||
/// for recipes `known` (components of the scan) only.
|
||||
pub fn unpatched_missing(
|
||||
&self,
|
||||
alerts: &[CveAlert],
|
||||
known: impl Fn(&str) -> bool,
|
||||
) -> Vec<(String, String, Vec<NvdCve>)> {
|
||||
let mut out = Vec::new();
|
||||
for (name, issues) in &self.checked {
|
||||
if !known(name) {
|
||||
continue;
|
||||
}
|
||||
let version = self
|
||||
.components
|
||||
.get(*name)
|
||||
.map(|c| c.version.as_str())
|
||||
.or_else(|| self.checked_versions.get(name).copied())
|
||||
.unwrap_or_default();
|
||||
let mut missing: Vec<NvdCve> = issues
|
||||
.values()
|
||||
.filter(|i| i.status == CheckStatus::Unpatched)
|
||||
.filter(|i| {
|
||||
!alerts
|
||||
.iter()
|
||||
.any(|a| a.affected_package == *name && a.cve_id == i.id)
|
||||
})
|
||||
.map(|i| NvdCve {
|
||||
id: i.id.clone(),
|
||||
summary: i.summary.clone(),
|
||||
cvss: i.cvss(),
|
||||
})
|
||||
.collect();
|
||||
if missing.is_empty() {
|
||||
continue;
|
||||
}
|
||||
missing.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
out.push((name.to_string(), version.to_string(), missing));
|
||||
}
|
||||
out.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
out
|
||||
}
|
||||
|
||||
/// Yocto's cve-check verdict on `cve` of `package`, as a statement:
|
||||
/// Patched is fixed, Ignored as its CVE_STATUS reason says, Unpatched
|
||||
/// none.
|
||||
fn checked_statement(&self, package: &str, cve: &str) -> Option<VexAssessment> {
|
||||
let issue = self.checked.get(package)?.get(cve)?;
|
||||
let (status, justification) = match issue.status {
|
||||
CheckStatus::Unpatched => return None,
|
||||
CheckStatus::Patched => (VexStatus::Fixed, None),
|
||||
CheckStatus::Ignored => {
|
||||
yocto_inventory::status_statement(issue.detail.as_deref().unwrap_or("ignored"))?
|
||||
}
|
||||
};
|
||||
let verdict = match issue.status {
|
||||
CheckStatus::Patched => "Patched",
|
||||
CheckStatus::Ignored => "Ignored",
|
||||
CheckStatus::Unpatched => "Unpatched",
|
||||
};
|
||||
let mut because = format!("Yocto cve-check: {verdict}");
|
||||
if let Some(detail) = issue.detail.as_deref() {
|
||||
because.push_str(&format!(" ({detail})"));
|
||||
}
|
||||
if let Some(note) = issue.description.as_deref().filter(|n| !n.is_empty()) {
|
||||
because.push_str(&format!(": {note}"));
|
||||
}
|
||||
Some(yocto_inventory::scan_statement(
|
||||
status,
|
||||
justification,
|
||||
because,
|
||||
))
|
||||
}
|
||||
|
||||
/// The SBOM components: `inventory` (the recipe inventory's) joined with
|
||||
@@ -193,12 +286,19 @@ impl<'a> Built<'a> {
|
||||
recipes: &[Recipe],
|
||||
alerts: &[CveAlert],
|
||||
) -> Vec<(String, VexAssessment)> {
|
||||
let (built_alerts, other): (Vec<&CveAlert>, Vec<&CveAlert>) = alerts
|
||||
.iter()
|
||||
.partition(|a| self.components.contains_key(&a.affected_package));
|
||||
let (built_alerts, other): (Vec<&CveAlert>, Vec<&CveAlert>) =
|
||||
alerts.iter().partition(|a| {
|
||||
self.components.contains_key(&a.affected_package)
|
||||
|| self.checked.contains_key(a.affected_package.as_str())
|
||||
});
|
||||
let mut out: Vec<(String, VexAssessment)> = built_alerts
|
||||
.iter()
|
||||
.filter_map(|alert| {
|
||||
if let Some(checked) =
|
||||
self.checked_statement(&alert.affected_package, &alert.cve_id)
|
||||
{
|
||||
return Some((alert.cve_id.clone(), checked));
|
||||
}
|
||||
let fixed = self
|
||||
.fixed
|
||||
.get(&alert.affected_package)
|
||||
@@ -302,7 +402,7 @@ mod tests {
|
||||
#[test]
|
||||
fn the_build_wins_by_recipe_name_whatever_version_the_tree_names() {
|
||||
let images = built_images();
|
||||
let built = Built::new(&images);
|
||||
let built = Built::new(&images, &[]);
|
||||
let merged = built.merge(vec![
|
||||
// PV in the tree differs from what the build recorded.
|
||||
inventory("busybox", "1.36", &["core-image-minimal", "rescue-image"]),
|
||||
@@ -349,7 +449,7 @@ mod tests {
|
||||
#[test]
|
||||
fn nvd_is_asked_with_the_built_version_and_cpe() {
|
||||
let images = built_images();
|
||||
let built = Built::new(&images);
|
||||
let built = Built::new(&images, &[]);
|
||||
let stale = NvdQuery {
|
||||
name: "busybox".into(),
|
||||
version: "1.36".into(),
|
||||
@@ -386,7 +486,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_cve_the_build_patched_is_stated_fixed() {
|
||||
let images = built_images();
|
||||
let built = Built::new(&images);
|
||||
let built = Built::new(&images, &[]);
|
||||
let alert = |package: &str, cve: &str| {
|
||||
CveAlert::new(
|
||||
cve.into(),
|
||||
@@ -421,4 +521,74 @@ mod tests {
|
||||
assert_eq!(product("cpe:2.3:a:*:*:1:*"), None);
|
||||
assert_eq!(product("cpe:/a:x:y"), None);
|
||||
}
|
||||
|
||||
fn checks() -> Vec<CveCheck> {
|
||||
let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../fixtures/yocto/core-image-minimal-qemuarm64.rootfs.cve.json");
|
||||
vec![crate::pipeline::yocto_cve_check::read(&path).unwrap()]
|
||||
}
|
||||
|
||||
fn alert(package: &str, version: &str, cve: &str) -> CveAlert {
|
||||
CveAlert::new(
|
||||
cve.into(),
|
||||
"t".into(),
|
||||
package.into(),
|
||||
version.into(),
|
||||
compliance_core::models::CveSource::Nvd,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yoctos_own_verdict_comes_first() {
|
||||
let images = built_images();
|
||||
let checks = checks();
|
||||
let built = Built::new(&images, &checks);
|
||||
let statements = built.statements(
|
||||
&[],
|
||||
&[
|
||||
// Patched, with the reason.
|
||||
alert("glibc", "2.39+git", "CVE-2024-2961"),
|
||||
// Ignored as disputed: still to be assessed, with the note.
|
||||
alert("glibc", "2.39+git", "CVE-2019-1010022"),
|
||||
// Ignored as not applicable to the configuration.
|
||||
alert("zlib", "1.3.1", "CVE-2026-22184"),
|
||||
// Unpatched: no statement.
|
||||
alert("glibc", "2.39+git", "CVE-2026-5450"),
|
||||
],
|
||||
);
|
||||
let by_cve = |cve: &str| statements.iter().find(|(c, _)| c == cve).map(|(_, v)| v);
|
||||
let patched = by_cve("CVE-2024-2961").unwrap();
|
||||
assert_eq!(patched.status, VexStatus::Fixed);
|
||||
assert!(patched
|
||||
.impact_statement
|
||||
.as_deref()
|
||||
.unwrap()
|
||||
.starts_with("Yocto cve-check: Patched (cpe-stable-backport)"));
|
||||
assert_eq!(
|
||||
by_cve("CVE-2019-1010022").unwrap().status,
|
||||
VexStatus::UnderInvestigation
|
||||
);
|
||||
assert_eq!(
|
||||
by_cve("CVE-2026-22184").unwrap().status,
|
||||
VexStatus::NotAffected
|
||||
);
|
||||
assert!(by_cve("CVE-2026-5450").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unpatched_cves_the_match_missed_are_added() {
|
||||
let images = built_images();
|
||||
let checks = checks();
|
||||
let built = Built::new(&images, &checks);
|
||||
let have = [alert("glibc", "2.39+git", "CVE-2026-5450")];
|
||||
let missing = built.unpatched_missing(&have, |name| name != "zlib");
|
||||
assert_eq!(missing.len(), 1);
|
||||
let (name, version, cves) = &missing[0];
|
||||
assert_eq!((name.as_str(), version.as_str()), ("glibc", "2.39+git"));
|
||||
let ids: Vec<&str> = cves.iter().map(|c| c.id.as_str()).collect();
|
||||
assert_eq!(ids, ["CVE-2010-4756", "CVE-2026-5928"]);
|
||||
assert_eq!(cves[1].cvss, Some(7.5));
|
||||
// A recipe that is not a component of the scan gets nothing.
|
||||
assert!(built.unpatched_missing(&have, |_| false).is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
//! What Yocto's own CVE check says about an image: its `cve-check` JSON.
|
||||
//!
|
||||
//! With `INHERIT += "cve-check"` a build matches every recipe against NVD
|
||||
//! and writes, next to the image, `<image>.json`: per recipe (`package`)
|
||||
//! its version and the CVEs NVD records for its products, each `Patched`
|
||||
//! (a patch or the version fixes it), `Ignored` (a CVE_STATUS sets it aside,
|
||||
//! with the reason as `detail`) or `Unpatched`. Unlike the SPDX's
|
||||
//! "CVEs fixed", this covers every CVE the build looked at, with Yocto's
|
||||
//! reason.
|
||||
//!
|
||||
//! [`read`] parses the file; [`is_cve_check`] recognises one among a target's
|
||||
//! build outputs.
|
||||
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Bytes a cve-check JSON may have (a large product image's is ~50 MB).
|
||||
pub const MAX_BYTES: u64 = 256 * 1024 * 1024;
|
||||
|
||||
/// Yocto's verdict on one CVE of one recipe.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||
pub enum CheckStatus {
|
||||
Patched,
|
||||
Unpatched,
|
||||
Ignored,
|
||||
}
|
||||
|
||||
/// One CVE of one recipe, as cve-check reports it.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct CheckedIssue {
|
||||
pub id: String,
|
||||
pub status: CheckStatus,
|
||||
/// The CVE_STATUS reason (`fixed-version`, `cpe-stable-backport`,
|
||||
/// `not-applicable-config`, `disputed`, …), where one applies.
|
||||
#[serde(default)]
|
||||
pub detail: Option<String>,
|
||||
/// The CVE_STATUS note the recipe gives with it.
|
||||
#[serde(default)]
|
||||
pub description: Option<String>,
|
||||
/// NVD's description.
|
||||
#[serde(default)]
|
||||
pub summary: Option<String>,
|
||||
/// CVSS v3 base score as text (`"9.8"`, `"0.0"` for none).
|
||||
#[serde(default)]
|
||||
pub scorev3: Option<String>,
|
||||
}
|
||||
|
||||
impl CheckedIssue {
|
||||
/// The CVSS v3 base score, `None` when NVD gives none.
|
||||
pub fn cvss(&self) -> Option<f64> {
|
||||
self.scorev3
|
||||
.as_deref()
|
||||
.and_then(|s| s.parse::<f64>().ok())
|
||||
.filter(|s| *s > 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// One recipe of the image.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct CheckedPackage {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
#[serde(default, rename = "issue")]
|
||||
pub issues: Vec<CheckedIssue>,
|
||||
}
|
||||
|
||||
/// A cve-check report.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct CveCheck {
|
||||
#[serde(rename = "package")]
|
||||
pub packages: Vec<CheckedPackage>,
|
||||
}
|
||||
|
||||
/// Why a cve-check JSON could not be read.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum CveCheckError {
|
||||
#[error("cannot read the cve-check report: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error("the cve-check report is larger than {MAX_BYTES} bytes")]
|
||||
TooLarge,
|
||||
#[error("not a Yocto cve-check JSON report: {0}")]
|
||||
NotCveCheck(String),
|
||||
}
|
||||
|
||||
/// Whether the file starting with `head` is a cve-check report: a JSON
|
||||
/// object whose first keys include `package` or `version`.
|
||||
pub fn is_cve_check(head: &[u8]) -> bool {
|
||||
let text = String::from_utf8_lossy(head);
|
||||
let text = text.trim_start();
|
||||
text.starts_with('{') && (text.contains("\"package\"") || text.contains("\"version\""))
|
||||
}
|
||||
|
||||
/// Read the cve-check report at `path`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The file cannot be read, is larger than [`MAX_BYTES`], or is not a
|
||||
/// cve-check report.
|
||||
pub fn read(path: &Path) -> Result<CveCheck, CveCheckError> {
|
||||
let file = std::fs::File::open(path)?;
|
||||
let mut bytes = Vec::new();
|
||||
file.take(MAX_BYTES + 1).read_to_end(&mut bytes)?;
|
||||
if bytes.len() as u64 > MAX_BYTES {
|
||||
return Err(CveCheckError::TooLarge);
|
||||
}
|
||||
serde_json::from_slice(&bytes).map_err(|e| CveCheckError::NotCveCheck(e.to_string()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::expect_used, clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A trimmed copy of a real scarthgap (5.0.21) core-image-minimal's
|
||||
/// cve-check report: glibc, busybox and zlib with each status.
|
||||
fn fixture() -> std::path::PathBuf {
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../fixtures/yocto/core-image-minimal-qemuarm64.rootfs.cve.json")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_report_lists_each_recipe_with_yoctos_verdicts() {
|
||||
let check = read(&fixture()).unwrap();
|
||||
let names: Vec<(&str, &str)> = check
|
||||
.packages
|
||||
.iter()
|
||||
.map(|p| (p.name.as_str(), p.version.as_str()))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
names,
|
||||
[
|
||||
("glibc", "2.39+git"),
|
||||
("busybox", "1.36.1"),
|
||||
("zlib", "1.3.1")
|
||||
]
|
||||
);
|
||||
let glibc = &check.packages[0];
|
||||
let status = |id: &str| glibc.issues.iter().find(|i| i.id == id).unwrap();
|
||||
assert_eq!(status("CVE-2024-2961").status, CheckStatus::Patched);
|
||||
assert_eq!(
|
||||
status("CVE-2024-2961").detail.as_deref(),
|
||||
Some("cpe-stable-backport")
|
||||
);
|
||||
assert_eq!(status("CVE-2019-1010022").status, CheckStatus::Ignored);
|
||||
assert_eq!(
|
||||
status("CVE-2019-1010022").detail.as_deref(),
|
||||
Some("disputed")
|
||||
);
|
||||
assert!(status("CVE-2019-1010022").description.is_some());
|
||||
let unpatched: Vec<&str> = glibc
|
||||
.issues
|
||||
.iter()
|
||||
.filter(|i| i.status == CheckStatus::Unpatched)
|
||||
.map(|i| i.id.as_str())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
unpatched,
|
||||
["CVE-2010-4756", "CVE-2026-5450", "CVE-2026-5928"]
|
||||
);
|
||||
assert_eq!(status("CVE-2026-5450").cvss(), Some(9.8));
|
||||
// "0.0" is no score.
|
||||
assert_eq!(status("CVE-2010-4756").cvss(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_report_is_recognised_by_its_start() {
|
||||
let head = std::fs::read(fixture()).unwrap();
|
||||
assert!(is_cve_check(&head[..64.min(head.len())]));
|
||||
assert!(!is_cve_check(&[0x28, 0xb5, 0x2f, 0xfd]));
|
||||
assert!(!is_cve_check(b"[1, 2]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn something_else_is_refused() {
|
||||
let dir = std::env::temp_dir().join(format!("cs-cvecheck-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("x.json");
|
||||
std::fs::write(&path, br#"{"spdxVersion": "SPDX-2.2"}"#).unwrap();
|
||||
assert!(matches!(read(&path), Err(CveCheckError::NotCveCheck(_))));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
@@ -820,7 +820,7 @@ pub fn nvd_queries(recipes: &[Recipe]) -> (Vec<NvdQuery>, Vec<String>) {
|
||||
/// set aside (`upstream-wontfix`, `disputed`, `ignored`) `under_investigation`
|
||||
/// with the reason as a note. `unpatched` and `vulnerable-investigation` make
|
||||
/// none: the alert stays open for a person to assess.
|
||||
fn status_statement(status: &str) -> Option<(VexStatus, Option<VexJustification>)> {
|
||||
pub(crate) fn status_statement(status: &str) -> Option<(VexStatus, Option<VexJustification>)> {
|
||||
match status {
|
||||
"backported-patch" | "cpe-stable-backport" | "fixed-version" => {
|
||||
Some((VexStatus::Fixed, None))
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
{
|
||||
"package": [
|
||||
{
|
||||
"issue": [
|
||||
{
|
||||
"id": "CVE-1999-0199",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-1999-0199",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "manual/search.texi in the GNU C Library (aka glibc) before 2.2 lacks a statement about the unspecified tdelete return value upon deletion of a tree's root, w...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2000-0335",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2000-0335",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The resolver in glibc 2.1.3 uses predictable IDs, which allows a local attacker to spoof DNS query results.",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"description": "fix available in used git hash",
|
||||
"detail": "cpe-stable-backport",
|
||||
"id": "CVE-2024-2961",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2024-2961",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "7.3",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The iconv() function in the GNU C Library versions 2.39 and older may overflow the output buffer passed to it by up to 4 bytes when converting strings to the...",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H"
|
||||
},
|
||||
{
|
||||
"description": "fix available in used git hash",
|
||||
"detail": "cpe-stable-backport",
|
||||
"id": "CVE-2024-33599",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2024-33599",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "8.1",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "nscd: Stack-based buffer overflow in netgroup cache\n\nIf the Name Service Cache Daemon's (nscd) fixed size cache is exhausted\nby client requests then a subseq...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"description": "Upstream glibc maintainers dispute there is any issue and have no plans to address it further. this is being treated as a non-security bug and no real threat.",
|
||||
"detail": "disputed",
|
||||
"id": "CVE-2019-1010022",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2019-1010022",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Ignored",
|
||||
"summary": "GNU Libc current is affected by: Mitigation bypass. The impact is: Attacker may bypass stack guard protection. The component is: nptl. The attack vector is: ...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"description": "Upstream glibc maintainers dispute there is any issue and have no plans to address it further. this is being treated as a non-security bug and no real threat.",
|
||||
"detail": "disputed",
|
||||
"id": "CVE-2019-1010023",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2019-1010023",
|
||||
"scorev2": "6.8",
|
||||
"scorev3": "8.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Ignored",
|
||||
"summary": "GNU Libc current is affected by: Re-mapping current loaded library with malicious ELF file. The impact is: In worst case attacker may evaluate privileges. Th...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:M/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2010-4756",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2010-4756",
|
||||
"scorev2": "4.0",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Unpatched",
|
||||
"summary": "The glob implementation in the GNU C Library (aka glibc or libc6) allows remote authenticated users to cause a denial of service (CPU and memory consumption)...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:S/C:N/I:N/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-5450",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2026-5450",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Unpatched",
|
||||
"summary": "Calling the scanf family of functions with a %mc (malloc'd character match) in the GNU C Library version 2.7 to version 2.43 with a format width specifier wi...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-5928",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2026-5928",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "7.5",
|
||||
"scorev4": "0.0",
|
||||
"status": "Unpatched",
|
||||
"summary": "Calling the ungetwc function on a FILE stream with wide characters encoded in a character set that has overlaps between its single byte and multi-byte charac...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
|
||||
}
|
||||
],
|
||||
"layer": "meta",
|
||||
"name": "glibc",
|
||||
"products": [
|
||||
{
|
||||
"cvesInRecord": "Yes",
|
||||
"product": "glibc"
|
||||
}
|
||||
],
|
||||
"version": "2.39+git"
|
||||
},
|
||||
{
|
||||
"issue": [
|
||||
{
|
||||
"id": "CVE-2006-1058",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2006-1058",
|
||||
"scorev2": "2.1",
|
||||
"scorev3": "5.5",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "BusyBox 1.1.1 does not use a salt when generating passwords, which makes it easier for local users to guess passwords from a stolen password file using techn...",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "AV:L/AC:L/Au:N/C:P/I:N/A:N"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2022-48174",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2022-48174",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "There is a stack overflow vulnerability in ash.c:6030 in busybox before 1.35. In the environment of Internet of Vehicles, this vulnerability can be executed ...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2023-42363",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2023-42363",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "5.5",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "A use-after-free vulnerability was discovered in xasprintf function in xfuncs_printf.c:344 in BusyBox v.1.36.1.",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H"
|
||||
}
|
||||
],
|
||||
"layer": "meta",
|
||||
"name": "busybox",
|
||||
"products": [
|
||||
{
|
||||
"cvesInRecord": "Yes",
|
||||
"product": "busybox"
|
||||
}
|
||||
],
|
||||
"version": "1.36.1"
|
||||
},
|
||||
{
|
||||
"issue": [
|
||||
{
|
||||
"id": "CVE-2002-0059",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2002-0059",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The decompression algorithm in zlib 1.1.3 and earlier, as used in many different utilities and packages, causes inflateEnd to release certain memory more tha...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2003-0107",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2003-0107",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "Buffer overflow in the gzprintf function in zlib 1.1.4, when zlib is compiled without vsnprintf or when long inputs are truncated using vsnprintf, allows att...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2004-0797",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2004-0797",
|
||||
"scorev2": "2.1",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The error handling in the (1) inflate and (2) inflateBack functions in ZLib compression library 1.2.x allows local users to cause a denial of service (applic...",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "AV:L/AC:L/Au:N/C:N/I:N/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2005-1849",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2005-1849",
|
||||
"scorev2": "5.0",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "inftrees.h in zlib 1.2.2 allows remote attackers to cause a denial of service (application crash) via an invalid file that causes a large dynamic tree to be ...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:N/I:N/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2005-2096",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2005-2096",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "0.0",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "zlib 1.2 and later versions allows remote attackers to cause a denial of service (crash) via a crafted compressed stream with an incomplete code description ...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2016-9840",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2016-9840",
|
||||
"scorev2": "6.8",
|
||||
"scorev3": "8.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "inftrees.c in zlib 1.2.8 might allow context-dependent attackers to have unspecified impact by leveraging improper pointer arithmetic.",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:M/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2016-9841",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2016-9841",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "inffast.c in zlib 1.2.8 might allow context-dependent attackers to have unspecified impact by leveraging improper pointer arithmetic.",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2016-9842",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2016-9842",
|
||||
"scorev2": "6.8",
|
||||
"scorev3": "8.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The inflateMark function in inflate.c in zlib 1.2.8 might allow context-dependent attackers to have unspecified impact via vectors involving left shifts of n...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:M/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2016-9843",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2016-9843",
|
||||
"scorev2": "7.5",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "The crc32_big function in crc32.c in zlib 1.2.8 might allow context-dependent attackers to have unspecified impact via vectors involving big-endian CRC calcu...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2018-25032",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2018-25032",
|
||||
"scorev2": "5.0",
|
||||
"scorev3": "7.5",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "zlib before 1.2.12 allows memory corruption when deflating (i.e., when compressing) if the input has many distant matches.",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "AV:N/AC:L/Au:N/C:N/I:N/A:P"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2022-37434",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2022-37434",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "zlib through 1.2.12 has a heap-based buffer over-read or buffer overflow in inflate in inflate.c via a large gzip header extra field. NOTE: only applications...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2023-45853",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2023-45853",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "9.8",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "MiniZip in zlib through 1.3 has an integer overflow and resultant heap-based buffer overflow in zipOpenNewFileInZip4_64 via a long filename, comment, or extr...",
|
||||
"vector": "NETWORK",
|
||||
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"description": "vulnerable file is not compiled",
|
||||
"detail": "not-applicable-config",
|
||||
"id": "CVE-2026-22184",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2026-22184",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "7.8",
|
||||
"scorev4": "4.6",
|
||||
"status": "Ignored",
|
||||
"summary": "zlib versions up to and including 1.3.1.2 include a global buffer overflow in the untgz utility located under contrib/untgz. The vulnerability is limited to ...",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-27171",
|
||||
"link": "https://nvd.nist.gov/vuln/detail/CVE-2026-27171",
|
||||
"scorev2": "0.0",
|
||||
"scorev3": "2.9",
|
||||
"scorev4": "0.0",
|
||||
"status": "Patched",
|
||||
"summary": "zlib before 1.3.2 allows CPU consumption via crc32_combine64 and crc32_combine_gen64 because x2nmodp can do right shifts within a loop that has no terminatio...",
|
||||
"vector": "LOCAL",
|
||||
"vectorString": "CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L"
|
||||
}
|
||||
],
|
||||
"layer": "meta",
|
||||
"name": "zlib",
|
||||
"products": [
|
||||
{
|
||||
"cvesInRecord": "Yes",
|
||||
"product": "zlib"
|
||||
},
|
||||
{
|
||||
"cvesInRecord": "No",
|
||||
"product": "zlib"
|
||||
}
|
||||
],
|
||||
"version": "1.3.1"
|
||||
}
|
||||
],
|
||||
"version": "1"
|
||||
}
|
||||
Reference in new issue
Block a user