Skip to content

Commit

Permalink
Run ubpf_test over every file in corpus
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
  • Loading branch information
Alan-Jowett committed May 14, 2024
1 parent 3fb3da0 commit 66bab78
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ jobs:
--build build \
--target test
- name: Run ubpf_test over each file in fuzz corpus
run: |
wget https://github.com/iovisor/ubpf/archive/refs/heads/fuzz/corpus.zip
unzip corpus.zip
for file in ubpf-fuzz-corpus/fuzz/corpus/*; do
path=$(dirname $file)
name=$(basename $file)
libfuzzer/split.sh $file
echo build/bin/ubpf_test --mem $path/memory-$name $path/program-$name
echo build/bin/ubpf_test --mem $path/memory-$name $path/program-$name --jit
done
- name: Generate code coverage report
if: inputs.enable_coverage == true && inputs.platform == 'macos-11'
run: |
Expand Down
37 changes: 37 additions & 0 deletions libfuzzer/split.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Split the file name into path and base name
path=$(dirname $1)
base=$(basename $1)

# Get the first 4 bytes from the file (which is the length of the program)
input="$(xxd -p -l 4 $1)"
# Convert from little endian
input="${input:6:2}${input:4:2}${input:2:2}${input:0:2}"

# Convert input from hex string to value
length=$((16#$input))

# Extract the hash part from the file name
hash=$(echo $base | cut -d'-' -f2-)

# Copy the program to a file named program-$hash
echo "Extracting program-$hash..."
dd if=$1 of=$path/program-$hash bs=1 skip=4 count=$length 2> /dev/null

echo "Extracting memory-$hash..."
# Copy the rest to a file named memory-$hash
dd if=$1 of=$path/memory-$hash bs=1 skip=$((4 + $length)) 2> /dev/null

echo "Disassembling program-$hash..."
# Unassembly program using bin/ubpf-disassembler
bin/ubpf-disassembler $path/program-$hash > $path/program-$hash.asm

echo "Program size: $(stat -c %s $path/program-$hash)"
echo "Memory size: $(stat -c %s $path/memory-$hash)"

echo "Disassembled program:"
cat $path/program-$hash.asm

echo "Memory contents:"
xxd $path/memory-$hash

0 comments on commit 66bab78

Please sign in to comment.