Skip to contentSkip to conversation

fuzz: broken build fixes

PATCH In review Alexander Bulekov 4 participants 12 messages Jul 8, 2020 – Jul 9, 2020

lore
Share & tools
lore
#0 lore raw

cover fuzz: broken build fixes

Hi,
These fix build-breaking problems with --enable-fuzzing The first patch prevents --enable-fuzzing from overwriting CFLAGS. The second patch adds a missing header to fuzz.c
-Alex

Alexander Bulekov (2):
configure: do not clobber CFLAGS with --enable-fuzzing
fuzz: add missing header for rcu_enable_atfork

 configure               | 2 +-
 tests/qtest/fuzz/fuzz.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 configure: do not clobber CFLAGS with --enable-fuzzing

When configuring with --enable-fuzzing, we overwrote the CFLAGS added by all the preceding checks. Instead of overwriting CFLAGS, append the ones we need.

Fixes adc28027ff ("fuzz: add configure flag --enable-fuzzing")
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
index ee6c3c6792..078ebaa9f3 100755
@@ -7898,7 +7898,7 @@ if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
     FUZZ_CFLAGS=" -fsanitize=address,fuzzer"
-    CFLAGS=" -fsanitize=address,fuzzer-no-link"
+    CFLAGS="$CFLAGS -fsanitize=address,fuzzer-no-link"
   else
     error_exit "Your compiler doesn't support -fsanitize=address,fuzzer"
     exit 1
Signature · 1 line
2.26.2
Tested-by Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH-for-5.1 1/2] configure: do not clobber CFLAGS with --enable-fuzzing

Quoted 8 lines · Alexander Bulekov <[email protected]> 于2020年7月9日周四 上午4:02写道:

When configuring with --enable-fuzzing, we overwrote the CFLAGS added by all the preceding checks. Instead of overwriting CFLAGS, append the ones we need.

Fixes adc28027ff ("fuzz: add configure flag --enable-fuzzing")
Quoted 21 lines
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -2
index ee6c3c6792..078ebaa9f3 100755
@@ -7898,7 +7898,7 @@ if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
     FUZZ_CFLAGS=" -fsanitize=address,fuzzer"
-    CFLAGS=" -fsanitize=address,fuzzer-no-link"
+    CFLAGS="$CFLAGS -fsanitize=address,fuzzer-no-link"
   else
     error_exit "Your compiler doesn't support -fsanitize=address,fuzzer"
     exit 1
--

2.26.2

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH-for-5.1 1/2] configure: do not clobber CFLAGS with --enable-fuzzing

In reply to Alexander Bulekov
Quoted 17 lines · Alexander Bulekov

When configuring with --enable-fuzzing, we overwrote the CFLAGS added by all the preceding checks. Instead of overwriting CFLAGS, append the ones we need.

Fixes adc28027ff ("fuzz: add configure flag --enable-fuzzing")
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index ee6c3c6792..078ebaa9f3 100755

configure if test "$fuzzing" = "yes" ; then · line 7904

Quoted 8 lines
configure +1 -1
@@ -7898,7 +7898,7 @@ if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
     FUZZ_CFLAGS=" -fsanitize=address,fuzzer"
-    CFLAGS=" -fsanitize=address,fuzzer-no-link"
+    CFLAGS="$CFLAGS -fsanitize=address,fuzzer-no-link"
   else
     error_exit "Your compiler doesn't support -fsanitize=address,fuzzer"
     exit 1
#4 lore raw

PATCH 2/2 fuzz: add missing header for rcu_enable_atfork

In reply to Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +1 -0
index a36d9038e0..0b66e43409 100644
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"
Signature · 1 line
2.26.2
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 17 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +0 -0
index a36d9038e0..0b66e43409 100644

tests/qtest/fuzz/fuzz.c line 25

Quoted 7 lines
tests/qtest/fuzz/fuzz.c +1 -0
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"
#6 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 16 lines

tests/qtest/fuzz/fuzz.c line 25

Quoted 13 lines
tests/qtest/fuzz/fuzz.c +1 -0
index a36d9038e0..0b66e43409 100644
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"

Please add the include to softmmu/vl.c too.

#7 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 16 lines

tests/qtest/fuzz/fuzz.c line 25

Quoted 13 lines
tests/qtest/fuzz/fuzz.c +1 -0
index a36d9038e0..0b66e43409 100644
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"
Quoted 1 line

Please add the include to softmmu/vl.c too.

Why? Did you run into compile problems here, too?

Thomas

#8 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 31 lines · Thomas Huth
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +0 -0
index a36d9038e0..0b66e43409 100644

tests/qtest/fuzz/fuzz.c line 25

Quoted 7 lines
tests/qtest/fuzz/fuzz.c +1 -0
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"
Quoted 3 lines
Quoted 1 line

Please add the include to softmmu/vl.c too.

Why? Did you run into compile problems here, too?

No, because it is unexpectedly pulled by "exec/memory.h".

You are right however this is unrelated to 45222b9a90, it comes from 73c6e4013b ("rcu: completely disable pthread_atfork callbacks as soon as possible"), so I'll send a separate patch.

Reviewed-by on v1 2/2
#9 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

In reply to Alexander Bulekov
Quoted 16 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +0 -0
index a36d9038e0..0b66e43409 100644

tests/qtest/fuzz/fuzz.c line 25

Quoted 7 lines
tests/qtest/fuzz/fuzz.c +1 -0
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"

