diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml new file mode 100644 index 0000000..b8835cb --- /dev/null +++ b/.github/workflows/rust-clippy.yml @@ -0,0 +1,54 @@ +--- +name: rust-clippy analyze +on: + push: + branches: + - main + pull_request: + types: + - opened + - reopened + - ready_for_review + - edited + branches: + - main + schedule: + - cron: '5 * * * *' +jobs: + rust-clippy-analyze: + name: Run rust-clippy analyzing + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + actions: read + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Submodules + run: git submodule update --init + - name: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy + override: true + - name: rust-cargo + uses: actions-rs/cargo@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + - name: Install required cargo + run: cargo install clippy-sarif sarif-fmt + - name: Run rust-clippy + run: cargo clippy --all-features --message-format=json | clippy-sarif | tee + rust-clippy-results.sarif | sarif-fmt + continue-on-error: true + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: rust-clippy-results.sarif + wait-for-processing: true + diff --git a/fuzzers/secworks-vcs/Cargo.toml b/fuzzers/secworks-vcs/Cargo.toml index 1be23be..d596e14 100644 --- a/fuzzers/secworks-vcs/Cargo.toml +++ b/fuzzers/secworks-vcs/Cargo.toml @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 [package] -name = "baby-rtl-fuzzer" +name = "secworks-vcs" version = "0.0.1" authors = ["Nassim Corteggiani "] edition = "2021" diff --git a/fuzzers/secworks-vcs/build.rs b/fuzzers/secworks-vcs/build.rs index 783bb8e..a873546 100644 --- a/fuzzers/secworks-vcs/build.rs +++ b/fuzzers/secworks-vcs/build.rs @@ -3,22 +3,77 @@ // SPDX-License-Identifier: Apache-2.0 use std::process::Command; +use std::path::PathBuf; +use std::fs::OpenOptions; +use std::io::prelude::*; fn main() { - let args = "fusesoc library add sha256 https://github.com/secworks/sha256"; - let args = args.split(' '); + let rtl_dir = PathBuf::from("./fusesoc_libraries/sha256"); + + if !rtl_dir.exists() { + + assert!(Command::new("fusesoc") + .arg("library") + .arg("add") + .arg("sha256") + .arg("https://github.com/secworks/sha256") + .status() + .unwrap() + .success()); + + assert!(Command::new("cp") + .arg("./tb_fuzz.sv") + .arg("./fusesoc_libraries/sha256/src/tb/") + .status() + .unwrap() + .success()); + + let mut file = OpenOptions::new() + .write(true) + .append(true) + .open("fusesoc_libraries/sha256/sha256.core") + .unwrap(); + + if let Err(e) = writeln!(file, " tb_fuzz:") { + eprintln!("Couldn't write to file: {}", e); + } + + if let Err(e) = writeln!(file, " <<: *tb") { + eprintln!("Couldn't write to file: {}", e); + } + + if let Err(e) = writeln!(file, " toplevel : tb_fuzz") { + eprintln!("Couldn't write to file: {}", e); + } + + assert!(Command::new("sed") + .arg("-i") + .arg("s|- src/tb/tb_sha256.v|- src/tb/tb_fuzz.sv|g") + .arg("fusesoc_libraries/sha256/sha256.core") + .status() + .unwrap() + .success()); + } - Command::new("fusesoc") - .args(args) - .output() - .expect("failed to execute process"); - let args = "fusesoc run --target=tb_fuzz --tool=vcs secworks:crypto:sha256 --vcs_options '-LDFLAGS -Wl,--no-as-needed -cm line+fsm+cond+tgl+branch -cm_dir Coverage.vdb -full64 -sverilog' --run_options '+TESTCASE=/home/nasm/Projects/HW_Fuzzing/research.security.fuzzing.hardware-fuzzing/fuzzers/baby-rtl-fuzzer/fuzz_inputs.hex -cm tgl'"; - let args = args.split(' '); + assert!(Command::new("fusesoc") + .arg("run") + .arg("--build") + .arg("--target=tb_fuzz") + .arg("--tool=vcs") + .arg("secworks:crypto:sha256") + .arg("--vcs_options") + .arg("-LDFLAGS -Wl,--no-as-needed -cm line+fsm+cond+tgl+branch -cm_dir Coverage.vdb -full64 -sverilog") + .status() + .unwrap() + .success()); - Command::new("fusesoc") - .args(args) - .output() - .expect("failed to execute process"); + // let args = "fusesoc run --target=tb_fuzz --tool=vcs secworks:crypto:sha256 --vcs_options '-LDFLAGS -Wl,--no-as-needed -cm line+fsm+cond+tgl+branch -cm_dir Coverage.vdb -full64 -sverilog' --run_options '+TESTCASE=/home/nasm/Projects/HW_Fuzzing/research.security.fuzzing.hardware-fuzzing/fuzzers/baby-rtl-fuzzer/fuzz_inputs.hex -cm tgl'"; + // let args = args.split(' '); +// + // Command::new("fusesoc") + // .args(args) + // .output() + // .expect("failed to execute process"); } diff --git a/fuzzers/secworks-vcs/init.sh b/fuzzers/secworks-vcs/init.sh deleted file mode 100644 index 4d2c66c..0000000 --- a/fuzzers/secworks-vcs/init.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -# SPDX-FileCopyrightText: 2022 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -#cargo clean - -#rm -rf build -#rm -rf fusesoc* -#rm -rf template -#rm -rf output -#rm -rf backup_* - -#fusesoc library add sha256 https://github.com/secworks/sha256 - -#cp ./tb_fuzz.sv ./fusesoc_libraries/sha256/src/tb/ - -#echo " tb_fuzz:" >> fusesoc_libraries/sha256/sha256.core -#echo " <<: *tb" >> fusesoc_libraries/sha256/sha256.core -#echo " toplevel : tb_fuzz" >> fusesoc_libraries/sha256/sha256.core -#sed -i '/tb_sha256.v/a \ \ \ \ \ \ - src\/tb\/tb_fuzz.sv' fusesoc_libraries/sha256/sha256.core - -#fusesoc run --build --target=tb_fuzz --tool=vcs secworks:crypto:sha256 --vcs_options '-LDFLAGS -Wl,--no-as-needed -cm line+fsm+cond+tgl+branch -cm_dir Coverage.vdb -full64 -sverilog' - -#cargo build - -#mkdir output -#cp -r build/secworks_crypto_sha256_0/tb_fuzz-vcs/* ./output - -#crg -dir ./output/Coverage.vdb -shared init - -export HW_HOME=$(pwd) - -mkdir $HW_HOME/seeds/ - -./target/debug/baby-rtl-fuzzer $HW_HOME/output/secworks_crypto_sha256_0 \ - $HW_HOME/seeds/ \ - $HW_HOME/output/Coverage.vdb \ - $HW_HOME/output/ "+TESTCASE=fuzz_input.hex -cm tgl" diff --git a/fuzzers/secworks-vcs/src/main.rs b/fuzzers/secworks-vcs/src/main.rs index 18b1fea..369b52f 100644 --- a/fuzzers/secworks-vcs/src/main.rs +++ b/fuzzers/secworks-vcs/src/main.rs @@ -200,7 +200,7 @@ pub fn main() { let (mut feedback, verdi_observer) = { let outdir = res.value_of("outdir").unwrap().to_string(); - let verdi_observer = unsafe{VerdiShMapObserver::<{MAP_SIZE/4}>::from_mut_ptr("verdi_map", &outdir, shmem_ptr, &VerdiCoverageMetric::Toggle)}; + let verdi_observer = unsafe{VerdiShMapObserver::<{MAP_SIZE/4}>::from_mut_ptr("verdi_map", &outdir, shmem_ptr, &VerdiCoverageMetric::Toggle, &"".to_string())}; let feedback = VerdiFeedback::<{MAP_SIZE/4}>::new_with_observer("verdi_map", MAP_SIZE, &outdir); // let feedback = MaxMapFeedback::new(&verdi_observer); diff --git a/fuzzers/secworks-vcs/tb_fuzz.sv b/fuzzers/secworks-vcs/tb_fuzz.sv index fd43eae..906a432 100644 --- a/fuzzers/secworks-vcs/tb_fuzz.sv +++ b/fuzzers/secworks-vcs/tb_fuzz.sv @@ -40,10 +40,11 @@ module tb_fuzz(); - string test_case; parameter WIDTH = 32; + int fd; int status; + string test_case; //---------------------------------------------------------------- // Internal constant and parameter definitions.