Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

fix(lisdex): B23 - a truncated symbol listing was counted as if it were complete

CarterPerez-dev49fca15ce23f
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
index 48daae30..b8d69ae2 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
@@ -296,6 +296,10 @@ fn inspect_artifacts(
let measured_counts = match verify::inspect(&item.path) {
Ok(measured_counts) => measured_counts,
Err(verify::VerifyError::Unreadable { .. }) => continue,
+ Err(source @ verify::VerifyError::Truncated { .. }) => {
+ shortfalls.push(format!("{}: {source}", item.path.display()));
+ continue;
+ }
Err(verify::VerifyError::Process(source)) => {
return Err(BuildError::Process(source));
}
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/verify.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/verify.rs
index 24ea3e66..f4a2a7c7 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/verify.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/verify.rs
@@ -31,6 +31,14 @@ pub enum VerifyError {
path: PathBuf,
output: String,
},
+ #[error(
+ "{nm} output for {path} exceeded the {captured}-byte capture limit, so an unknown number of symbols were never read; a count taken from a partial listing can report an instrumented build as bare, or a benchmark build as field"
+ )]
+ Truncated {
+ nm: String,
+ path: PathBuf,
+ captured: usize,
+ },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@@ -189,16 +197,39 @@ pub fn nm_spec(path: &Path) -> CommandSpec {
CommandSpec::new(LLVM_NM).arg(ARG_NO_SORT).path_arg(path)
}
-pub fn inspect(path: &Path) -> Result<SymbolCounts, VerifyError> {
- let execution = process::run(&nm_spec(path), Duration::from_secs(NM_TIMEOUT_SECS))?;
- if !execution.success {
+pub fn scan_listing(
+ path: &Path,
+ succeeded: bool,
+ truncated: bool,
+ output: &str,
+ tail: &str,
+) -> Result<SymbolCounts, VerifyError> {
+ if !succeeded {
return Err(VerifyError::Unreadable {
nm: LLVM_NM.to_owned(),
path: path.to_path_buf(),
- output: execution.tail(10),
+ output: tail.to_owned(),
+ });
+ }
+ if truncated {
+ return Err(VerifyError::Truncated {
+ nm: LLVM_NM.to_owned(),
+ path: path.to_path_buf(),
+ captured: process::MAX_CAPTURED_BYTES,
});
}
- Ok(scan_symbols(&execution.output))
+ Ok(scan_symbols(output))
+}
+
+pub fn inspect(path: &Path) -> Result<SymbolCounts, VerifyError> {
+ let execution = process::run(&nm_spec(path), Duration::from_secs(NM_TIMEOUT_SECS))?;
+ scan_listing(
+ path,
+ execution.success,
+ execution.truncated,
+ &execution.output,
+ &execution.tail(10),
+ )
}
#[cfg(test)]
@@ -369,6 +400,39 @@ asan_shim.o:
assert!(shortfalls[0].contains("cmplog"));
}
+ #[test]
+ fn a_truncated_listing_is_refused_rather_than_counted() {
+ let magma_listing = " U magma_log\n";
+ let path = Path::new("/out/harness");
+
+ assert_eq!(
+ scan_listing(path, true, false, magma_listing, "")
+ .unwrap()
+ .magma,
+ 1,
+ "the fixture must isolate the signal: a complete listing of these bytes DOES count a canary"
+ );
+
+ assert!(
+ matches!(
+ scan_listing(path, true, true, magma_listing, ""),
+ Err(VerifyError::Truncated { .. })
+ ),
+ "the same bytes cut short must refuse instead. B94's benchmark-tree detection is `counts.magma > 0` over this listing, so a partial read that happens to miss the canary silently marks a benchmark tree as field and makes its findings disclosable. Measured headroom on the real magma target is 355,611 of 524,288 bytes - it fits today, and a bigger target does not."
+ );
+ }
+
+ #[test]
+ fn a_failed_listing_is_refused_before_truncation_is_considered() {
+ assert!(
+ matches!(
+ scan_listing(Path::new("/out/x"), false, true, "", "no such file"),
+ Err(VerifyError::Unreadable { .. })
+ ),
+ "a command that failed outright is unreadable, not truncated, and the message has to name the real cause"
+ );
+ }
+
#[test]
fn a_memory_sanitizer_build_does_not_demand_address_symbols() {
let requirements = Requirements::for_sanitizers(SanitizerSet::Memory);
@@ -442,6 +506,9 @@ asan_shim.o:
match inspect(&path) {
Ok(counts) => panic!("a text file reported symbols: {counts:?}"),
Err(VerifyError::Unreadable { .. }) => {}
+ Err(VerifyError::Truncated { .. }) => {
+ panic!("18 bytes cannot exceed the capture limit")
+ }
Err(VerifyError::Process(_)) => {
assert!(
process::run(