D'oh, mea culpa, I also apparently did not properly compile test that patch :-( I think we need a CI job that at least compile tests the fuzzing code - I can look into that once Alex Bennée's current testing pull request has been merged.

Alexander, is there also a way to run a fuzzer just for some few minutes? E.g. a fuzzing test that finishes quickly, or an option to limit the time that a test is running? If so, we could also add that quick test to the CI pipeline, to make sure that the fuzzer code does not only compile, but is also able to run (at least a little bit).

For this patch here:

#10 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 21 lines · Thomas Huth
Quoted 20 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +1 -0
index a36d9038e0..0b66e43409 100644
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
Quoted 8 lines

tests/qtest/fuzz/fuzz.c line 25

Quoted 3 lines
tests/qtest/fuzz/fuzz.c +0 -0
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"

D'oh, mea culpa, I also apparently did not properly compile test that patch :-( I think we need a CI job that at least compile tests the fuzzing code - I can look into that once Alex Bennée's current testing pull request has been merged.

My bad - I should have done a clean build with a version of clang that doesn't require me to -disable-werror

Quoted 5 lines

Alexander, is there also a way to run a fuzzer just for some few minutes? E.g. a fuzzing test that finishes quickly, or an option to limit the time that a test is running? If so, we could also add that quick test to the CI pipeline, to make sure that the fuzzer code does not only compile, but is also able to run (at least a little bit).

Yes. I think the sequence could look something like:
CC=clang CXX=clang++ ../configure --enable-fuzzing --enable-sanitizers \
--enable-werror
make i386-softmmu/fuzz
./i386-softmmu/qemu-fuzz-i386 --fuzz-target=i440fx-qtest-reboot-fuzz -runs=5000

This will run the i440fx fuzzer over 5000 inputs which should finish in a second or so. I don't expect it to actually find any crashes in the i440fx in such a short period, so, ideally, all errors would be fuzzer-related.

Where can I get started with building out a CI job for this?

One aside: running this right now, QEMU exits and AddressSanitizer complains about some leaks. There is a patch in Paolo's PR that should fix this, but I was surprised that existing CI tests didn't catch it. Is leak detection usually disabled in CI?

Quoted 2 lines

For this patch here:

Thanks!
-Alex

#11 lore raw

Re: [PATCH-for-5.1 2/2] fuzz: add missing header for rcu_enable_atfork

Quoted 46 lines · Alexander Bulekov
Quoted 21 lines · Thomas Huth
Quoted 20 lines · Alexander Bulekov

In 45222b9a90, I fixed a broken check for rcu_enable_atfork introduced in d6919e4cb6. I added a call to rcu_enable_atfork after the call to qemu_init in fuzz.c, but forgot to include the corresponding header, breaking --enable-fuzzing --enable-werror builds.

Fixes 45222b9a90 ("fuzz: fix broken qtest check at rcu_disable_atfork")
---
 tests/qtest/fuzz/fuzz.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/fuzz/fuzz.c +1 -0
index a36d9038e0..0b66e43409 100644
@@ -19,6 +19,7 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "qemu/main-loop.h"
+#include "qemu/rcu.h"
Quoted 8 lines

tests/qtest/fuzz/fuzz.c line 25

Quoted 3 lines
tests/qtest/fuzz/fuzz.c +0 -0
 #include "tests/qtest/libqtest.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "fuzz.h"

D'oh, mea culpa, I also apparently did not properly compile test that patch :-( I think we need a CI job that at least compile tests the fuzzing code - I can look into that once Alex Bennée's current testing pull request has been merged.

My bad - I should have done a clean build with a version of clang that doesn't require me to -disable-werror

Quoted 5 lines

Alexander, is there also a way to run a fuzzer just for some few minutes? E.g. a fuzzing test that finishes quickly, or an option to limit the time that a test is running? If so, we could also add that quick test to the CI pipeline, to make sure that the fuzzer code does not only compile, but is also able to run (at least a little bit).

Yes. I think the sequence could look something like:
CC=clang CXX=clang++ ../configure --enable-fuzzing --enable-sanitizers \
--enable-werror
make i386-softmmu/fuzz
./i386-softmmu/qemu-fuzz-i386 --fuzz-target=i440fx-qtest-reboot-fuzz -runs=5000

Quoted 6 lines

This will run the i440fx fuzzer over 5000 inputs which should finish in a second or so. I don't expect it to actually find any crashes in the i440fx in such a short period, so, ideally, all errors would be fuzzer-related.

Where can I get started with building out a CI job for this?

I'd suggest to use gitlab, since we're currently focusing on that for our CI. So get an account on gitlab, clone the qemu repository there
(https://gitlab.com/qemu-project/qemu) to your account, and then you should almost be ready to go: Edit the .gitlab-ci.yml file in the repository, and once you push your local branch to the gitlab server, you should see the jobs running in the "CI / CD" section. (Not sure anymore whether you have to enable the CI manually for your project, though, but it should not be too hard to find that setting if that's the case)

Quoted 4 lines

One aside: running this right now, QEMU exits and AddressSanitizer complains about some leaks. There is a patch in Paolo's PR that should fix this, but I was surprised that existing CI tests didn't catch it. Is leak detection usually disabled in CI?

I'm not aware of any CI tests that is currently using leak detection ... so it's certainly welcome if we get more test coverage here!

Thomas