feat(sbom): FreeRTOS+TCP and FatFs in firmware trees, matched in NVD (#375) (#393)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Canceled after 0s

This commit was merged in pull request #393.
This commit is contained in:
sharang committed 2026-09-25 11:07:07 +00:00
1 parent 9a0d690036
commit 827b7196b5
5 files changed
+139 -9

No files matched your search

@@ -3,7 +3,8 @@
//! Microcontroller projects vendor their RTOS, TCP/IP stack and TLS library as
//! source: no manifest names them, so no package SBOM sees them, yet they are
//! where the published CVEs are. Each one states its version in a header, and
//! that is where it is read from. The entries are matched against NVD by CPE
//! that is where it is read from: FreeRTOS and its TCP/IP stack, lwIP, Mbed
//! TLS, wolfSSL and FatFs. The entries are matched against NVD by CPE
//! (see [`crate::pipeline::nvd_cpe`]).
use std::path::Path;
@@ -31,7 +32,7 @@ struct Library {
product: NvdProduct,
}
const LIBRARIES: [Library; 5] = [
const LIBRARIES: [Library; 7] = [
Library {
name: "FreeRTOS",
header: "task.h",
@@ -54,6 +55,30 @@ const LIBRARIES: [Library; 5] = [
marker: ":lwip_project:lwip:",
},
},
// NVD files the TCP/IP stack's own CVEs (4.x) under this product; those
// of the 2018 AMNESIA-era releases are under the kernel's.
Library {
name: "FreeRTOS+TCP",
header: "FreeRTOS_IP.h",
parent: None,
read: freertos_tcp_version,
license: "MIT",
product: NvdProduct {
match_string: "cpe:2.3:*:amazon:freertos-plus-tcp",
marker: ":amazon:freertos-plus-tcp:",
},
},
Library {
name: "FatFs",
header: "ff.h",
parent: None,
read: fatfs_version,
license: "BSD-1-Clause",
product: NvdProduct {
match_string: "cpe:2.3:*:elm-chan:fatfs",
marker: ":elm-chan:fatfs:",
},
},
// Mbed TLS 3.x states it in build_info.h, 2.x in version.h.
Library {
name: "Mbed TLS",
@@ -194,6 +219,29 @@ fn lwip_version(text: &str) -> Option<String> {
))
}
/// `#define ipFR_TCP_VERSION_NUMBER "V4.1.0"`.
fn freertos_tcp_version(text: &str) -> Option<String> {
let raw = define(text, "ipFR_TCP_VERSION_NUMBER")?;
dotted(raw.trim_start_matches(['V', 'v']))
}
/// The revision in ff.h's banner (`FatFs - Generic FAT Filesystem module
/// R0.14b`), as NVD writes it: `r0.14b`. The header has no version macro
/// (`FF_DEFINED` is a revision id).
fn fatfs_version(text: &str) -> Option<String> {
let banner = text.lines().take(10).find(|l| l.contains("FatFs"))?;
banner.split_whitespace().find_map(|word| {
let rest = word.strip_prefix(['R', 'r'])?;
let (major, minor) = rest.split_once('.')?;
let digits = minor.trim_end_matches(|c: char| c.is_ascii_lowercase());
let ok = !major.is_empty()
&& major.chars().all(|c| c.is_ascii_digit())
&& !digits.is_empty()
&& digits.chars().all(|c| c.is_ascii_digit());
ok.then(|| format!("r{}", rest.to_ascii_lowercase()))
})
}
/// `#define MBEDTLS_VERSION_STRING "3.4.0"`.
fn mbedtls_version(text: &str) -> Option<String> {
dotted(&define(text, "MBEDTLS_VERSION_STRING")?)
@@ -226,6 +274,15 @@ mod tests {
wolfssl_version("#define LIBWOLFSSL_VERSION_STRING \"5.6.3\"").as_deref(),
Some("5.6.3")
);
assert_eq!(
freertos_tcp_version("#define ipFR_TCP_VERSION_NUMBER \"V4.1.0\"").as_deref(),
Some("4.1.0")
);
let fatfs = "/*----------------------------------------------------------------------------/\n\
/ FatFs - Generic FAT Filesystem module R0.14b /\n";
assert_eq!(fatfs_version(fatfs).as_deref(), Some("r0.14b"));
// Another ff.h: no FatFs banner, no version.
assert_eq!(fatfs_version("/* ffmpeg helpers R1.2 */"), None);
}
#[test]
@@ -262,6 +319,14 @@ mod tests {
"lib/mbedtls/include/mbedtls/build_info.h",
"#define MBEDTLS_VERSION_STRING \"3.4.0\"\n",
);
write(
"Middlewares/Third_Party/FreeRTOS-Plus-TCP/source/include/FreeRTOS_IP.h",
"#define ipFR_TCP_VERSION_NUMBER \"V4.1.0\"\n",
);
write(
"Middlewares/Third_Party/FatFs/src/ff.h",
"/ FatFs - Generic FAT Filesystem module R0.14b /\n",
);
// An unrelated `init.h` and a second copy of the same FreeRTOS.
write("Core/Inc/init.h", "#define LWIP_VERSION_MAJOR 9\n");
write(
@@ -277,7 +342,9 @@ mod tests {
assert_eq!(
found,
[
("FatFs".to_string(), "r0.14b".to_string()),
("FreeRTOS".to_string(), "10.3.1".to_string()),
("FreeRTOS+TCP".to_string(), "4.1.0".to_string()),
("Mbed TLS".to_string(), "3.4.0".to_string()),
("lwIP".to_string(), "2.1.2".to_string()),
]
+41 -7
View File
@@ -235,15 +235,29 @@ fn version_matches(v: &str, r: &CpeRange) -> bool {
ok
}
/// Compare two dotted numeric versions (`4.17.0.0` vs `4.9.0.0`); missing
/// components count as 0, non-numeric components as 0.
/// Compare two dotted versions (`4.17.0.0` vs `4.9.0.0`); a missing
/// component counts as 0.
///
/// A leading `r`/`v` is ignored (FatFs `r0.14b`, `V10.4.6`), and a component
/// is its number then any letter suffix, so `14` < `14b` < `15`.
fn cmp_dotted(a: &str, b: &str) -> std::cmp::Ordering {
let pa: Vec<u64> = a.split('.').map(|x| x.parse().unwrap_or(0)).collect();
let pb: Vec<u64> = b.split('.').map(|x| x.parse().unwrap_or(0)).collect();
let parts = |v: &str| -> Vec<(u64, String)> {
v.trim_start_matches(['r', 'R', 'v', 'V'])
.split('.')
.map(|part| {
let digits =
part.len() - part.trim_start_matches(|c: char| c.is_ascii_digit()).len();
(
part[..digits].parse().unwrap_or(0),
part[digits..].to_ascii_lowercase(),
)
})
.collect()
};
let (pa, pb) = (parts(a), parts(b));
let zero = (0, String::new());
for i in 0..pa.len().max(pb.len()) {
let x = pa.get(i).copied().unwrap_or(0);
let y = pb.get(i).copied().unwrap_or(0);
match x.cmp(&y) {
match pa.get(i).unwrap_or(&zero).cmp(pb.get(i).unwrap_or(&zero)) {
std::cmp::Ordering::Equal => continue,
other => return other,
}
@@ -345,12 +359,32 @@ mod tests {
assert_eq!(hits.load(Ordering::SeqCst), 1);
}
#[test]
fn fatfs_revisions_match_nvds_ranges() {
// The shape of CVE-2026-6682: FatFs R0.16 and earlier.
let body = serde_json::json!({ "vulnerabilities": [{ "cve": {
"id": "CVE-2026-6682",
"configurations": [{ "nodes": [{ "cpeMatch": [{
"vulnerable": true,
"criteria": "cpe:2.3:a:elm-chan:fatfs:*:*:*:*:*:*:*:*",
"versionEndIncluding": "r0.16"
}]}]}]
}}]});
assert_eq!(parse(&body, ":elm-chan:fatfs:", "r0.14b").len(), 1);
assert!(parse(&body, ":elm-chan:fatfs:", "r0.16a").is_empty());
}
#[test]
fn dotted_version_comparison() {
assert_eq!(cmp_dotted("4.17.0.0", "4.9.0.0"), Greater);
assert_eq!(cmp_dotted("4.9.0.0", "4.17.0.0"), Less);
assert_eq!(cmp_dotted("3.5.18.0", "3.5.18.0"), Equal);
assert_eq!(cmp_dotted("4.2", "4.2.0.0"), Equal); // missing components = 0
// FatFs revisions, as NVD writes them.
assert_eq!(cmp_dotted("r0.14b", "r0.16"), Less);
assert_eq!(cmp_dotted("r0.14b", "r0.14"), Greater);
assert_eq!(cmp_dotted("R0.14B", "r0.14b"), Equal);
assert_eq!(cmp_dotted("V4.1.0", "4.1.1"), Less);
}
#[test]
@@ -4,6 +4,8 @@
"sast_vendor_code"
],
"sbom": [
"embedded:FatFs@r0.14b",
"embedded:FreeRTOS+TCP@4.0.0",
"embedded:FreeRTOS@10.3.1",
"embedded:Mbed TLS@2.16.2",
"embedded:lwIP@2.1.2",
@@ -46,6 +48,10 @@
"CVE-2024-23775",
"CVE-2024-28115",
"CVE-2024-28960",
"CVE-2024-38373",
"CVE-2025-11616",
"CVE-2025-11617",
"CVE-2025-11618",
"CVE-2025-27809",
"CVE-2025-27810",
"CVE-2025-47917",
@@ -57,6 +63,17 @@
"CVE-2025-66442",
"CVE-2026-34871",
"CVE-2026-34872",
"CVE-2026-6682",
"CVE-2026-6683",
"CVE-2026-6684",
"CVE-2026-6686",
"CVE-2026-6687",
"CVE-2026-6688",
"CVE-2026-7422",
"CVE-2026-7423",
"CVE-2026-7424",
"CVE-2026-7425",
"CVE-2026-7426",
"CVE-2026-77234",
"CVE-2026-77235",
"CVE-2026-77236",
@@ -0,0 +1,8 @@
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem module R0.14b /
/-----------------------------------------------------------------------------/
/ (planted for the nightly: FatFs CVEs up to R0.16)
/----------------------------------------------------------------------------*/
#ifndef FF_DEFINED
#define FF_DEFINED 86631 /* Revision ID */
#endif
@@ -0,0 +1,4 @@
/* FreeRTOS+TCP V4.0.0 (planted for the nightly: its own CVEs). */
#define ipFR_TCP_VERSION_NUMBER "V4.0.0"
#define ipFR_TCP_VERSION_MAJOR 4
#define ipFR_TCP_VERSION_MINOR 0