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 đŸ‘‡
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
fix(lisdex): B94 - provenance moves to the tree, and the hazard it named does not reproduce
CarterPerez-deva7158980ac71
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/campaign.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/campaign.rsindex b7e04142..73f51af9 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/campaign.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/campaign.rs@@ -4,6 +4,39 @@#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub struct CampaignId(pub i64);+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum TreeProvenance {+ Field,+ Benchmark,+ Unknown,+}++impl TreeProvenance {+ #[must_use]+ pub fn is_benchmark(self) -> bool {+ self == TreeProvenance::Benchmark+ }++ #[must_use]+ pub fn as_str(self) -> &'static str {+ match self {+ TreeProvenance::Field => "field",+ TreeProvenance::Benchmark => "benchmark",+ TreeProvenance::Unknown => "unknown",+ }+ }++ #[must_use]+ pub fn from_db_str(value: &str) -> Option<TreeProvenance> {+ match value {+ "field" => Some(TreeProvenance::Field),+ "benchmark" => Some(TreeProvenance::Benchmark),+ "unknown" => Some(TreeProvenance::Unknown),+ _ => None,+ }+ }+}+#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum CampaignStatus {Pending,@@ -60,22 +93,29 @@ pub struct TransitionError {pub struct Campaign {target: String,status: CampaignStatus,+ tree: TreeProvenance,}impl Campaign {#[must_use]- pub fn new(target: impl Into<String>) -> Self {+ pub fn new(target: impl Into<String>, tree: TreeProvenance) -> Self {Self {target: target.into(),status: CampaignStatus::Pending,+ tree,}}#[must_use]- pub(crate) fn from_stored(target: impl Into<String>, status: CampaignStatus) -> Self {+ pub(crate) fn from_stored(+ target: impl Into<String>,+ status: CampaignStatus,+ tree: TreeProvenance,+ ) -> Self {Self {target: target.into(),status,+ tree,}}@@ -89,6 +129,11 @@ impl Campaign {&self.target}+ #[must_use]+ pub fn tree(&self) -> TreeProvenance {+ self.tree+ }+pub fn advance(&mut self, next: CampaignStatus) -> Result<(), TransitionError> {if self.status.can_transition_to(next) {self.status = next;@@ -108,21 +153,21 @@ mod tests {#[test]fn new_campaign_starts_pending() {- let campaign = Campaign::new("libpng");+ let campaign = Campaign::new("libpng", TreeProvenance::Field);assert_eq!(campaign.status(), CampaignStatus::Pending);assert_eq!(campaign.target(), "libpng");}#[test]fn advance_follows_legal_transition() {- let mut campaign = Campaign::new("libpng");+ let mut campaign = Campaign::new("libpng", TreeProvenance::Field);assert!(campaign.advance(CampaignStatus::Building).is_ok());assert_eq!(campaign.status(), CampaignStatus::Building);}#[test]fn advance_rejects_illegal_transition() {- let mut campaign = Campaign::new("libpng");+ let mut campaign = Campaign::new("libpng", TreeProvenance::Field);let err = campaign.advance(CampaignStatus::Fuzzing).unwrap_err();assert_eq!(err.from, CampaignStatus::Pending);assert_eq!(err.to, CampaignStatus::Fuzzing);@@ -172,10 +217,38 @@ mod tests {assert_eq!(CampaignStatus::from_db_str("bogus"), None);}+ #[test]+ fn tree_provenance_round_trips_through_db_string() {+ for tree in [+ TreeProvenance::Field,+ TreeProvenance::Benchmark,+ TreeProvenance::Unknown,+ ] {+ assert_eq!(TreeProvenance::from_db_str(tree.as_str()), Some(tree));+ }+ }++ #[test]+ fn tree_provenance_from_db_str_rejects_unknown_value() {+ assert_eq!(TreeProvenance::from_db_str("bogus"), None);+ }++ #[test]+ fn only_a_benchmark_tree_is_a_benchmark() {+ assert!(TreeProvenance::Benchmark.is_benchmark());+ assert!(+ !TreeProvenance::Unknown.is_benchmark(),+ "an unmeasured tree must not be treated as a benchmark, or every legacy campaign silently loses its findings"+ );+ assert!(!TreeProvenance::Field.is_benchmark());+ }+#[test]fn from_stored_preserves_target_and_status() {- let campaign = Campaign::from_stored("libpng", CampaignStatus::Fuzzing);+ let campaign =+ Campaign::from_stored("libpng", CampaignStatus::Fuzzing, TreeProvenance::Benchmark);assert_eq!(campaign.target(), "libpng");assert_eq!(campaign.status(), CampaignStatus::Fuzzing);+ assert_eq!(campaign.tree(), TreeProvenance::Benchmark);}}diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rsindex eb31c2cf..f703cb01 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs@@ -5,7 +5,7 @@ use std::path::Path;use rusqlite::{Connection, params};-use crate::campaign::{Campaign, CampaignId, CampaignStatus};+use crate::campaign::{Campaign, CampaignId, CampaignStatus, TreeProvenance};use crate::crash::{Crash, CrashId};const BUSY_TIMEOUT_MS: u64 = 5000;@@ -16,7 +16,8 @@ PRAGMA journal_mode = WAL;CREATE TABLE IF NOT EXISTS campaigns (id INTEGER PRIMARY KEY,target TEXT NOT NULL,- status TEXT NOT NULL+ status TEXT NOT NULL,+ tree_provenance TEXT);CREATE TABLE IF NOT EXISTS crashes (id INTEGER PRIMARY KEY,@@ -27,13 +28,20 @@ CREATE TABLE IF NOT EXISTS crashes ();CREATE INDEX IF NOT EXISTS idx_crashes_campaign ON crashes(campaign_id);";-const INSERT_CAMPAIGN_SQL: &str = "INSERT INTO campaigns (target, status) VALUES (?1, ?2)";-const SELECT_CAMPAIGN_SQL: &str = "SELECT target, status FROM campaigns WHERE id = ?1";+const INSERT_CAMPAIGN_SQL: &str =+ "INSERT INTO campaigns (target, status, tree_provenance) VALUES (?1, ?2, ?3)";+const SELECT_CAMPAIGN_SQL: &str =+ "SELECT target, status, tree_provenance FROM campaigns WHERE id = ?1";const UPDATE_CAMPAIGN_STATUS_SQL: &str = "UPDATE campaigns SET status = ?1 WHERE id = ?2";const INSERT_CRASH_SQL: &str = "INSERT INTO crashes (campaign_id, input, sanitizer_report, stack_hash) VALUES (?1, ?2, ?3, ?4)";const SELECT_CRASHES_SQL: &str ="SELECT campaign_id, input, sanitizer_report FROM crashes WHERE campaign_id = ?1 ORDER BY id";-const SELECT_ALL_CAMPAIGNS_SQL: &str = "SELECT id, target, status FROM campaigns ORDER BY id";+const SELECT_ALL_CAMPAIGNS_SQL: &str =+ "SELECT id, target, status, tree_provenance FROM campaigns ORDER BY id";++const CAMPAIGN_TREE_COLUMN: &str = "tree_provenance";+const CAMPAIGN_COLUMNS_SQL: &str = "SELECT name FROM pragma_table_info('campaigns')";+const ADD_TREE_COLUMN_SQL: &str = "ALTER TABLE campaigns ADD COLUMN tree_provenance TEXT";#[derive(Debug, thiserror::Error)]pub enum StoreError {@@ -41,6 +49,8 @@ pub enum StoreError {Sqlite(#[from] rusqlite::Error),#[error("unknown campaign status in database: {0}")]UnknownStatus(String),+ #[error("unknown campaign tree provenance in database: {0}")]+ UnknownTreeProvenance(String),#[error("no campaign with id {0} in the store")]CampaignNotFound(i64),}@@ -70,13 +80,38 @@ impl Store {self.conn.busy_timeout(std::time::Duration::from_millis(BUSY_TIMEOUT_MS))?;self.conn.execute_batch(MIGRATE_SQL)?;+ self.backfill_campaign_columns()?;Ok(())}+ fn backfill_campaign_columns(&self) -> Result<(), StoreError> {+ let mut stmt = self.conn.prepare(CAMPAIGN_COLUMNS_SQL)?;+ let present = stmt+ .query_map([], |row| row.get::<_, String>(0))?+ .collect::<Result<Vec<_>, _>>()?;+ if !present.iter().any(|name| name == CAMPAIGN_TREE_COLUMN) {+ self.conn.execute(ADD_TREE_COLUMN_SQL, [])?;+ }+ Ok(())+ }++ fn tree_from_stored(value: Option<String>) -> Result<TreeProvenance, StoreError> {+ match value {+ None => Ok(TreeProvenance::Unknown),+ Some(text) => {+ TreeProvenance::from_db_str(&text).ok_or(StoreError::UnknownTreeProvenance(text))+ }+ }+ }+pub fn insert_campaign(&self, campaign: &Campaign) -> Result<CampaignId, StoreError> {self.conn.execute(INSERT_CAMPAIGN_SQL,- params![campaign.target(), campaign.status().as_str()],+ params![+ campaign.target(),+ campaign.status().as_str(),+ campaign.tree().as_str()+ ],)?;Ok(CampaignId(self.conn.last_insert_rowid()))}@@ -85,13 +120,18 @@ impl Store {let row = self.conn.query_row(SELECT_CAMPAIGN_SQL, params![id.0], |row| {- Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?))+ Ok((+ row.get::<_, String>(0)?,+ row.get::<_, String>(1)?,+ row.get::<_, Option<String>>(2)?,+ ))});match row {- Ok((target, status_str)) => {+ Ok((target, status_str, tree_str)) => {let status = CampaignStatus::from_db_str(&status_str).ok_or(StoreError::UnknownStatus(status_str))?;- Ok(Some(Campaign::from_stored(target, status)))+ let tree = Self::tree_from_stored(tree_str)?;+ Ok(Some(Campaign::from_stored(target, status, tree)))}Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None),Err(err) => Err(err.into()),@@ -120,14 +160,16 @@ impl Store {row.get::<_, i64>(0)?,row.get::<_, String>(1)?,row.get::<_, String>(2)?,+ row.get::<_, Option<String>>(3)?,))})?.collect::<Result<Vec<_>, _>>()?;let mut campaigns = Vec::with_capacity(rows.len());- for (id, target, status_str) in rows {+ for (id, target, status_str, tree_str) in rows {let status = CampaignStatus::from_db_str(&status_str).ok_or(StoreError::UnknownStatus(status_str))?;- campaigns.push((CampaignId(id), Campaign::from_stored(target, status)));+ let tree = Self::tree_from_stored(tree_str)?;+ campaigns.push((CampaignId(id), Campaign::from_stored(target, status, tree)));}Ok(campaigns)}@@ -183,7 +225,7 @@ mod tests {#[test]fn campaign_round_trips_through_store() {let store = Store::open_in_memory().unwrap();- let mut campaign = Campaign::new("libpng");+ let mut campaign = Campaign::new("libpng", TreeProvenance::Field);campaign.advance(CampaignStatus::Building).unwrap();let id = store.insert_campaign(&campaign).unwrap();let loaded = store.get_campaign(id).unwrap().unwrap();@@ -199,7 +241,9 @@ mod tests {#[test]fn update_campaign_status_persists() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();store.update_campaign_status(id, CampaignStatus::Building).unwrap();@@ -210,7 +254,9 @@ mod tests {#[test]fn crashes_round_trip_and_link_to_campaign() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();let crash = Crash::from_report(id, b"\x89PNG\r\n\x1a\n".to_vec(), KEYED_REPORT);store.insert_crash(&crash).unwrap();let crashes = store.crashes_for_campaign(id).unwrap();@@ -220,7 +266,9 @@ mod tests {#[test]fn a_stored_key_is_a_cache_and_the_report_is_the_truth() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();store.insert_crash(&Crash::new(id,@@ -246,7 +294,9 @@ mod tests {#[test]fn a_stored_key_the_current_algorithm_would_refuse_loads_as_none() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();store.insert_crash(&Crash::new(id,@@ -266,7 +316,9 @@ mod tests {#[test]fn rows_written_either_side_of_a_filter_change_count_as_one_bug() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();for key in [OBSOLETE_KEY, SECOND_OBSOLETE_KEY] {store.insert_crash(&Crash::new(@@ -290,7 +342,9 @@ mod tests {#[test]fn crash_without_stack_hash_round_trips_as_null() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();let crash = Crash::new(id, b"unreproduced".to_vec(), "", None);store.insert_crash(&crash).unwrap();let loaded = store.crashes_for_campaign(id).unwrap();@@ -304,7 +358,9 @@ mod tests {#[test]fn binary_input_with_embedded_nuls_round_trips_exactly() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();let raw: Vec<u8> = vec![0x00, 0xff, 0x89, 0x00, 0x0a, 0xc3, 0x28];store.insert_crash(&Crash::new(id, raw.clone(), "report", None))@@ -326,7 +382,9 @@ mod tests {fn list_campaigns_returns_every_row_in_insertion_order() {let store = Store::open_in_memory().unwrap();for target in ["libpng", "libtiff", "openjpeg"] {- store.insert_campaign(&Campaign::new(target)).unwrap();+ store+ .insert_campaign(&Campaign::new(target, TreeProvenance::Field))+ .unwrap();}let listed = store.list_campaigns().unwrap();let targets: Vec<&str> = listed@@ -339,7 +397,9 @@ mod tests {#[test]fn list_campaigns_carries_the_id_a_caller_needs_to_fetch_crashes() {let store = Store::open_in_memory().unwrap();- let inserted = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let inserted = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();store.insert_crash(&Crash::from_report(inserted,@@ -355,7 +415,9 @@ mod tests {#[test]fn list_campaigns_preserves_status_rather_than_resetting_to_pending() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();store.update_campaign_status(id, CampaignStatus::Building).unwrap();@@ -372,7 +434,9 @@ mod tests {#[test]fn crashes_for_campaign_without_crashes_is_empty() {let store = Store::open_in_memory().unwrap();- let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();+ let id = store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();assert!(store.crashes_for_campaign(id).unwrap().is_empty());}@@ -383,11 +447,94 @@ mod tests {let _ = std::fs::remove_file(&path);let id = {let store = Store::open(&path).unwrap();- store.insert_campaign(&Campaign::new("libpng")).unwrap()+ store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap()};let store = Store::open(&path).unwrap();let loaded = store.get_campaign(id).unwrap().unwrap();assert_eq!(loaded.target(), "libpng");std::fs::remove_file(&path).unwrap();}++ fn scratch_db(name: &str) -> std::path::PathBuf {+ let path =+ std::env::temp_dir().join(format!("lisdex-store-{name}-{}.sqlite", std::process::id()));+ let _ = std::fs::remove_file(&path);+ path+ }++ #[test]+ fn a_benchmark_tree_round_trips_through_the_store() {+ let store = Store::open_in_memory().unwrap();+ let id = store+ .insert_campaign(&Campaign::new("magma-libpng", TreeProvenance::Benchmark))+ .unwrap();+ assert_eq!(+ store.get_campaign(id).unwrap().unwrap().tree(),+ TreeProvenance::Benchmark,+ "the tree a campaign ran against is what decides disclosability, so it has to survive the store"+ );+ }++ #[test]+ fn a_database_written_before_the_tree_column_existed_reads_as_unknown_not_field() {+ let path = scratch_db("legacy");+ let conn = Connection::open(&path).unwrap();+ conn.execute_batch(+ "CREATE TABLE campaigns (id INTEGER PRIMARY KEY, target TEXT NOT NULL, status TEXT NOT NULL);+ INSERT INTO campaigns (target, status) VALUES ('lisdex_libpng_read', 'completed');",+ )+ .unwrap();+ drop(conn);++ let store = Store::open(&path).unwrap();+ let loaded = store.get_campaign(CampaignId(1)).unwrap().unwrap();+ assert_eq!(+ loaded.tree(),+ TreeProvenance::Unknown,+ "a campaign recorded before lisdex measured trees was never measured; calling it Field would assert something no one checked"+ );+ assert_eq!(loaded.status(), CampaignStatus::Completed);+ std::fs::remove_file(&path).unwrap();+ }++ #[test]+ fn list_campaigns_carries_the_tree_each_one_ran_against() {+ let store = Store::open_in_memory().unwrap();+ for (target, tree) in [+ ("magma-libpng", TreeProvenance::Benchmark),+ ("libpng", TreeProvenance::Field),+ ] {+ store.insert_campaign(&Campaign::new(target, tree)).unwrap();+ }+ let listed = store.list_campaigns().unwrap();+ assert_eq!(listed[0].1.tree(), TreeProvenance::Benchmark);+ assert_eq!(listed[1].1.tree(), TreeProvenance::Field);+ }++ #[test]+ fn an_unreadable_tree_provenance_is_an_error_rather_than_a_silent_field() {+ let path = scratch_db("badtree");+ {+ let store = Store::open(&path).unwrap();+ store+ .insert_campaign(&Campaign::new("libpng", TreeProvenance::Field))+ .unwrap();+ }+ let conn = Connection::open(&path).unwrap();+ conn.execute("UPDATE campaigns SET tree_provenance = 'bogus'", [])+ .unwrap();+ drop(conn);++ let store = Store::open(&path).unwrap();+ assert!(+ matches!(+ store.get_campaign(CampaignId(1)),+ Err(StoreError::UnknownTreeProvenance(_))+ ),+ "an unrecognised value must refuse to load, because the safe-looking fallback is the one that publishes a benchmark bug"+ );+ std::fs::remove_file(&path).unwrap();+ }}diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-dashboard/tests/console.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-dashboard/tests/console.rsindex a314778d..017aa800 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-dashboard/tests/console.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-dashboard/tests/console.rs@@ -5,7 +5,7 @@ use std::io::{BufRead, BufReader, Read, Write};use std::net::{SocketAddr, TcpStream};use std::path::PathBuf;-use lisdex_core::campaign::{Campaign, CampaignStatus};+use lisdex_core::campaign::{Campaign, CampaignStatus, TreeProvenance};use lisdex_core::crash::Crash;use lisdex_core::store::Store;use lisdex_dashboard::{SNAPSHOT_ROUTE, loopback, router};@@ -69,7 +69,7 @@ impl Lab {std::fs::write(dir.join("plot_data"), REAL_PLOT).unwrap();let store = Store::open(root.join("lisdex.sqlite")).unwrap();- let mut campaign = Campaign::new("lisdex_libpng_read");+ let mut campaign = Campaign::new("lisdex_libpng_read", TreeProvenance::Field);let id = store.insert_campaign(&campaign).unwrap();campaign.advance(CampaignStatus::Building).unwrap();campaign.advance(CampaignStatus::Fuzzing).unwrap();diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-monitor/tests/real_campaign.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-monitor/tests/real_campaign.rsindex be86807f..fe82e93b 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-monitor/tests/real_campaign.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-monitor/tests/real_campaign.rs@@ -3,7 +3,7 @@use std::path::PathBuf;-use lisdex_core::campaign::{Campaign, CampaignStatus};+use lisdex_core::campaign::{Campaign, CampaignStatus, TreeProvenance};use lisdex_core::crash::Crash;use lisdex_core::store::Store;use lisdex_monitor::snapshot::{MonitorError, Notice, Severity, Snapshot, Source};@@ -117,7 +117,7 @@ impl Lab {fn campaign(&self, target: &str, reports: &[&str]) -> &Lab {let store = Store::open(self.db()).unwrap();- let mut campaign = Campaign::new(target);+ let mut campaign = Campaign::new(target, TreeProvenance::Field);let id = store.insert_campaign(&campaign).unwrap();campaign.advance(CampaignStatus::Building).unwrap();campaign.advance(CampaignStatus::Fuzzing).unwrap();@@ -354,7 +354,9 @@ fn with_no_campaign_named_the_most_recent_one_is_shown() {lab.instance("main", MAIN_STATS, Some(REAL_PLOT));let store = Store::open(lab.db()).unwrap();for target in ["libpng", "libtiff", "openjpeg"] {- store.insert_campaign(&Campaign::new(target)).unwrap();+ store+ .insert_campaign(&Campaign::new(target, TreeProvenance::Field))+ .unwrap();}drop(store);assert_eq!(lab.read().campaign().unwrap().target, "openjpeg");@@ -367,7 +369,9 @@ fn a_named_campaign_is_shown_instead_of_the_most_recent_one() {let store = Store::open(lab.db()).unwrap();let mut first = None;for target in ["libpng", "libtiff"] {- let id = store.insert_campaign(&Campaign::new(target)).unwrap();+ let id = store+ .insert_campaign(&Campaign::new(target, TreeProvenance::Field))+ .unwrap();first.get_or_insert(id);}drop(store);diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/advisory.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/advisory.rsindex 48573623..bf9a8804 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/advisory.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/advisory.rs@@ -1,6 +1,7 @@// ©AngelaMos | 2026// advisory.rs+use lisdex_core::campaign::TreeProvenance;use lisdex_core::crash::Crash;use lisdex_core::report::SanitizerReport;use lisdex_triage::classify::classify;@@ -75,12 +76,18 @@ pub struct Advisory {crash_count: usize,reproducer_bytes: usize,provenance: Provenance,+ tree: TreeProvenance,sanitizer_report: String,}impl Advisory {#[must_use]- pub fn draft(target: &str, representative: &Crash, crash_count: usize) -> Option<Advisory> {+ pub fn draft(+ target: &str,+ representative: &Crash,+ crash_count: usize,+ tree: TreeProvenance,+ ) -> Option<Advisory> {let text = representative.sanitizer_report();let parsed = SanitizerReport::parse(text)?;let classification = classify(text)?;@@ -96,7 +103,8 @@ impl Advisory {frames: parsed.frames().to_vec(),crash_count,reproducer_bytes: representative.input().len(),- provenance: provenance_of(&parsed),+ provenance: resolve_provenance(tree, &parsed),+ tree,sanitizer_report: text.to_owned(),})}@@ -156,6 +164,11 @@ impl Advisory {self.provenance}+ #[must_use]+ pub fn tree(&self) -> TreeProvenance {+ self.tree+ }+#[must_use]pub fn sanitizer_report(&self) -> &str {&self.sanitizer_report@@ -184,6 +197,14 @@ pub fn provenance_of(report: &SanitizerReport) -> Provenance {}}+#[must_use]+pub fn resolve_provenance(tree: TreeProvenance, report: &SanitizerReport) -> Provenance {+ if tree.is_benchmark() {+ return Provenance::SyntheticBenchmark;+ }+ provenance_of(report)+}+#[cfg(test)]mod tests {use lisdex_core::campaign::CampaignId;@@ -235,7 +256,8 @@ SUMMARY: AddressSanitizer: heap-buffer-overflow (/out/harness+0x4a1) in MAGMA_pn#[test]fn a_draft_carries_the_measured_facts_of_its_group() {- let advisory = Advisory::draft("libpng", &crash(REAL_HEAP_WRITE), 44).unwrap();+ let advisory =+ Advisory::draft("libpng", &crash(REAL_HEAP_WRITE), 44, TreeProvenance::Field).unwrap();assert_eq!(advisory.target(), "libpng");assert_eq!(advisory.class(), "heap-buffer-overflow(write)");assert_eq!(advisory.severity(), Severity::Exploitable);@@ -255,14 +277,15 @@ SUMMARY: AddressSanitizer: heap-buffer-overflow (/out/harness+0x4a1) in MAGMA_pn);assert_eq!(unkeyed.stack_hash(), None);assert!(- Advisory::draft("libpng", &unkeyed, 1).is_none(),+ Advisory::draft("libpng", &unkeyed, 1, TreeProvenance::Field).is_none(),"an advisory names one bug, and a crash the triage layer refused to key is not known to be one bug");}#[test]fn a_planted_benchmark_crash_is_never_disclosable() {- let advisory = Advisory::draft("libpng", &crash(CANARY_CRASH), 44).unwrap();+ let advisory =+ Advisory::draft("libpng", &crash(CANARY_CRASH), 44, TreeProvenance::Field).unwrap();assert_eq!(advisory.provenance(), Provenance::SyntheticBenchmark);assert!(!advisory.is_disclosable(),@@ -295,7 +318,8 @@ SUMMARY: AddressSanitizer: heap-buffer-overflow (/out/harness+0x4a1) in MAGMA_pn#[test]fn a_real_crash_is_not_mistaken_for_a_benchmark() {- let advisory = Advisory::draft("libpng", &crash(REAL_HEAP_WRITE), 1).unwrap();+ let advisory =+ Advisory::draft("libpng", &crash(REAL_HEAP_WRITE), 1, TreeProvenance::Field).unwrap();assert_eq!(advisory.provenance(),Provenance::Field,@@ -316,6 +340,83 @@ SUMMARY: AddressSanitizer: heap-buffer-overflow (/out/harness+0x4a1) in MAGMA_pnassert!(report.frames().iter().any(|f| f == BENCHMARK_CANARY_FRAME));}+ #[test]+ fn a_benchmark_tree_makes_a_crash_with_no_canary_frame_undisclosable() {+ let report = SanitizerReport::parse(REAL_HEAP_WRITE).unwrap();+ assert_eq!(+ provenance_of(&report),+ Provenance::Field,+ "the fixture must isolate the signal: the frame guard sees nothing benchmark-shaped here"+ );++ let advisory = Advisory::draft(+ "libpng",+ &crash(REAL_HEAP_WRITE),+ 44,+ TreeProvenance::Benchmark,+ )+ .unwrap();+ assert_eq!(advisory.provenance(), Provenance::SyntheticBenchmark);+ assert!(+ !advisory.is_disclosable(),+ "magma forward-ports real historical CVEs into current source, so a benchmark tree contains already-fixed vulnerabilities; a crash that misses the canary would otherwise be filed as a new bug against a library that fixed it years ago"+ );+ }++ #[test]+ fn an_unknown_tree_decides_on_frame_evidence_in_both_directions() {+ let planted =+ Advisory::draft("libpng", &crash(CANARY_CRASH), 1, TreeProvenance::Unknown).unwrap();+ assert_eq!(planted.provenance(), Provenance::SyntheticBenchmark);++ let field = Advisory::draft(+ "libpng",+ &crash(REAL_HEAP_WRITE),+ 1,+ TreeProvenance::Unknown,+ )+ .unwrap();+ assert_eq!(+ field.provenance(),+ Provenance::Field,+ "a database written before lisdex measured trees must keep behaving exactly as it did, or the fix silently retracts every finding ever recorded"+ );+ }++ #[test]+ fn the_tree_and_the_frames_are_independent_arms() {+ let clean = SanitizerReport::parse(REAL_HEAP_WRITE).unwrap();+ let planted = SanitizerReport::parse(CANARY_CRASH).unwrap();++ assert_eq!(+ resolve_provenance(TreeProvenance::Benchmark, &clean),+ Provenance::SyntheticBenchmark,+ "the tree arm alone must be enough"+ );+ assert_eq!(+ resolve_provenance(TreeProvenance::Field, &planted),+ Provenance::SyntheticBenchmark,+ "the frame arm alone must be enough, so a benchmark tree that was never recorded is still caught"+ );+ assert_eq!(+ resolve_provenance(TreeProvenance::Field, &clean),+ Provenance::Field,+ "and with neither arm firing the finding stays disclosable, or the mark means nothing"+ );+ }++ #[test]+ fn an_advisory_remembers_which_tree_it_came_from() {+ let advisory = Advisory::draft(+ "libpng",+ &crash(REAL_HEAP_WRITE),+ 1,+ TreeProvenance::Benchmark,+ )+ .unwrap();+ assert_eq!(advisory.tree(), TreeProvenance::Benchmark);+ }+#[test]fn every_operator_input_states_a_field_and_a_reason() {for input in OPERATOR_INPUTS {@@ -332,7 +433,7 @@ SUMMARY: AddressSanitizer: heap-buffer-overflow (/out/harness+0x4a1) in MAGMA_pnlet ubsan = crash("pngrutil.c:1204:7: runtime error: left shift of negative value -1\n #0 0x55a in png_do_read_transform pngrtran.c:1204:7\n",);- let advisory = Advisory::draft("libpng", &ubsan, 1).unwrap();+ let advisory = Advisory::draft("libpng", &ubsan, 1, TreeProvenance::Field).unwrap();assert_eq!(advisory.severity(), Severity::Undefined);assert!(!advisory.severity_is_assessed(),diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/json.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/json.rsindex 5d4ad1c1..267b43b2 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/json.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/json.rs@@ -50,6 +50,7 @@ pub fn render(advisory: &Advisory) -> Value {Provenance::Field => "field",Provenance::SyntheticBenchmark => "synthetic_benchmark",},+ "tree_provenance": advisory.tree().as_str(),"sanitizer_report": advisory.sanitizer_report(),"declined": declined(),"ghsa": {diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/markdown.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/markdown.rsindex 677fcbfa..9400c155 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/markdown.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/src/markdown.rs@@ -19,6 +19,13 @@ const PROVENANCE_BANNER: &str = "> **DO NOT FILE THIS ADVISORY.** The crash it dFiling it would report a fabricated vulnerability against real, widely deployed software. \lisdex renders it so the run can be audited, not so it can be sent.";+const TREE_PROVENANCE_BANNER: &str = "> **DO NOT FILE THIS ADVISORY.** It was found against a \+ benchmark tree, not against the library as its maintainers ship it. Benchmark suites plant \+ canaries and forward-port real historical CVEs into current source, so a finding from one is \+ either a fabricated bug or a genuine vulnerability that was fixed years ago. This is decided \+ by the target lisdex measured at campaign start, not by the call stack below, which may carry \+ no benchmark frame at all. lisdex renders it so the run can be audited, not so it can be sent.";+const DRAFTED_BY: &str = "_Drafted by lisdex from one fuzzing campaign. Every heading below that \reads NOT ESTABLISHED is a field lisdex declines to fill rather than guess, and each states \why. Fill them in or delete them before sending this to anyone._";@@ -231,10 +238,18 @@ fn push_analysis(out: &mut String, advisory: &Advisory) {let _ = writeln!(out);}+fn provenance_banner(advisory: &Advisory) -> &'static str {+ if advisory.tree().is_benchmark() {+ TREE_PROVENANCE_BANNER+ } else {+ PROVENANCE_BANNER+ }+}+fn push_filing(out: &mut String, advisory: &Advisory) {let _ = write!(out, "{FILING_HEADING}\n\n");if advisory.provenance() == Provenance::SyntheticBenchmark {- let _ = write!(out, "{PROVENANCE_BANNER}\n\n");+ let _ = write!(out, "{}\n\n", provenance_banner(advisory));return;}let _ = writeln!(out, "- {PACKAGE_NAME_NOTE}");@@ -258,7 +273,7 @@ pub fn render(advisory: &Advisory, bundled: Option<Reproducer>) -> String {site);if advisory.provenance() == Provenance::SyntheticBenchmark {- let _ = write!(out, "{PROVENANCE_BANNER}\n\n");+ let _ = write!(out, "{}\n\n", provenance_banner(advisory));}let _ = write!(out, "{DRAFTED_BY}\n\n");push_summary(&mut out, advisory);diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/bundling.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/bundling.rsindex 2db097d6..974e214f 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/bundling.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/bundling.rs@@ -1,7 +1,7 @@// ©AngelaMos | 2026// bundling.rs-use lisdex_core::campaign::CampaignId;+use lisdex_core::campaign::{CampaignId, TreeProvenance};use lisdex_core::crash::Crash;use lisdex_report::advisory::Advisory;use lisdex_report::bundle::{@@ -33,7 +33,7 @@ SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0x4553b) in kilfn advisory(report: &str) -> Advisory {let crash = Crash::from_report(CAMPAIGN, POC.to_vec(), report);- Advisory::draft("libpng", &crash, 12).expect("fixture must draft")+ Advisory::draft("libpng", &crash, 12, TreeProvenance::Field).expect("fixture must draft")}fn scratch(name: &str) -> std::path::PathBuf {diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/rendering.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/rendering.rsindex 50fb36ef..bade7819 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/rendering.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-report/tests/rendering.rs@@ -1,7 +1,7 @@// ©AngelaMos | 2026// rendering.rs-use lisdex_core::campaign::CampaignId;+use lisdex_core::campaign::{CampaignId, TreeProvenance};use lisdex_core::crash::Crash;use lisdex_report::advisory::{Advisory, OPERATOR_INPUTS};use lisdex_report::json::{self, GHSA_ECOSYSTEM_FOR_C_LIBRARIES};@@ -35,7 +35,7 @@ pngrutil.c:1204:7: runtime error: left shift of negative value -1fn advisory(report: &str) -> Advisory {let crash = Crash::from_report(CAMPAIGN, b"reproducer-bytes".to_vec(), report);- Advisory::draft("libpng", &crash, 44).expect("fixture must draft")+ Advisory::draft("libpng", &crash, 44, TreeProvenance::Field).expect("fixture must draft")}#[test]@@ -76,6 +76,30 @@ fn a_planted_benchmark_finding_is_rendered_with_a_refusal_and_no_filing_instruct);}+#[test]+fn a_tree_refusal_does_not_claim_a_call_stack_it_cannot_show() {+ let crash = Crash::from_report(CAMPAIGN, b"reproducer-bytes".to_vec(), REAL_HEAP_WRITE);+ let from_tree = Advisory::draft("libpng", &crash, 44, TreeProvenance::Benchmark)+ .expect("fixture must draft");+ let rendered = markdown::render(&from_tree, None);++ assert!(rendered.contains("DO NOT FILE THIS ADVISORY"));+ assert!(+ !rendered.contains("benchmark instrumentation in its call stack"),+ "this crash was refused on the target lisdex measured, and its stack carries no benchmark frame; saying otherwise is a claim the evidence does not support"+ );+ assert!(+ rendered.contains("forward-port real historical CVEs"),+ "the reader has to be told the actual reason, or a refusal they can see is unfounded reads as a bug in lisdex"+ );++ let from_frames = markdown::render(&advisory(CANARY_CRASH), None);+ assert!(+ from_frames.contains("benchmark instrumentation in its call stack"),+ "and the stack-evidence wording must survive for the case where the stack really does show it"+ );+}+#[test]fn a_real_finding_is_rendered_with_the_filing_route_that_actually_applies() {let rendered = markdown::render(&advisory(REAL_HEAP_WRITE), None);diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-tui/tests/render.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-tui/tests/render.rsindex 56d338d4..5c547022 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-tui/tests/render.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-tui/tests/render.rs@@ -3,7 +3,7 @@use std::path::PathBuf;-use lisdex_core::campaign::{Campaign, CampaignStatus};+use lisdex_core::campaign::{Campaign, CampaignStatus, TreeProvenance};use lisdex_core::crash::Crash;use lisdex_core::store::Store;use lisdex_monitor::snapshot::{Snapshot, Source};@@ -105,7 +105,7 @@ impl Lab {fn campaign(&self) {let store = Store::open(self.root.join("lisdex.sqlite")).unwrap();- let mut campaign = Campaign::new("lisdex_libpng_read");+ let mut campaign = Campaign::new("lisdex_libpng_read", TreeProvenance::Field);let id = store.insert_campaign(&campaign).unwrap();campaign.advance(CampaignStatus::Building).unwrap();campaign.advance(CampaignStatus::Fuzzing).unwrap();diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rsindex 082e5be6..a83be9f9 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs@@ -3,7 +3,7 @@use std::error::Error;use std::io::Write;-use std::path::PathBuf;+use std::path::{Path, PathBuf};use std::process::ExitCode;use std::time::Duration;@@ -12,8 +12,8 @@ use lisdex_build::artifact;use lisdex_build::instrument::Instrumentation;use lisdex_build::ladder::{self, BuildOptions};use lisdex_build::layout::{BuildLayout, VARIANT_AFL, VARIANT_BENCH};-use lisdex_build::verify::Requirements;-use lisdex_core::campaign::{Campaign, CampaignId, CampaignStatus};+use lisdex_build::verify::{self, Requirements};+use lisdex_core::campaign::{Campaign, CampaignId, CampaignStatus, TreeProvenance};use lisdex_core::config::{DEFAULT_MINIMIZE_EXEC_TIMEOUT_MS, DEFAULT_REPRODUCE_TIMEOUT_MS, LlmTier,};@@ -53,6 +53,12 @@ const MINIMIZED_SUFFIX: &str = ".min";const MARKDOWN_SUFFIX: &str = ".md";const JSON_SUFFIX: &str = ".json";const NOT_DISCLOSABLE_MARKER: &str = " NOT DISCLOSABLE";+const BENCHMARK_TREE_WARNING: &str = "warning: this target links magma canary symbols, so its tree is a benchmark carrying \+ forward-ported historical CVEs. Every finding from this campaign is recorded NOT \+ DISCLOSABLE regardless of what its stack shows.";+const UNKNOWN_TREE_WARNING: &str = "warning: the target's symbols could not be read, so whether its tree is a benchmark is \+ unknown. Disclosability falls back to stack frames alone, which cannot see a \+ forward-ported bug that misses the canary.";const DISPLAYED_FRAMES: usize = 6;const SOURCES_DIR: &str = "sources";const BUILDS_DIR: &str = "builds";@@ -1352,6 +1358,20 @@ fn oracle_bench(}}+fn campaign_tree(target: &Path) -> TreeProvenance {+ let tree = match verify::inspect(target) {+ Ok(counts) if counts.magma > 0 => TreeProvenance::Benchmark,+ Ok(_) => TreeProvenance::Field,+ Err(_) => TreeProvenance::Unknown,+ };+ match tree {+ TreeProvenance::Benchmark => eprintln!("{BENCHMARK_TREE_WARNING}"),+ TreeProvenance::Unknown => eprintln!("{UNKNOWN_TREE_WARNING}"),+ TreeProvenance::Field => {}+ }+ tree+}+fn fuzz(args: &FuzzArgs) -> Result<(), Box<dyn Error>> {let label = args.label.clone().unwrap_or_else(|| {args.target@@ -1369,7 +1389,7 @@ fn fuzz(args: &FuzzArgs) -> Result<(), Box<dyn Error>> {std::fs::create_dir_all(parent)?;}let store = Store::open(&args.db)?;- let mut campaign = Campaign::new(label.clone());+ let mut campaign = Campaign::new(label.clone(), campaign_tree(&args.target));let campaign_id = store.insert_campaign(&campaign)?;for status in [CampaignStatus::Building, CampaignStatus::Fuzzing] {@@ -1787,7 +1807,7 @@ fn advisories(args: &AdvisoryArgs) -> Result<(), Box<dyn Error>> {};let stem = short_hash(crash.stack_hash());let package = args.package.as_deref().unwrap_or_else(|| campaign.target());- match Advisory::draft(package, crash, group.len()) {+ match Advisory::draft(package, crash, group.len(), campaign.tree()) {Some(advisory) => drafted.push((stem, advisory)),None => eprintln!("warning: bug {stem} has no dedup key, so its crashes are not known to be one bug and no advisory names them"@@ -1849,7 +1869,7 @@ fn bundles(args: &BundleArgs) -> Result<(), Box<dyn Error>> {};let stem = short_hash(crash.stack_hash());let package = args.package.as_deref().unwrap_or_else(|| campaign.target());- let Some(advisory) = Advisory::draft(package, crash, group.len()) else {+ let Some(advisory) = Advisory::draft(package, crash, group.len(), campaign.tree()) else {eprintln!("warning: bug {stem} has no dedup key, so no advisory names it and no bundle is written");diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/02-ARCHITECTURE.md b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/02-ARCHITECTURE.mdindex 6670f747..c4751611 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/02-ARCHITECTURE.md+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/02-ARCHITECTURE.md@@ -143,7 +143,8 @@ differential oracle, and it is stronger than any amount of reading the code.main verdict, `FaultAddress` for the null-versus-wild distinction.8. **`Advisory::draft` builds the disclosure** from the group's representative- crash, refusing the fields it cannot know.+ crash and the campaign's tree provenance, refusing the fields it cannot know+ and refusing disclosure entirely for anything from a benchmark tree.## Design Decisions@@ -223,7 +224,12 @@ struct Crash {The sqlite schema is deliberately small:```sql-CREATE TABLE campaigns (id INTEGER PRIMARY KEY, target TEXT, status TEXT);+CREATE TABLE campaigns (+ id INTEGER PRIMARY KEY,+ target TEXT,+ status TEXT,+ tree_provenance TEXT+);CREATE TABLE crashes (id INTEGER PRIMARY KEY,campaign_id INTEGER REFERENCES campaigns(id),@@ -233,6 +239,11 @@ CREATE TABLE crashes ();```+`tree_provenance` is `field`, `benchmark`, or `unknown`, and a database written+before that column existed reads back as `unknown` rather than `field`. That+distinction is load-bearing: an unmeasured tree must not be able to assert+something nobody checked.+There is no version column, no severity column, no bug table. Severity andbucketing are computed from the report on read, so improving the classifierimproves every campaign already in the store.@@ -257,8 +268,23 @@ page is the SVG namespace string, which browsers never fetch.lisdex validates itself against Magma, which works by injecting known bugs intoreal libraries. A Magma crash is a *planted* bug, and reporting one to libpng-would be embarrassing at best. `provenance_of` detects the Magma canary frames-and stamps the advisory NOT DISCLOSABLE with no filing route.+would be embarrassing at best. Worse, Magma also forward-ports real historical+CVEs into current source, so a benchmark tree holds genuine vulnerabilities that+were fixed years ago.++The guard has two independent arms, and either one alone refuses disclosure:++- **The stack arm.** `provenance_of` detects Magma's canary frames in the report.+- **The tree arm.** At campaign start lisdex scans the target binary's symbols. A+ build carrying the canary runtime is a benchmark build, and `tree_provenance`+ records that on the campaign. Every finding from it is refused *whatever the+ stack looks like*.++The tree arm exists because the stack arm asks the wrong question. Whether a+crash routed through a canary is an accident of which bug fired; whether the tree+is a benchmark is a fact about the target. `Advisory::draft` takes the campaign's+tree provenance as a required argument, so no caller can draft an advisory+without stating what kind of tree it came from.## Performance Considerationsdiff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/03-IMPLEMENTATION.md b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/03-IMPLEMENTATION.mdindex d5a17b27..f2ef0eee 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/03-IMPLEMENTATION.md+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/03-IMPLEMENTATION.md@@ -315,13 +315,22 @@ override is visible rather than hidden.`Advisory::draft` builds from a group's representative crash:```rust-pub fn draft(target: &str, representative: &Crash, crash_count: usize)- -> Option<Advisory>+pub fn draft(+ target: &str,+ representative: &Crash,+ crash_count: usize,+ tree: TreeProvenance,+) -> Option<Advisory>```It returns `None` when the crash cannot support an advisory, which is the samerefusal discipline as everywhere else.+`tree` is required rather than optional on purpose. Disclosability depends on+what kind of tree the campaign ran against, so making it a parameter means the+compiler will not let a caller draft an advisory while leaving that question+unanswered.+`weakness.rs` maps the bug class to a CWE. `markdown.rs` and `json.rs` render theOpenSSF template. `bundle.rs` writes a directory per bug:@@ -344,6 +353,21 @@ no reproducer.instrumented benchmark is stamped `NOT DISCLOSABLE` and carries no filing route,because reporting a planted bug to a maintainer wastes their time.+That is only half the guard, and it is the weaker half. A stack heuristic answers+"did this crash route through a canary?" when the question that matters is "is+this target a benchmark?" So `campaign_tree` scans the target binary's symbols+once, at campaign start, and stores the answer on the campaign;+`resolve_provenance` refuses disclosure if *either* the tree or the frames say+benchmark. The two arms are independent, and the exit gate proves it with a pair+of controls that are the same report bytes differing only in the stored tree+value.++Watch what the split did to the rendered advisory. The original refusal banner+told the reader the crash "carries benchmark instrumentation in its call stack."+For a tree-arm refusal that sentence is false, and a reader who checks the stack+and finds it clean would reasonably conclude lisdex was broken. A refusal has to+state the reason it actually used, so there are two banners.+## Stage 8: The Read-Model`Snapshot::read` collapses everything into one immutable value:diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/04-CHALLENGES.md b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/04-CHALLENGES.mdindex 0124be51..a3c4c63b 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/04-CHALLENGES.md+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/learn/04-CHALLENGES.md@@ -65,16 +65,36 @@ Implementing this means running each crash more than once and comparing. Thinkabout what that costs on a pile of 200 crashes, and whether the answer changesany advisory.-### 6. Target-level provenance--The Magma guard reads the crash stack for canary frames. That works, but the real-property is of the **target tree**: a build that was patched with bug canaries is-a benchmark build, whatever any individual stack looks like.--Move the signal to where it belongs. The `campaigns` table would need a column,-and `lisdex build` would need to record that it applied benchmark patches. Then-a campaign against an instrumented target is non-disclosable even for a crash-whose stack happens to contain no canary frame.+### 6. Target-level provenance beyond Magma++This one is half done in the shipped code, and the half that is missing is the+interesting half.++lisdex records a `tree_provenance` on every campaign by scanning the target+binary's symbols for Magma's canary runtime, and refuses disclosure for anything+from a benchmark tree whatever the stack shows. But that detector knows exactly+one benchmark suite. Point lisdex at a target built from an OSS-Fuzz corpus, from+FuzzBench, or from an ARVO reproducer and it will happily call the tree `field`.++Generalize it. What is the signal for "this build is not the library as its+maintainers ship it"? Symbol names are one answer and a narrow one. Build+metadata, a recorded source provenance, and a checksum against an upstream+release tarball are all better and all harder.++Two things worth knowing before you start, both measured on the shipped code:++- The obvious way to test this is to build Magma without `MAGMA_FATAL_CANARIES`+ so the canary logs instead of killing the process, expecting execution to+ continue into the real corruption and produce a crash with no canary frame on+ the stack. It does not work on libpng. A 600-second campaign against that build+ ran 62.6 million executions to the same edge coverage and found **zero**+ crashes, and replaying 83 known-crashing inputs against it produced **zero**+ faults where the fatal build produced 83. A canary condition is a *precondition+ detector*, not the corruption itself.+- Replaying crashes at scale needs `ASAN_OPTIONS=symbolize=0`. With the default,+ every execution stalls in the in-process symbolizer and emits a truncated+ report with no function names at all, so any grep over the frames silently+ matches nothing and hands you a confident null result.### 7. Statistical rigor for comparisonsdiff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/build-magma-libpng.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/build-magma-libpng.shindex e3533cb4..e2772840 100755--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/build-magma-libpng.sh+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/build-magma-libpng.sh@@ -9,7 +9,16 @@ MAGMA="$MAGMA_SRC/magma"WORK="${MAGMA_WORK:-/opt/magma-work}"TARGET="$WORK/libpng"SHARED="$WORK/shared"-OUT_ROOT="$WORK/out/libpng"+FATAL_CANARIES="${LISDEX_MAGMA_FATAL_CANARIES:-1}"+if [ "$FATAL_CANARIES" = "1" ]; then+ FATAL_DEFINE="-DMAGMA_FATAL_CANARIES"+ OUT_ROOT="$WORK/out/libpng"+ CANARY_MODE="FATAL canaries ON"+else+ FATAL_DEFINE=""+ OUT_ROOT="$WORK/out/libpng-nonfatal"+ CANARY_MODE="FATAL canaries OFF - canaries LOG ONLY and execution continues into the real corruption"+fiHARNESS_SRC="${LISDEX_HARNESS:-/work/harnesses/libpng_read.c}"DRIVER="${LISDEX_AFL_DRIVER:-/usr/local/lib/afl/libAFLDriver.a}"HARNESS_BIN="lisdex_libpng_read"@@ -19,7 +28,7 @@ EXPECTED_LIBPNG_COMMIT="a37d4836519517bdce6cb9d956092321eca3e73b"VARIANTS=(afl cmplog)LISDEX_EXCLUDED_BUGS="${LISDEX_EXCLUDED_BUGS:-PNG005 PNG002}"-CANARY_FLAGS="-include $MAGMA/src/canary.h -DMAGMA_ENABLE_CANARIES -DMAGMA_FATAL_CANARIES -g -O0"+CANARY_FLAGS="-include $MAGMA/src/canary.h -DMAGMA_ENABLE_CANARIES $FATAL_DEFINE -g -O0"log() {printf '\n[lisdex] %s\n' "$1"@@ -121,7 +130,7 @@ for VARIANT in "${VARIANTS[@]}"; doexport CC=clangexport LD=ld.lld- export CFLAGS="-DMAGMA_FATAL_CANARIES -g -O0"+ export CFLAGS="$FATAL_DEFINE -g -O0"export LDFLAGS=""bash "$MAGMA/build.sh"@@ -199,7 +208,7 @@ doneprintf '\n'if [ "$FAILURES" -eq 0 ]; then- printf '[lisdex] MAGMA LIBPNG TARGET READY (canaries ON, fixes OFF, FATAL canaries ON)\n'+ printf '[lisdex] MAGMA LIBPNG TARGET READY (canaries ON, fixes OFF, %s)\n' "$CANARY_MODE"printf '[lisdex] fuzz target : %s\n' "$OUT_ROOT/afl/$HARNESS_BIN"printf '[lisdex] cmplog : %s\n' "$OUT_ROOT/cmplog/$HARNESS_BIN"printf '[lisdex] monitor : %s\n' "$OUT_ROOT/monitor"diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m8-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m8-gate.shindex 584c2e8d..d91fd16f 100755--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m8-gate.sh+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m8-gate.sh@@ -110,6 +110,18 @@ elsefail "campaign found no crashes; the gate has nothing to report on"fi+# The two stage-7 controls hand lisdex a tree provenance in a hand-built database, so they+# check what lisdex DOES with the value, never whether it can MEASURE one. This reads the+# column lisdex wrote for itself, off the real magma binary it just fuzzed. Without it, a+# detector hardwired to 'field' passes the whole gate, because every crash above carries a+# canary frame and the frame arm covers for it.+STORED_TREE="$(sqlite3 "$DB" 'SELECT tree_provenance FROM campaigns WHERE id = 1;' || true)"+if [ "$STORED_TREE" = "benchmark" ]; then+ pass "lisdex measured the target itself and recorded the campaign tree as benchmark"+else+ fail "the campaign against a magma build recorded tree_provenance='$STORED_TREE', not 'benchmark'"+fi+log "stage 5/8: minimize, then bundle"rm -rf "$MIN_OUT" "$BUNDLES" "$STANDALONE""$LISDEX_BIN" minimize --db "$DB" --campaign 1 --target "$TARGET" --out "$MIN_OUT" \@@ -242,6 +254,47 @@ elsefail "a disclosable advisory was rendered without a filing route"fi+# The control above proves the FRAME arm is not hardwired. It says nothing about the TREE+# arm. Magma forward-ports real historical CVEs into current source, so a benchmark tree+# holds genuine already-fixed vulnerabilities a crash can reach without ever touching a+# canary - and that crash carries no benchmark frame to find. This control is the SAME+# report bytes as the one above, attributed to a campaign whose tree lisdex recorded as a+# benchmark. The tree column is the only difference between them, so neither can alibi the+# other.+TREE_DB="$GATE/control-tree.sqlite"+rm -f "$TREE_DB"+sqlite3 "$TREE_DB" <<'SQL'+CREATE TABLE campaigns (+ id INTEGER PRIMARY KEY,+ target TEXT NOT NULL,+ status TEXT NOT NULL,+ tree_provenance TEXT+);+CREATE TABLE crashes (+ id INTEGER PRIMARY KEY,+ campaign_id INTEGER NOT NULL REFERENCES campaigns(id),+ input BLOB NOT NULL,+ sanitizer_report TEXT NOT NULL,+ stack_hash TEXT+);+INSERT INTO campaigns (id, target, status, tree_provenance)+VALUES (1, 'libpng', 'completed', 'benchmark');+SQL+sqlite3 "$TREE_DB" \+ "INSERT INTO crashes (campaign_id, input, sanitizer_report, stack_hash)+ VALUES (1, zeroblob(1), CAST(readfile('$GATE/control-report.txt') AS TEXT), NULL);"+"$LISDEX_BIN" advisory --db "$TREE_DB" --campaign 1 --package "$PACKAGE" \+ --format json > "$GATE/control-tree-advisories.json" 2>/dev/null || true+python3 - "$GATE/control-tree-advisories.json" <<'PY' && pass "the same de-instrumented report from a BENCHMARK tree is refused on the tree alone" || fail "a benchmark tree did not refuse disclosure, so a forward-ported CVE could be filed as a new bug"+import json, sys+documents = json.load(open(sys.argv[1]))+assert documents, "no advisory drafted from the de-instrumented report"+for d in documents:+ assert d["disclosable"] is False, f"{d['dedup_key']} is disclosable from a benchmark tree"+ assert d["provenance"] == "synthetic_benchmark", d["provenance"]+print(f" {len(documents)} advisory, NOT disclosable, provenance synthetic_benchmark")+PY+log "stage 8/8: the shipped reproducer still crashes, and the bundles do not all carry the same bug"SIGNATURES="$GATE/signatures.txt": > "$SIGNATURES"@@ -273,6 +326,7 @@ if [ "$FAILURES" -eq 0 ]; thenprintf ' CHECK 2 that bundle is stamped NOT DISCLOSABLE, and carries no filing route\n'printf ' CHECK 3 real captured errors are still disclosable, so the mark is not a constant\n'printf ' CHECK 4 the shipped reproducer replays the fault it names\n'+ printf ' CHECK 5 a benchmark TREE refuses disclosure on its own, with no canary frame to read\n'exit 0fiprintf '\n[m8] M8 EXIT GATE FAILED: %s check(s)\n' "$FAILURES" >&2