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
feat(lisdex): B80 - the library must be numbered before the harness, not beside it
CarterPerez-devbf0f2b22add3
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/instrument.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/instrument.rsindex 52af8102..97d8fa97 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/instrument.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/instrument.rs@@ -3,6 +3,8 @@pub const AFL_CC: &str = "afl-clang-lto";pub const AFL_CXX: &str = "afl-clang-lto++";+pub const AFL_CC_PCGUARD: &str = "afl-clang-fast";+pub const AFL_CXX_PCGUARD: &str = "afl-clang-fast++";pub const PLAIN_CC: &str = "clang";pub const PLAIN_CXX: &str = "clang++";pub const LLVM_AR: &str = "llvm-ar";@@ -98,6 +100,19 @@ impl Toolchain {}}+ // B80. The fuzzing archive is LTO because that is the faster instrumentation, and LTO is+ // also why two harnesses linked against it cannot have their edges compared. PCGUARD bakes+ // a guard array into each object instead, so the library's numbering survives a second+ // link - which is the whole precondition oracles 3b and 4 rest on.+ #[must_use]+ pub fn pcguard() -> Self {+ Self {+ cc: AFL_CC_PCGUARD.to_owned(),+ cxx: AFL_CXX_PCGUARD.to_owned(),+ ..Self::default()+ }+ }+#[must_use]pub fn with_compilers(mut self, cc: impl Into<String>, cxx: impl Into<String>) -> Self {self.cc = cc.into();@@ -158,6 +173,18 @@ impl Instrumentation {}}+ // The oracle bench's own library build. Same sanitizers and same flags as the fuzzing+ // build - it has to execute the same code - and cmplog is off because it is a fuzzing+ // aid that costs the bench time and buys it nothing.+ #[must_use]+ pub fn oracle_bench() -> Self {+ Self {+ cmplog: false,+ toolchain: Toolchain::pcguard(),+ ..Self::default()+ }+ }+#[must_use]pub fn with_cmplog(mut self, cmplog: bool) -> Self {self.cmplog = cmplog;@@ -325,6 +352,43 @@ mod tests {assert_eq!(value(&envs, ENV_CFLAGS), value(&envs, ENV_CXXFLAGS));}+ // B80's remaining half. The oracle bench needs a library whose guard IDs are baked into the+ // objects, which is what `afl-clang-fast` emits and what `afl-clang-lto` by definition+ // cannot: LTO has no objects to bake them into until the link.+ #[test]+ fn the_oracle_bench_builds_the_library_with_the_pcguard_compiler() {+ let envs = Instrumentation::oracle_bench().envs();+ assert_eq!(value(&envs, ENV_CC).as_deref(), Some(AFL_CC_PCGUARD));+ assert_eq!(value(&envs, ENV_CXX).as_deref(), Some(AFL_CXX_PCGUARD));+ }++ // It has to execute the SAME code as the fuzzing build or the coverage it measures is not+ // the coverage that gets fuzzed, so the sanitizers and flags are not relaxed for speed.+ #[test]+ fn the_oracle_bench_keeps_the_sanitizers_the_fuzzing_build_has() {+ let envs = Instrumentation::oracle_bench().envs();+ assert_eq!(value(&envs, ENV_AFL_USE_ASAN).as_deref(), Some(ENV_ENABLED));+ assert_eq!(+ value(&envs, ENV_AFL_USE_UBSAN).as_deref(),+ Some(ENV_ENABLED)+ );+ assert_eq!(+ Instrumentation::oracle_bench().cflags_string(),+ Instrumentation::instrumented().cflags_string()+ );+ }++ // cmplog is a fuzzing aid. The bench never fuzzes, and a cmplog pass on it is build time+ // spent on a table nothing reads.+ #[test]+ fn the_oracle_bench_does_not_carry_cmplog() {+ assert!(!Instrumentation::oracle_bench().cmplog);+ assert_eq!(+ value(&Instrumentation::oracle_bench().envs(), ENV_AFL_LLVM_CMPLOG),+ None+ );+ }+#[test]fn the_uninstrumented_pass_uses_plain_clang_and_no_sanitizers() {let instrumentation = Instrumentation::uninstrumented();diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/layout.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/layout.rsindex e1ca00c8..c65916a8 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/layout.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/layout.rs@@ -7,6 +7,7 @@ use lisdex_ingest::detect::BuildSystem;pub const VARIANT_AFL: &str = "afl";pub const VARIANT_CMPLOG: &str = "cmplog";+pub const VARIANT_BENCH: &str = "bench";pub const BUILD_DIR_PREFIX: &str = "build";pub const INSTALL_DIR: &str = "install";pub const TOOLCHAIN_DIR: &str = "toolchain";diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rsindex 477ea311..50475b99 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs@@ -6,6 +6,11 @@ use std::path::{Path, PathBuf};use lisdex_core::process::CommandSpec;pub const CC: &str = "afl-clang-lto";+pub const CC_PCGUARD: &str = "afl-clang-fast";+pub const WHOLE_ARCHIVE: &str = "-Wl,--whole-archive";+pub const NO_WHOLE_ARCHIVE: &str = "-Wl,--no-whole-archive";+pub const START_GROUP: &str = "-Wl,--start-group";+pub const END_GROUP: &str = "-Wl,--end-group";pub const SHOWMAP: &str = "afl-showmap";pub const DEFAULT_DRIVER: &str = "/usr/local/lib/afl/libAFLDriver.a";pub const ASAN_OPTIONS: &str = "ASAN_OPTIONS";@@ -17,6 +22,40 @@ pub const SHOWMAP_TIMEOUT_MS: u64 = 5000;pub const TARGET_MODE_KEY: &str = "target_mode";pub const REQUIRED_TARGET_MODES: &[&str] = &["persistent", "shmem_testcase", "deferred"];+// B80. Which compiler builds the bench harness, and where the library sits on the link line.+// Both are decided by the archive, and neither is a preference.+//+// PCGUARD assigns edge IDs at startup by walking the concatenated `__sancov_guards` sections,+// so whichever object the linker placed FIRST owns the low IDs and everything after it shifts+// when that object changes size. `Lto` is the shape that has always shipped: `afl-clang-lto`+// instruments the whole merged module at link time, and nothing about the argument order+// changes that. `PcGuard` puts the library's guards in front of the harness's, which is the+// only arrangement in which appending a call to the harness leaves the library's numbering+// alone. `--whole-archive` rather than a `--start-group` that merely lists the archive first:+// a group re-scan still places each member where it was PULLED IN, which is after the harness,+// and measured 0 of 16 for exactly that reason.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub enum LinkScheme {+ #[default]+ Lto,+ PcGuard,+}++impl LinkScheme {+ #[must_use]+ pub fn compiler(self) -> &'static str {+ match self {+ LinkScheme::Lto => CC,+ LinkScheme::PcGuard => CC_PCGUARD,+ }+ }++ #[must_use]+ pub fn library_leads(self) -> bool {+ self == LinkScheme::PcGuard+ }+}+#[derive(Debug, Clone)]pub struct BuildSpec {pub source: PathBuf,@@ -28,6 +67,7 @@ pub struct BuildSpec {pub link_args: Vec<String>,pub driver: PathBuf,pub cmplog: bool,+ pub scheme: LinkScheme,}impl BuildSpec {@@ -43,13 +83,14 @@ impl BuildSpec {link_args: Vec::new(),driver: PathBuf::from(DEFAULT_DRIVER),cmplog: false,+ scheme: LinkScheme::default(),}}}#[must_use]pub fn build_command(spec: &BuildSpec) -> CommandSpec {- let mut command = CommandSpec::new(CC)+ let mut command = CommandSpec::new(spec.scheme.compiler()).env("AFL_USE_ASAN", "1").env("AFL_USE_UBSAN", "1").env("AFL_QUIET", "1");@@ -65,16 +106,23 @@ pub fn build_command(spec: &BuildSpec) -> CommandSpec {for include in &spec.includes {command = command.arg(format!("-I{}", include.display()));}+ if spec.scheme.library_leads() && !spec.archives.is_empty() {+ command = command.arg(WHOLE_ARCHIVE);+ for archive in &spec.archives {+ command = command.path_arg(archive);+ }+ command = command.arg(NO_WHOLE_ARCHIVE);+ }command = command.path_arg(&spec.source).arg("-o").path_arg(&spec.output);- if !spec.archives.is_empty() {- command = command.arg("-Wl,--start-group");+ if !spec.scheme.library_leads() && !spec.archives.is_empty() {+ command = command.arg(START_GROUP);for archive in &spec.archives {command = command.path_arg(archive);}- command = command.arg("-Wl,--end-group");+ command = command.arg(END_GROUP);}command = command.path_arg(&spec.driver);for link in &spec.link_args {@@ -189,6 +237,79 @@ mod tests {assert_eq!(build_command(&spec()).program, CC);}+ // B80's remaining half. Against a PCGUARD archive the harness has to be compiled by the+ // matching driver, because `afl-clang-lto` numbers its own blocks at link time and PCGUARD+ // bases the library's runtime numbering after that count.+ #[test]+ fn a_pcguard_archive_is_matched_by_the_pcguard_driver() {+ let mut spec = spec();+ spec.scheme = LinkScheme::PcGuard;+ assert_eq!(build_command(&spec).program, CC_PCGUARD);+ }++ // The ordering half, and it is the one the toy lab hid. Measured on libpng's real emitted+ // climb: the library ahead of the harness contains the parent's map in 16 of 16, and the+ // shipped order in 0 of 16 even with both sides on PCGUARD.+ #[test]+ fn a_pcguard_link_puts_the_library_ahead_of_the_harness() {+ let mut spec = spec();+ spec.scheme = LinkScheme::PcGuard;+ let line = build_command(&spec).command_line();+ let archive = line.find("libpng16.a").expect("archive on the line");+ let source = line.find("h.c").expect("source on the line");+ assert!(+ archive < source,+ "the library's guards must be numbered before the harness's: {line}"+ );+ assert!(line.contains(WHOLE_ARCHIVE));+ assert!(line.contains(NO_WHOLE_ARCHIVE));+ }++ // `--whole-archive` is what forces the placement; a `--start-group` listing the archive+ // first still places each member where it was pulled in, which is after the harness.+ #[test]+ fn a_pcguard_link_does_not_fall_back_to_a_group_that_would_not_reorder() {+ let mut spec = spec();+ spec.scheme = LinkScheme::PcGuard;+ let line = build_command(&spec).command_line();+ assert!(!line.contains(START_GROUP));+ }++ // The default is unchanged, and stays unchanged: an LTO archive is re-instrumented at every+ // link, so reordering it buys nothing and `--whole-archive` would only inflate the binary.+ #[test]+ fn the_lto_link_keeps_the_harness_first_and_the_archive_in_a_group() {+ let line = build_command(&spec()).command_line();+ let archive = line.find("libpng16.a").expect("archive on the line");+ let source = line.find("h.c").expect("source on the line");+ assert!(source < archive);+ assert!(line.contains(START_GROUP));+ assert!(!line.contains(WHOLE_ARCHIVE));+ }++ // The driver defines main and is not the thing being measured, so it stays last under both+ // schemes - ahead of it the library, behind it the caller's own link arguments.+ #[test]+ fn the_driver_still_follows_the_library_under_the_pcguard_scheme() {+ let mut spec = spec();+ spec.scheme = LinkScheme::PcGuard;+ let line = build_command(&spec).command_line();+ let archive = line.find("libpng16.a").expect("archive on the line");+ let driver = line.find("libAFLDriver.a").expect("driver on the line");+ let lz = line.find("-lz").expect("link arg on the line");+ assert!(archive < driver);+ assert!(driver < lz);+ }++ #[test]+ fn a_scheme_with_no_archives_emits_no_ordering_flags_at_all() {+ let mut spec = BuildSpec::new("/w/h.c", "/w/h.bin");+ spec.scheme = LinkScheme::PcGuard;+ let line = build_command(&spec).command_line();+ assert!(!line.contains(WHOLE_ARCHIVE));+ assert!(!line.contains(START_GROUP));+ }+#[test]fn showmap_bounds_the_execution_and_silences_leak_detection() {let command = showmap_command(diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/coverage.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/coverage.rsindex 5368d086..c6fc0b4b 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/coverage.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/coverage.rs@@ -9,26 +9,50 @@ pub const AR_MAGIC: &[u8] = b"!<arch>\n";pub const AR_HEADER_BYTES: usize = 60;pub const AR_SIZE_RANGE: std::ops::Range<usize> = 48..58;pub const BITCODE_MAGIC: &[u8] = b"BC\xc0\xde";+pub const SANCOV_GUARDS_SECTION: &[u8] = b"__sancov_guards";-// Whether two SEPARATELY LINKED binaries built against this archive can have their edge IDs-// compared at all, which is the precondition under every cross-harness coverage number.+// How the LIBRARY in this archive was instrumented, which is the precondition under every+// cross-harness coverage number: whether two SEPARATELY LINKED binaries built against it can+// have their edge IDs compared at all.//-// Measured on three real emitted parent/child pairs over eight seeds each. An LTO-bitcode-// archive is re-instrumented at every link and the parent's map was contained in the child's-// in 0 of 24 cases. An object archive carries PCGUARD guards whose IDs are assigned at STARTUP-// over the guard array, so a harness compiled to bitcode still shifts the library's base: 16 of-// 24. Matching both sides on PCGUARD gives 24 of 24. So a bitcode archive is the one state that-// can be read off the artifact and is always wrong, and that is what this answers.+// Read off the artifact rather than inferred. A bitcode member means `afl-clang-lto` will+// re-instrument the whole merged module at every link. A `__sancov_guards` section means the+// library carries PCGUARD guards of its own, assigned IDs at STARTUP by walking the guard+// array. Neither means the library carries no coverage instrumentation at all, so it+// contributes no fixed edges and the only edges in the map are the harness's own - which move+// whenever the harness does.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum ArchiveScheme {+ Bitcode,+ PcGuard,+ Opaque,+}++fn contains(haystack: &[u8], needle: &[u8]) -> bool {+ haystack.len() >= needle.len() && haystack.windows(needle.len()).any(|slot| slot == needle)+}++fn member_scheme(body: &[u8]) -> Option<ArchiveScheme> {+ if body.starts_with(BITCODE_MAGIC) {+ return Some(ArchiveScheme::Bitcode);+ }+ if contains(body, SANCOV_GUARDS_SECTION) {+ return Some(ArchiveScheme::PcGuard);+ }+ None+}+#[must_use]-pub fn is_bitcode_archive(path: &Path) -> bool {+pub fn archive_scheme(path: &Path) -> ArchiveScheme {let Ok(bytes) = std::fs::read(path) else {- return false;+ return ArchiveScheme::Opaque;};if !bytes.starts_with(AR_MAGIC) {- // Not an archive at all - a bare object or a shared library. Its own magic decides.- return bytes.starts_with(BITCODE_MAGIC);+ // Not an archive at all - a bare object or a shared library. Its own contents decide.+ return member_scheme(&bytes).unwrap_or(ArchiveScheme::Opaque);}let mut at = AR_MAGIC.len();+ let mut seen = ArchiveScheme::Opaque;while at + AR_HEADER_BYTES <= bytes.len() {let header = &bytes[at..at + AR_HEADER_BYTES];let size: usize = std::str::from_utf8(&header[AR_SIZE_RANGE])@@ -37,16 +61,34 @@ pub fn is_bitcode_archive(path: &Path) -> bool {.unwrap_or(0);let body = at + AR_HEADER_BYTES;if size == 0 || body + size > bytes.len() {- return false;+ return seen;}- if bytes[body..].starts_with(BITCODE_MAGIC) {- return true;+ match member_scheme(&bytes[body..body + size]) {+ // One bitcode member is enough: the link re-instruments the merged module, so+ // whatever the other members carry is renumbered along with it.+ Some(ArchiveScheme::Bitcode) => return ArchiveScheme::Bitcode,+ Some(scheme) => seen = scheme,+ None => {}}// Members are padded to an even offset, and the symbol table is a member like any- // other - it simply never carries the bitcode magic, so it needs no special case.+ // other - it simply never carries either signature, so it needs no special case.at = body + size + (size & 1);}- false+ seen+}++#[must_use]+pub fn is_bitcode_archive(path: &Path) -> bool {+ archive_scheme(path) == ArchiveScheme::Bitcode+}++// The one archive state whose numbering a second link cannot move. Measured on libpng's real+// emitted climb over 16 seeds: a PCGUARD archive with the harness compiled to match AND linked+// after the library contains the parent's map in 16 of 16, and every other combination of the+// three factors in 0 of 16.+#[must_use]+pub fn is_pcguard_archive(path: &Path) -> bool {+ archive_scheme(path) == ArchiveScheme::PcGuard}#[derive(Debug, Clone, Default, PartialEq, Eq)]@@ -205,6 +247,99 @@ mod tests {)));}+ // B80's remaining half. "Not bitcode" was never the same claim as "the library carries a+ // fixed numbering of its own": an uninstrumented archive is neither, and against one the+ // only edges in the map belong to the harness, which moves whenever the harness does.+ #[test]+ fn an_archive_carrying_guard_sections_is_recognised_as_fixed_at_library_build_time() {+ let path = written(+ "pcg",+ &archive(&[(+ "mylib.o/",+ b"\x7fELF\x02\x01\x01\x00....__sancov_guards....",+ )]),+ );+ assert!(is_pcguard_archive(&path));+ assert!(!is_bitcode_archive(&path));+ let _ = std::fs::remove_file(path);+ }++ // The isolating control for the arm above: same container, same walk, an ELF member with+ // no guard section. Without this a function returning PcGuard for every non-bitcode+ // archive would pass.+ #[test]+ fn an_uninstrumented_archive_is_neither_bitcode_nor_pcguard() {+ let path = written(+ "plain",+ &archive(&[("mylib.o/", b"\x7fELF\x02\x01\x01\x00")]),+ );+ assert_eq!(archive_scheme(&path), ArchiveScheme::Opaque);+ assert!(!is_pcguard_archive(&path));+ assert!(!is_bitcode_archive(&path));+ let _ = std::fs::remove_file(path);+ }++ // A real archive holds many members and the instrumented ones are not first. The guard+ // section has to be found behind the symbol table and behind uninstrumented members alike.+ #[test]+ fn a_guard_section_behind_other_members_is_still_found() {+ let path = written(+ "pcg-deep",+ &archive(&[+ ("/", b"\x00\x00\x00\x01symbols"),+ ("empty.o/", b"\x7fELF\x02\x01\x01\x00"),+ ("mylib.o/", b"\x7fELF\x02\x01\x01\x00..__sancov_guards.."),+ ]),+ );+ assert!(is_pcguard_archive(&path));+ let _ = std::fs::remove_file(path);+ }++ // Precedence, and it is not symmetric. A mixed archive still goes through the LTO link that+ // renumbers the merged module, so one bitcode member settles it however many guard sections+ // the other members carry.+ //+ // The member ORDER here is the whole control and was found by gutting: with the bitcode+ // member last, a walk that merely recorded what it saw instead of returning on it still+ // ends on Bitcode and passes. Bitcode FIRST is the arrangement in which only an early+ // return survives - anything else is overwritten by the guard section behind it.+ #[test]+ fn one_bitcode_member_outranks_every_guard_section_behind_it() {+ let path = written(+ "mixed-bc-first",+ &archive(&[+ ("lto.o/", b"BC\xc0\xde\x00\x01\x02\x03"),+ ("fast.o/", b"\x7fELF\x02\x01\x01\x00..__sancov_guards.."),+ ]),+ );+ assert_eq!(archive_scheme(&path), ArchiveScheme::Bitcode);+ assert!(!is_pcguard_archive(&path));+ let _ = std::fs::remove_file(path);+ }++ // The same claim with the members the other way round, because a real archive orders them+ // however the build system happened to add them and neither order may be trusted.+ #[test]+ fn one_bitcode_member_outranks_every_guard_section_ahead_of_it() {+ let path = written(+ "mixed-bc-last",+ &archive(&[+ ("fast.o/", b"\x7fELF\x02\x01\x01\x00..__sancov_guards.."),+ ("lto.o/", b"BC\xc0\xde\x00\x01\x02\x03"),+ ]),+ );+ assert_eq!(archive_scheme(&path), ArchiveScheme::Bitcode);+ assert!(!is_pcguard_archive(&path));+ let _ = std::fs::remove_file(path);+ }++ #[test]+ fn a_missing_archive_is_not_claimed_to_be_pcguard_either() {+ assert!(!is_pcguard_archive(std::path::Path::new(+ "/nonexistent/libnope.a"+ )));+ }+#[test]fn parses_edge_ids_and_discards_hit_counts() {let map = parse_showmap("000123:1\n004567:3\n065535:255\n");diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rsindex a63cb846..569e7dcd 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/verify.rs@@ -7,7 +7,7 @@ use std::time::Duration;use lisdex_core::process::{self, ProcessError};-use crate::compile::{self, BuildSpec, DEFAULT_DRIVER, LeakCheck};+use crate::compile::{self, BuildSpec, DEFAULT_DRIVER, LeakCheck, LinkScheme};use crate::coverage::{self, EdgeSet};use crate::oracle::{self, EXEC_TIMEOUT_SECS, MIN_VALID_SEEDS, Observation, Rejection, RunStatus, SeedRun,@@ -136,6 +136,20 @@ impl Default for Toolchain {}}+// B80. The bench does not get to choose its link scheme; the archives decide it. Every archive+// has to carry a numbering of its own for the harness's own instrumentation to be safely+// numbered behind it, so ONE bitcode or uninstrumented archive puts the whole link back on the+// shipped shape - where the guard in oracle 3b refuses a verdict rather than reading a+// renumbering as a coverage gain.+#[must_use]+pub fn link_scheme(archives: &[PathBuf]) -> LinkScheme {+ if !archives.is_empty() && archives.iter().all(|a| coverage::is_pcguard_archive(a)) {+ LinkScheme::PcGuard+ } else {+ LinkScheme::Lto+ }+}+impl Toolchain {#[must_use]pub fn spec(&self, source: &Path, output: &Path) -> BuildSpec {@@ -146,6 +160,7 @@ impl Toolchain {spec.archives.clone_from(&self.archives);spec.link_args.clone_from(&self.link_args);spec.driver.clone_from(&self.driver);+ spec.scheme = link_scheme(&self.archives);spec}}@@ -383,6 +398,74 @@ mod tests {assert!(corpus.invalid.is_empty());}+ // B80's remaining half. The bench does not choose its scheme; the archives do. These four+ // pin the whole decision table, because every arm of it changes what the oracles may claim.+ fn archive_of(name: &str, body: &[u8]) -> PathBuf {+ let path =+ std::env::temp_dir().join(format!("lisdex-scheme-{}-{name}.a", std::process::id()));+ let mut bytes = b"!<arch>\n".to_vec();+ bytes.extend_from_slice(format!("{:<16}", "m.o/").as_bytes());+ bytes.extend_from_slice(format!("{:<12}{:<6}{:<6}{:<8}", 0, 0, 0, 644).as_bytes());+ bytes.extend_from_slice(format!("{:<10}", body.len()).as_bytes());+ bytes.extend_from_slice(b"\x60\n");+ bytes.extend_from_slice(body);+ std::fs::write(&path, bytes).expect("fixture");+ path+ }++ #[test]+ fn an_archive_whose_numbering_is_fixed_puts_the_bench_on_the_matching_scheme() {+ let path = archive_of("pcg", b"\x7fELF\x02\x01\x01\x00..__sancov_guards..");+ assert_eq!(+ link_scheme(std::slice::from_ref(&path)),+ LinkScheme::PcGuard+ );+ let _ = std::fs::remove_file(path);+ }++ #[test]+ fn a_bitcode_archive_leaves_the_bench_on_the_shipped_scheme() {+ let path = archive_of("lto", b"BC\xc0\xde\x00\x01\x02\x03");+ assert_eq!(link_scheme(std::slice::from_ref(&path)), LinkScheme::Lto);+ let _ = std::fs::remove_file(path);+ }++ // One archive is enough to lose it. A harness numbered behind a library that is itself+ // renumbered at link is no better off than one numbered in front of it.+ #[test]+ fn one_incomparable_archive_puts_the_whole_link_back_on_the_shipped_scheme() {+ let good = archive_of("mix-pcg", b"\x7fELF\x02\x01\x01\x00..__sancov_guards..");+ let bad = archive_of("mix-lto", b"BC\xc0\xde\x00\x01\x02\x03");+ assert_eq!(+ link_scheme(&[good.clone(), bad.clone()]),+ LinkScheme::Lto,+ "a PCGUARD archive beside a bitcode one does not make the pair comparable"+ );+ let _ = std::fs::remove_file(good);+ let _ = std::fs::remove_file(bad);+ }++ // A header-only target passes no archive at all, and reordering nothing is not a scheme.+ #[test]+ fn no_archives_at_all_is_not_a_reason_to_change_compilers() {+ assert_eq!(link_scheme(&[]), LinkScheme::Lto);+ }++ #[test]+ fn the_scheme_reaches_the_build_spec_the_bench_actually_runs() {+ let path = archive_of("spec", b"\x7fELF\x02\x01\x01\x00..__sancov_guards..");+ let mut toolchain = Toolchain::default();+ toolchain.archives.push(path.clone());+ let spec = toolchain.spec(Path::new("/w/h.c"), Path::new("/w/h.bin"));+ assert_eq!(spec.scheme, LinkScheme::PcGuard);+ assert_eq!(+ compile::build_command(&spec).program,+ compile::CC_PCGUARD,+ "resolving the scheme and never passing it on would be silently inert"+ );+ let _ = std::fs::remove_file(path);+ }+#[test]fn the_toolchain_reaches_the_build_spec() {let mut toolchain = Toolchain::default();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 c1d04b80..e9632ed6 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@@ -7,9 +7,10 @@ use std::process::ExitCode;use std::time::Duration;use clap::{Parser, Subcommand};+use lisdex_build::artifact;use lisdex_build::instrument::Instrumentation;use lisdex_build::ladder::{self, BuildOptions};-use lisdex_build::layout::{BuildLayout, VARIANT_AFL};+use lisdex_build::layout::{BuildLayout, VARIANT_AFL, VARIANT_BENCH};use lisdex_build::verify::Requirements;use lisdex_core::campaign::{Campaign, CampaignId, CampaignStatus};use lisdex_core::report::SanitizerReport;@@ -89,6 +90,11 @@ struct BuildArgs {jobs: Option<usize>,#[arg(long, help = "build a cmplog-instrumented variant")]cmplog: bool,+ #[arg(+ long = "no-oracle-bench",+ help = "skip the PCGUARD archive the harness oracles compare coverage against"+ )]+ no_oracle_bench: bool,#[arg(long, help = "build in the source tree instead of copying it first")]in_place: bool,#[arg(long, help = "reuse an already acquired source tree")]@@ -431,15 +437,17 @@ fn harness(args: &HarnessArgs) -> Result<(), Box<dyn Error>> {// B80. Every number in the survivor summary that spans MORE THAN ONE harness - the novelty// figure and the union total - rests on two separately linked binaries numbering the same edge-// the same way. Against an LTO-bitcode archive they do not: measured over three real emitted-// parent/child pairs and eight seeds, the shorter sequence's map was contained in the longer-// one's in 0 of 24 cases, and renumbering can only INFLATE apparent novelty. A rejection-// therefore still stands - a harness that looks redundant even with scrambled IDs really is --// but no cross-harness TOTAL may be printed as if it were measured.+// the same way. That is the SAME question the bench asks when it picks a link scheme, so it is+// asked once and answered in one place: the scheme the bench could build under IS whether the+// resulting maps can be compared. Answering it twice is how the two drift apart.+//+// Note what this is not: it is not the absence of bitcode. An uninstrumented archive is not+// bitcode either, and against one every edge in the map belongs to the harness and moves with+// it. Renumbering can only INFLATE apparent novelty, so a rejection still stands - a harness+// that looks redundant even with scrambled IDs really is - but no cross-harness TOTAL may be+// printed as if it were measured.fn comparable_numbering(archives: &[std::path::PathBuf]) -> bool {- !archives- .iter()- .any(|archive| lisdex_harness::coverage::is_bitcode_archive(archive))+ lisdex_harness::verify::link_scheme(archives) == lisdex_harness::compile::LinkScheme::PcGuard}// `--no-verify` promotes the first candidate that plans and stops. It cannot climb: an@@ -899,9 +907,74 @@ fn build(args: &BuildArgs) -> Result<(), Box<dyn Error>> {println!(" {} {}", artifact.kind.as_str(), artifact.path.display());}+ if !args.no_oracle_bench {+ oracle_bench(&detected, &layout, args, &options);+ }+Ok(())}+// B80. The fuzzing archive is LTO, and an LTO archive is re-instrumented at every link - so two+// harnesses built against it do not number the same edge the same way and no coverage figure+// spanning both can be published. This second pass builds the SAME library with PCGUARD, whose+// guards are baked into the objects, and it is the archive `lisdex harness --archive` should be+// pointed at. It is not the fuzzing target: PCGUARD is the slower instrumentation, which is why+// both exist rather than one replacing the other.+//+// A failure here is degradation, never an error. The fuzzing artifact is already built and+// valid at this point, and a tree that will not build twice still fuzzes perfectly well - it+// only loses the cross-harness numbers, which is exactly the state that ships today.+fn oracle_bench(+ detected: &lisdex_ingest::detect::Detection,+ layout: &BuildLayout,+ args: &BuildArgs,+ options: &BuildOptions,+) {+ let instrumentation = Instrumentation::oracle_bench().with_extra_cflags(args.cflags.clone());+ let options = BuildOptions::new(VARIANT_BENCH, options.jobs)+ .with_requirements(Requirements::library().with_magma_canaries(args.require_canaries));+ let outcome = match ladder::build(detected, layout, &instrumentation, &options) {+ Ok(outcome) => outcome,+ Err(error) => {+ eprintln!("degraded: no oracle-bench archive: {error}");+ return;+ }+ };+ if !outcome.succeeded() {+ eprintln!(+ "degraded: no oracle-bench archive; {} attempt(s) failed, so cross-harness \+ coverage numbers stay unpublishable",+ outcome.attempts.len()+ );+ return;+ }+ // Reported by the property rather than by the variant name, because "the bench pass ran"+ // and "the bench pass produced something the oracles can compare" are different claims and+ // only the second one is worth printing. A shared library is not an archive `--archive`+ // takes, and an archive with no guard sections of its own is the state this pass exists to+ // avoid - so both are counted out here rather than discovered later by the guard.+ let comparable: Vec<&artifact::Artifact> = outcome+ .artifacts+ .iter()+ .filter(|found| found.kind == artifact::ArtifactKind::StaticLib)+ .filter(|found| lisdex_harness::coverage::is_pcguard_archive(&found.path))+ .collect();+ if comparable.is_empty() {+ eprintln!(+ "degraded: the oracle-bench pass built, but no archive it produced carries a \+ numbering of its own, so cross-harness coverage numbers stay unpublishable"+ );+ return;+ }+ println!(+ "oracle bench: {} archive(s) with a numbering fixed at library-build time",+ comparable.len()+ );+ for library in &comparable {+ println!(" {} {}", library.kind.as_str(), library.path.display());+ }+}+fn fuzz(args: &FuzzArgs) -> Result<(), Box<dyn Error>> {let label = args.label.clone().unwrap_or_else(|| {args.targetdiff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.shindex a058b245..8ec2d7ac 100755--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh@@ -780,18 +780,34 @@ log "stage 13/14: a library-filled out-param compiles and runs against the real# clean on every seed. Reaching oracle 3b at all is the proof, because 3b sits behind compilation,# execution and inter-seed divergence - a declaration that did not compile never gets here.#-# The VERDICT is deliberately not asserted, and that is B80 rather than caution. Both outcomes-# below mean the same thing about B81; which one appears is decided by whether this particular-# relink renumbered the harness TU's own edges, and D33 measured that as unpredictable across two-# trees over one library. Asserting acceptance would make this stage a coin flip on link order.-# When B80 lands - the map holding only the library's fixed edges - this becomes an acceptance.+# The VERDICT is asserted here now, and B80's remaining half is what earns it. This stage used+# to accept either outcome because whether 3b could judge the relink at all depended on the+# numbering, which was a coin flip: the lab archive is PCGUARD but the harness was compiled by+# afl-clang-lto and linked ahead of the library, and either mismatch renumbers everything+# underneath. With the bench matching the archive's scheme AND linking the library first, the+# parent's map is contained in the child's on every seed, so an acceptance is a judgement rather+# than a link-order accident.lab_run entry-if grep -qE 'extended by 1 author call\(s\): mylib_next_entry|appending mylib_next_entry' \- "$LAB/entry.log" && ! grep -q 'does not compile' "$LAB/entry.log"; then- pass "a step whose out-param the library fills compiles and runs against the real header"+if grep -q 'extended by 1 author call(s): mylib_next_entry' "$LAB/entry.log"; then+ pass "a step whose out-param the library fills is ACCEPTED by oracle 3b, verdict and all"elsetail -6 "$LAB/entry.log" >&2- fail "the library-filled extension never reached the oracle that judges it"+ fail "the library-filled extension was not accepted by the oracle that judges it"+fi+# The isolating control for that verdict, and the reason it is a measurement rather than a+# tautology: the SAME tree, the SAME seeds, the SAME candidate, against the LTO build of the+# SAME library. Nothing about the harness changed, so if this one were also accepted the pass+# above would be telling us nothing about the numbering. Gut either the compiler switch or the+# link order and the two stop disagreeing.+"$LISDEX_BIN" harness "$LAB/entry" --out "$LAB/out-entry-lto" --top 6 \+ --seeds "$LAB/seeds" --archive "$LAB/lib/libmylib_lto.a" --driver "$DRIVER" \+ >"$LAB/entry-lto.log" 2>&1+if grep -q 'do not describe the same numbering' "$LAB/entry-lto.log" \+ && ! grep -q 'extended by 1 author call(s): mylib_next_entry' "$LAB/entry-lto.log"; then+ pass "and the same candidate against the LTO build of that library is refused, not accepted"+else+ tail -6 "$LAB/entry-lto.log" >&2+ fail "the acceptance above did not depend on the archive's numbering, so it proves nothing"fi# The declaration is the harness's own, and LSAN is what proves the ownership line is drawn in# the right place: the entry belongs to the library, so nothing here frees it.@@ -822,28 +838,22 @@ log "stage 14/14: a macro-stated capacity is allocated, is the right size, and i# byte MYLIB_IMAGE_SIZE claims, so a buffer even one byte short is a heap-buffer-overflow here# rather than in a real target.#-# The VERDICT is deliberately not asserted, for the same reason stage 13 does not assert one:-# whether oracle 3b can judge the relink is B80's remaining half, not B82's.+# The VERDICT is asserted here now, for the same reason stage 13 asserts one: B80's remaining+# half fixed the library's numbering, so 3b can judge this relink instead of refusing it.+#+# This one assertion carries what two used to. Acceptance sits behind compilation, execution+# and inter-seed divergence, so it is also the size claim this stage exists for: `mylib_finish_+# read` writes every byte `MYLIB_IMAGE_SIZE` promises, and a buffer one byte short is a+# heap-buffer-overflow, a missing free is a LeakSanitizer report and a missing NULL guard is a+# memset through NULL - each one an execution-oracle rejection, and none of them reaches an+# acceptance. The separate `crashed on seed` grep that used to make that claim is gone because+# it could no longer go red on its own, which is the inert-rule case doc 02 says to delete.lab_run sized-if grep -qE 'extended by 1 author call\(s\): mylib_finish_read|appending mylib_finish_read' \- "$LAB/sized.log" && ! grep -q 'does not compile' "$LAB/sized.log"; then- pass "a buffer sized by the header's own macro compiles and runs against the real header"-else- tail -6 "$LAB/sized.log" >&2- fail "the macro-sized extension never reached the oracle that judges it"-fi-# The size itself, which is the assertion this whole stage exists for, and the phrasing is the-# result of a gutting pass rather than a guess: a first version grepped the log for-# `AddressSanitizer`, and lisdex does not print that - it reports "crashed on seed X" - so the-# assertion stayed green with the guard gutted AND with the free gutted. `crashed` is the word-# that moves. An under-allocated buffer is a heap-buffer-overflow, a missing free is a-# LeakSanitizer report, and a missing NULL guard is a memset through NULL; all three arrive here.-if grep -q 'appending mylib_finish_read' "$LAB/sized.log" \- && ! grep -q 'appending mylib_finish_read - crashed on seed' "$LAB/sized.log"; then- pass "and every byte the library claimed was writable and released, on every seed"-else- grep -m2 'appending mylib_finish_read' "$LAB/sized.log" >&2- fail "the macro-sized buffer did not survive execution against the real library"+if grep -q 'extended by 1 author call(s): mylib_finish_read' "$LAB/sized.log"; then+ pass "a buffer sized by the header's own macro is ACCEPTED, so every byte it claimed was writable"+else+ grep -m2 'mylib_finish_read' "$LAB/sized.log" >&2+ fail "the macro-sized extension was not accepted by the oracle that judges it"fi# The EXTENDED candidate by name, never `find | head -1`: the candidates directory also holds# the two unextended variants, and reading one of those would assert nothing about the climb.