about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2024-01-30 15:06:34 +0100
committervanhauser-thc <vh@thc.org>2024-01-30 15:06:34 +0100
commit9604fe922ede9282a06a89b8d18d4de267aebd54 (patch)
tree0c6f0a940ee546e711e43d539471b9c423ba405a
parentd5b6c0f773178eb8890d0e7004c3c6d4931687fa (diff)
downloadafl++-9604fe922ede9282a06a89b8d18d4de267aebd54.tar.gz
nyx test for CI
-rw-r--r--src/afl-fuzz-init.c6
-rw-r--r--src/afl-fuzz.c9
-rwxr-xr-xtest/test-all.sh2
-rwxr-xr-xtest/test-nyx-mode.sh69
-rwxr-xr-xtest/test-pre.sh2
5 files changed, 87 insertions, 1 deletions
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 35932913..8ab44a3b 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -124,6 +124,9 @@ void bind_to_free_cpu(afl_state_t *afl) {
     }
 
     WARNF("Not binding to a CPU core (AFL_NO_AFFINITY set).");
+  #ifdef __linux__
+    if (afl->fsrv.nyx_mode) { afl->fsrv.nyx_bind_cpu_id = 0; }
+  #endif
     return;
 
   }
@@ -151,6 +154,9 @@ void bind_to_free_cpu(afl_state_t *afl) {
     } else {
 
       OKF("CPU binding request using -b %d successful.", afl->cpu_to_bind);
+  #ifdef __linux__
+      if (afl->fsrv.nyx_mode) { afl->fsrv.nyx_bind_cpu_id = afl->cpu_to_bind; }
+  #endif
 
     }
 
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 5aec072e..8cf6c735 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -1915,6 +1915,15 @@ int main(int argc, char **argv_orig, char **envp) {
   bind_to_free_cpu(afl);
   #endif                                                   /* HAVE_AFFINITY */
 
+  #ifdef __linux__
+  if (afl->fsrv.nyx_mode && afl->fsrv.nyx_bind_cpu_id == 0xFFFFFFFF) {
+
+    afl->fsrv.nyx_bind_cpu_id = 0;
+
+  }
+
+  #endif
+
   #ifdef __HAIKU__
   /* Prioritizes performance over power saving */
   set_scheduler_mode(SCHEDULER_MODE_LOW_LATENCY);
diff --git a/test/test-all.sh b/test/test-all.sh
index 3cb692ca..65cfb812 100755
--- a/test/test-all.sh
+++ b/test/test-all.sh
@@ -16,6 +16,8 @@
 
 . ./test-frida-mode.sh
 
+. ./test-nyx-mode.sh
+
 . ./test-unicorn-mode.sh
 
 . ./test-custom-mutators.sh
diff --git a/test/test-nyx-mode.sh b/test/test-nyx-mode.sh
new file mode 100755
index 00000000..913a6d07
--- /dev/null
+++ b/test/test-nyx-mode.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+. ./test-pre.sh
+
+$ECHO "$BLUE[*] Testing: nyx_mode"
+
+test -e ../libnyx.so && {
+  ../afl-cc -o test-instr ../test-instr.c >/dev/null 2>&1
+  test -e test-instr && {
+    {
+      rm -rf nyx-test in out
+      $ECHO "$GREY[*] running nyx_packer"
+      python3 ../nyx_mode/packer/packer/nyx_packer.py \
+        ./test-instr \
+        nyx-test \
+        afl \
+        instrumentation \
+        --fast_reload_mode \
+        --purge > /dev/null 2>&1
+
+      test -e nyx-test/test-instr && {
+
+        $ECHO "$GREY[*] running nyx_config_gen"
+        python3 ../nyx_mode/packer/packer/nyx_config_gen.py nyx-test Kernel > /dev/null 2>&1
+        
+        test -e nyx-test/config.ron && {
+          sudo modprobe -r kvm-intel
+          sudo modprobe -r kvm
+          sudo modprobe  kvm enable_vmware_backdoor=y
+          sudo modprobe  kvm-intel
+          #cat /sys/module/kvm/parameters/enable_vmware_backdoor 
+
+          mkdir -p in
+          echo 00000 > in/in
+          $ECHO "$GREY[*] running afl-fuzz for nyx_mode, this will take approx 10 seconds"
+          {
+            AFL_DEBUG=1 ../afl-fuzz -i in -o out -V05 -X -- ./nyx-test >>errors 2>&1
+          } >>errors 2>&1
+          test -n "$( ls out/default/queue/id:000002* 2>/dev/null )" && {
+            $ECHO "$GREEN[+] afl-fuzz is working correctly with nyx_mode"
+            RUNTIME=`grep execs_done out/default/fuzzer_stats | awk '{print$3}'`
+            rm -rf errors nyx-test test-instr in out
+          } || {
+            echo CUT------------------------------------------------------------------CUT
+            cat errors
+            echo CUT------------------------------------------------------------------CUT
+            $ECHO "$RED[!] afl-fuzz is not working correctly with nyx_mode"
+            CODE=1
+          }
+        } || {
+          $ECHO "$RED[!] nyx_packer failed, likely install requirements not met."
+          CODE=1
+        }
+      } || {
+       $ECHO "$RED[!] nyx_packer failed, likely install requirements not met."
+       CODE=1
+      }
+      #rm -rf test-instr in out errors nyx-test
+    }
+  } || {
+    $ECHO "$RED[!] afl-cc compilation of test targets failed - what is going on??"
+    CODE=1
+  }
+} || {
+  $ECHO "$YELLOW[-] nyx_mode is not compiled, cannot test"
+  INCOMPLETE=1
+}
+
+. ./test-post.sh
diff --git a/test/test-pre.sh b/test/test-pre.sh
index 1ca9dfb5..ce996415 100755
--- a/test/test-pre.sh
+++ b/test/test-pre.sh
@@ -20,7 +20,7 @@ echo foobar | grep -qE 'asd|oob' 2>/dev/null || { echo Error: grep command does
 test -e ./test-all.sh || cd $(dirname $0) || exit 1
 test -e ./test-all.sh || { echo Error: you must be in the test/ directory ; exit 1 ; }
 export AFL_PATH=`pwd`/..
-export AFL_NO_AFFINITY=1 # workaround for travis that fails for no avail cores 
+export AFL_TRY_AFFINITY=1 # workaround for travis that fails for no avail cores
 
 echo 1 > test.1
 echo 1 > test.2