Skip to contentSkip to conversation

fuzz: add oss-fuzz build.sh script

PATCH Superseded Alexander Bulekov 3 participants 6 messages Jun 5, 2020 – Jun 8, 2020

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuzz: add oss-fuzz build.sh script

It is neater to keep this in the QEMU repo, since any change that requires an update to the oss-fuzz build configuration, can make the necessary changes in the same series.

---
 scripts/oss-fuzz/build.sh | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 scripts/oss-fuzz/build.sh
scripts/oss-fuzz/build.sh new file +47 -0
new file mode 100755
index 0000000000..7be6dcce4c
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+# build project
+# e.g.
+# ./autogen.sh
+# ./configure
+# make -j$(nproc) all
+
+# build fuzzers
+# e.g.
+# $CXX $CXXFLAGS -std=c++11 -Iinclude \
+#     /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \
+#     $LIB_FUZZING_ENGINE /path/to/library.a
+
+mkdir -p $OUT/lib/              # Shared libraries
+
+# Build once to get the list of dynamic lib paths, and copy them over
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__ "
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+for i in $(ldd ./i386-softmmu/qemu-fuzz-i386  | cut -f3 -d' '); do 
+    cp $i $OUT/lib/
+done
+rm ./i386-softmmu/qemu-fuzz-i386
+
+# Build a second time to build the final binary with correct rpath
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__" \
+    --extra-ldflags="-Wl,-rpath,'\$\$ORIGIN/lib'"
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+# Copy over the datadir
+cp  -r ./pc-bios/ $OUT/pc-bios
+
+# Copy over the qemu-fuzz-i386, naming it according to each available fuzz
+# target (See 05509c8e6d fuzz: select fuzz target using executable name)
+for target in $(./i386-softmmu/qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}');
+do
+    cp ./i386-softmmu/qemu-fuzz-i386 $OUT/qemu-fuzz-i386-target-$target
+done
Signature · 1 line
2.26.2
#1 lore raw
Quoted 17 lines · Alexander Bulekov

It is neater to keep this in the QEMU repo, since any change that requires an update to the oss-fuzz build configuration, can make the necessary changes in the same series.

---
 scripts/oss-fuzz/build.sh | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 scripts/oss-fuzz/build.sh
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..7be6dcce4c

scripts/oss-fuzz/build.sh line 3

Quoted 3 lines
scripts/oss-fuzz/build.sh new file +3 -0
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h

This is obviously wrong... Sending v2.

Quoted 47 lines
scripts/oss-fuzz/build.sh new file +44 -0
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+# build project
+# e.g.
+# ./autogen.sh
+# ./configure
+# make -j$(nproc) all
+
+# build fuzzers
+# e.g.
+# $CXX $CXXFLAGS -std=c++11 -Iinclude \
+#     /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \
+#     $LIB_FUZZING_ENGINE /path/to/library.a
+
+mkdir -p $OUT/lib/              # Shared libraries
+
+# Build once to get the list of dynamic lib paths, and copy them over
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__ "
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+for i in $(ldd ./i386-softmmu/qemu-fuzz-i386  | cut -f3 -d' '); do 
+    cp $i $OUT/lib/
+done
+rm ./i386-softmmu/qemu-fuzz-i386
+
+# Build a second time to build the final binary with correct rpath
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__" \
+    --extra-ldflags="-Wl,-rpath,'\$\$ORIGIN/lib'"
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+# Copy over the datadir
+cp  -r ./pc-bios/ $OUT/pc-bios
+
+# Copy over the qemu-fuzz-i386, naming it according to each available fuzz
+# target (See 05509c8e6d fuzz: select fuzz target using executable name)
+for target in $(./i386-softmmu/qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}');
+do
+    cp ./i386-softmmu/qemu-fuzz-i386 $OUT/qemu-fuzz-i386-target-$target
+done
Signature · 1 line
2.26.2
#2 lore raw
In reply to Alexander Bulekov
Quoted 5 lines · Alexander Bulekov

It is neater to keep this in the QEMU repo, since any change that requires an update to the oss-fuzz build configuration, can make the necessary changes in the same series.

'Philippe Mathieu-Daudé' ;)

