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): M7.1 - a key every crash in the library would share is not a key

CarterPerez-dev2752f5ccb839
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs
index 0dde2f99..194041a2 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs
@@ -99,12 +99,13 @@ impl SanitizerReport {
} else {
significant
};
- if frames.is_empty() {
+ let top: Vec<&str> = frames.into_iter().take(STACK_HASH_FRAMES).collect();
+ if top.is_empty() || top.iter().all(|frame| is_unsymbolized_frame(frame)) {
return None;
}
let mut hasher = Sha256::new();
hasher.update(self.kind.as_bytes());
- for frame in frames.iter().take(STACK_HASH_FRAMES) {
+ for frame in &top {
hasher.update(b"\n");
hasher.update(frame.as_bytes());
}
@@ -117,6 +118,10 @@ impl SanitizerReport {
}
}
+fn is_unsymbolized_frame(frame: &str) -> bool {
+ frame.starts_with(UNSYMBOLIZED_SYMBOL)
+}
+
fn is_noise_frame(frame: &str) -> bool {
NOISE_FRAME_EXACT.contains(&frame)
|| NOISE_FRAME_PREFIXES
@@ -364,6 +369,16 @@ SUMMARY: AddressSanitizer: stack-buffer-overflow (/t/harness+0x10e881) in __asan
#0 0x7f0c8a2 (/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
#1 0x7f0c8b3 (/out/libpng.so+0x1234) (BuildId: aabb)
";
+ const SAME_MODULE_UNSYMBOLIZED_A: &str = "\
+==12==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x4a1
+ #0 0x55a5aee0a111 (/out/target+0x1111) (BuildId: aabb)
+ #1 0x55a5aee0a222 (/out/target+0x2222) (BuildId: aabb)
+";
+ const SAME_MODULE_UNSYMBOLIZED_B: &str = "\
+==12==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x4a1
+ #0 0x55a5aee0a333 (/out/target+0x3333) (BuildId: aabb)
+ #1 0x55a5aee0a444 (/out/target+0x4444) (BuildId: aabb)
+";
const FUNCTION_OFFSET: &str = "\
==13==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000018 at pc 0x4a1
@@ -410,7 +425,35 @@ pngrutil.c:1204:7: runtime error: left shift of negative value -1
2,
"unsymbolized frames must not be silently dropped"
);
- assert!(report.stack_hash().is_some());
+ assert!(
+ report.frames().iter().all(|frame| frame.contains('@')),
+ "a kept unsymbolized frame must still name its module: {:?}",
+ report.frames()
+ );
+ }
+
+ #[test]
+ fn a_stack_with_no_symbols_at_all_refuses_a_dedup_key() {
+ let report = SanitizerReport::parse(UNSYMBOLIZED).unwrap();
+ assert!(
+ report.stack_hash().is_none(),
+ "every frame is <unknown>@module, so the hash carries only (kind, module set) and cannot identify a bug"
+ );
+ }
+
+ #[test]
+ fn two_bugs_in_one_module_do_not_share_a_key_when_unsymbolized() {
+ let first = SanitizerReport::parse(SAME_MODULE_UNSYMBOLIZED_A).unwrap();
+ let second = SanitizerReport::parse(SAME_MODULE_UNSYMBOLIZED_B).unwrap();
+ assert_eq!(
+ first.frames(),
+ second.frames(),
+ "the fixture must reproduce the collision: identical frame identities from different addresses"
+ );
+ assert!(
+ first.stack_hash().is_none() && second.stack_hash().is_none(),
+ "an all-unsymbolized stack degenerates to a constant per (kind, module); on real libwebp-style output this merged a use-after-free WRITE with a use-after-free READ, so the key must be refused rather than shared"
+ );
}
#[test]
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
index 8131a4e8..d1789935 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
@@ -21,6 +21,9 @@ const REPRODUCE_POLL_MS: u64 = 25;
const ENV_ASAN_OPTIONS: &str = "ASAN_OPTIONS";
const ENV_UBSAN_OPTIONS: &str = "UBSAN_OPTIONS";
const SANITIZER_OPTIONS: &str = "symbolize=0:detect_leaks=0:handle_segv=1";
+const UNPARSEABLE_REASON: &str = "no parseable sanitizer report";
+const UNSYMBOLIZED_REASON: &str =
+ "no symbolized frames, so any key would be shared by every crash of this kind in this module";
const CRASHES_DIR: &str = "crashes";
const CRASH_PREFIX: &str = "id:";
const MEM_LIMIT_UNLIMITED: &str = "none";
@@ -268,10 +271,16 @@ pub fn harvest(
if reproduction.truncated {
problems.push(format!("{}: report truncated", input_path.display()));
}
- let stack_hash = SanitizerReport::parse(&reproduction.output).and_then(|r| r.stack_hash());
+ let report = SanitizerReport::parse(&reproduction.output);
+ let stack_hash = report.as_ref().and_then(SanitizerReport::stack_hash);
if stack_hash.is_none() {
+ let reason = if report.is_some() {
+ UNSYMBOLIZED_REASON
+ } else {
+ UNPARSEABLE_REASON
+ };
problems.push(format!(
- "{}: no parseable sanitizer report, stored without a dedup key",
+ "{}: {reason}, stored without a dedup key",
input_path.display()
));
}