Quoted 12 lines
---
 scripts/oss-fuzz/build.sh | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 scripts/oss-fuzz/build.sh
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..7be6dcce4c

scripts/oss-fuzz/build.sh line 3

Quoted 3 lines
scripts/oss-fuzz/build.sh new file +3 -0
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h

Hmmm?

scripts/oss-fuzz/build.sh line 9

Quoted 6 lines
scripts/oss-fuzz/build.sh new file +6 -0
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+# build project

Please mention this file use consumed by
https://github.com/google/oss-fuzz/.../projects/qemu/Dockerfile

scripts/oss-fuzz/build.sh line 21

Quoted 12 lines
scripts/oss-fuzz/build.sh new file +12 -0
+# e.g.
+# ./autogen.sh
+# ./configure
+# make -j$(nproc) all
+
+# build fuzzers
+# e.g.
+# $CXX $CXXFLAGS -std=c++11 -Iinclude \
+#     /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \
+#     $LIB_FUZZING_ENGINE /path/to/library.a
+
+mkdir -p $OUT/lib/              # Shared libraries

Maybe rename OUT -> DEST_DIR?

scripts/oss-fuzz/build.sh line 25

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+
+# Build once to get the list of dynamic lib paths, and copy them over
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__ "

So we use an in-tree build.

Still we could set some SRCDIR=./

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+for i in $(ldd ./i386-softmmu/qemu-fuzz-i386  | cut -f3 -d' '); do 
+    cp $i $OUT/lib/
+done

scripts/oss-fuzz/build.sh line 40

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+rm ./i386-softmmu/qemu-fuzz-i386
+
+# Build a second time to build the final binary with correct rpath
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__" \
+    --extra-ldflags="-Wl,-rpath,'\$\$ORIGIN/lib'"
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+# Copy over the datadir
+cp  -r ./pc-bios/ $OUT/pc-bios

"make install-datadir"?

scripts/oss-fuzz/build.sh line 46

Quoted 6 lines
scripts/oss-fuzz/build.sh new file +6 -0
+
+# Copy over the qemu-fuzz-i386, naming it according to each available fuzz
+# target (See 05509c8e6d fuzz: select fuzz target using executable name)
+for target in $(./i386-softmmu/qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}');
+do
+    cp ./i386-softmmu/qemu-fuzz-i386 $OUT/qemu-fuzz-i386-target-$target

There seems to be an extra 'target'.

scripts/oss-fuzz/build.sh line 47

Quoted 2 lines
scripts/oss-fuzz/build.sh new file +1 -0
+done

Or "make install", not sure.

#3 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Alexander Bulekov

It is neater to keep this in the QEMU repo, since any change that requires an update to the oss-fuzz build configuration, can make the necessary changes in the same series.

'Philippe Mathieu-Daudé' ;)

Oops - Sorry.

Quoted 7 lines
Quoted 7 lines
---
 scripts/oss-fuzz/build.sh | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 scripts/oss-fuzz/build.sh
Quoted 11 lines

scripts/oss-fuzz/build.sh line 3

Quoted 9 lines
scripts/oss-fuzz/build.sh new file +3 -0
new file mode 100755
index 0000000000..7be6dcce4c
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h

Hmmm?

Fixed in v2.

Quoted 11 lines

scripts/oss-fuzz/build.sh line 9

Quoted 7 lines
scripts/oss-fuzz/build.sh new file +6 -0
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+# build project

Please mention this file use consumed by
https://github.com/google/oss-fuzz/.../projects/qemu/Dockerfile

Quoted 14 lines

scripts/oss-fuzz/build.sh line 21

Quoted 12 lines
scripts/oss-fuzz/build.sh new file +12 -0
+# e.g.
+# ./autogen.sh
+# ./configure
+# make -j$(nproc) all
+
+# build fuzzers
+# e.g.
+# $CXX $CXXFLAGS -std=c++11 -Iinclude \
+#     /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \
+#     $LIB_FUZZING_ENGINE /path/to/library.a
+
+mkdir -p $OUT/lib/              # Shared libraries

Maybe rename OUT -> DEST_DIR?

$OUT is something specified by OSS-Fuzz, when it runs the script in docker. If its better, I can do DEST_DIR=$OUT

Quoted 8 lines

scripts/oss-fuzz/build.sh line 25

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+
+# Build once to get the list of dynamic lib paths, and copy them over
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__ "

So we use an in-tree build.

Still we could set some SRCDIR=./

I can change it to build in ./build/ or even an out-of-tree build, if thats neater..

Quoted 10 lines
Quoted 10 lines
scripts/oss-fuzz/build.sh new file +9 -0
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+for i in $(ldd ./i386-softmmu/qemu-fuzz-i386  | cut -f3 -d' '); do 
+    cp $i $OUT/lib/
+done
+rm ./i386-softmmu/qemu-fuzz-i386
+
+# Build a second time to build the final binary with correct rpath
+./configure --datadir="./data/" --disable-werror --cc="$CC" --cxx="$CXX" \
Quoted 8 lines

scripts/oss-fuzz/build.sh line 40

Quoted 6 lines
scripts/oss-fuzz/build.sh new file +6 -0
+    --extra-cflags="$CFLAGS -U __OPTIMIZE__" \
+    --extra-ldflags="-Wl,-rpath,'\$\$ORIGIN/lib'"
+make CONFIG_FUZZ=y CFLAGS="$LIB_FUZZING_ENGINE" -j$(nproc) i386-softmmu/fuzz
+
+# Copy over the datadir
+cp  -r ./pc-bios/ $OUT/pc-bios

"make install-datadir"?

With something like: ./configure --datadir="$OUT/pc-bios/" Ok.

Quoted 9 lines

scripts/oss-fuzz/build.sh line 46

Quoted 7 lines
scripts/oss-fuzz/build.sh new file +6 -0
+
+# Copy over the qemu-fuzz-i386, naming it according to each available fuzz
+# target (See 05509c8e6d fuzz: select fuzz target using executable name)
+for target in $(./i386-softmmu/qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}');
+do
+    cp ./i386-softmmu/qemu-fuzz-i386 $OUT/qemu-fuzz-i386-target-$target

There seems to be an extra 'target'.

I don't think so, unless i'm missing something.
We do a strstr(argv[0], "-target-") in fuzz.c The
targets need to be named:
qemu-fuzz-i386-target-virtio-net-socket
qemu-fuzz-i386-target-i440fx-qos-fork-fuzz
etc..

Thanks
-Alex

Quoted 4 lines

scripts/oss-fuzz/build.sh line 47

Quoted 2 lines
scripts/oss-fuzz/build.sh new file +1 -0
+done

Or "make install", not sure.

#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 1 line · Philippe Mathieu-Daudé

On 6/5/20 7:40 PM, Alexander Bulekov wrote:

-cut-

Quoted 1 line

"make install-datadir"?

I think this just sets up the datadir for subsequent copies:

install-datadir:

    $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"

The actual copy happens in install:

install: all $(if $(BUILD_DOCS),install-doc) \
install-datadir install-localstatedir install-includedir
...
ifneq ($(BLOBS),)

	set -e; for x in $(BLOBS); do \
		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
	done

...

Quoted 10 lines

scripts/oss-fuzz/build.sh line 46

Quoted 7 lines
scripts/oss-fuzz/build.sh new file +6 -0
+
+# Copy over the qemu-fuzz-i386, naming it according to each available fuzz
+# target (See 05509c8e6d fuzz: select fuzz target using executable name)
+for target in $(./i386-softmmu/qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}');
+do
+    cp ./i386-softmmu/qemu-fuzz-i386 $OUT/qemu-fuzz-i386-target-$target

There seems to be an extra 'target'.

Quoted 4 lines
Quoted 2 lines

+done

Or "make install", not sure.

If I can get this to work, hopefully it will also take care of the datadir.
Thanks
-Alex

#5 lore raw
In reply to Alexander Bulekov
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [PATCH] fuzz: add oss-fuzz build.sh script
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
8109a86 fuzz: add oss-fuzz build.sh script

=== OUTPUT BEGIN ===
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100755

ERROR: trailing whitespace
#48: FILE: scripts/oss-fuzz/build.sh:28:
+for i in $(ldd ./i386-softmmu/qemu-fuzz-i386 | cut -f3 -d' '); do $

total: 1 errors, 1 warnings, 47 lines checked

Commit 8109a8627d68 (fuzz: add oss-fuzz build.sh script) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]