Skip to contentSkip to conversation

fuzz: Skip QTest serialization

PATCH In review Alexander Bulekov 4 participants 8 messages May 29, 2020 – Jun 3, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover fuzz: Skip QTest serialization

In the same vein as Philippe's patch:

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

This uses linker trickery to wrap calls to libqtest functions and directly call the corresponding read/write functions, rather than relying on the ASCII-serialized QTest protocol.

v2: applies properly

v3: add missing qtest_wrappers.c file and fix formatting in fuzz.c

Alexander Bulekov (2):
fuzz: skip QTest serialization
fuzz: Add support for logging QTest commands

 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  20 ++-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 1/2 fuzz: skip QTest serialization

The QTest server usually parses ASCII commands from clients. Since we fuzz within the QEMU process, skip the QTest serialization and server for most QTest commands. Leave the option to use the ASCII protocol, to generate readable traces for crash reproducers.

---
 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  13 +-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 288 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
tests/qtest/fuzz/Makefile.include +21 -0
index f259d866c9..5bde793bf2 100644
@@ -5,6 +5,7 @@ fuzz-obj-y += $(libqos-obj-y)
 fuzz-obj-y += tests/qtest/fuzz/fuzz.o # Fuzzer skeleton
 fuzz-obj-y += tests/qtest/fuzz/fork_fuzz.o
 fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o
+fuzz-obj-y += tests/qtest/fuzz/qtest_wrappers.o
 
 # Targets
 fuzz-obj-$(CONFIG_PCI_I440FX) += tests/qtest/fuzz/i440fx_fuzz.o
@@ -16,3 +17,23 @@ FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest
 # Linker Script to force coverage-counters into known regions which we can mark
 # shared
 FUZZ_LDFLAGS += -Xlinker -T$(SRC_PATH)/tests/qtest/fuzz/fork_fuzz.ld
+
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_inb
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_inw
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_inl
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_outb
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_outw
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_outl
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_readb
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_readw
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_readl
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_readq
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_writeb
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_writew
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_writel
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_writeq
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_memread
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_bufread
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_memwrite
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_bufwrite
+FUZZ_LDFLAGS += -Wl,-wrap,qtest_memset
tests/qtest/fuzz/fuzz.c +12 -1
index f5c923852e..88ac88bca9 100644
@@ -91,7 +91,10 @@ static void usage(char *path)
         printf(" * %s  : %s\n", tmp->target->name,
                 tmp->target->description);
     }
-    printf("Alternatively, add -target-FUZZ_TARGET to the executable name\n");
+    printf("Alternatively, add -target-FUZZ_TARGET to the executable name\n\n"
+           "Set the environment variable FUZZ_SERIALIZE_QTEST=1 to serialize\n"
+           "QTest commands into an ASCII protocol. Useful for building crash\n"
+           "reproducers, but slows down execution.\n");
     exit(0);
 }
 
@@ -137,6 +140,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
 {
 
     char *target_name;
+    bool serialize = false;
 
     /* Initialize qgraph and modules */
     qos_graph_init();
@@ -157,6 +161,13 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
         usage(**argv);
     }
 
+    /* Should we always serialize qtest commands? */
+    if (getenv("FUZZ_SERIALIZE_QTEST")) {
+        serialize = true;
+    }
+
+    fuzz_qtest_set_serialize(serialize);
+
     /* Identify the fuzz target */
     fuzz_target = fuzz_get_target(target_name);
     if (!fuzz_target) {
tests/qtest/fuzz/fuzz.h +3 -0
index 03901d414e..72d5710f6c 100644
@@ -82,6 +82,9 @@ typedef struct FuzzTarget {
 void flush_events(QTestState *);
 void reboot(QTestState *);
 
+/* Use the QTest ASCII protocol or call address_space API directly?*/
+void fuzz_qtest_set_serialize(bool option);
+
 /*
  * makes a copy of *target and adds it to the target-list.
  * i.e. fine to set up target on the caller's stack
tests/qtest/fuzz/qtest_wrappers.c new file +252 -0

252 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

PATCH v3 2/2 fuzz: Add support for logging QTest commands

In reply to Alexander Bulekov
---
 tests/qtest/fuzz/fuzz.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/qtest/fuzz/fuzz.c +8 -1
index 88ac88bca9..21cdee53db 100644
@@ -94,7 +94,9 @@ static void usage(char *path)
     printf("Alternatively, add -target-FUZZ_TARGET to the executable name\n\n"
            "Set the environment variable FUZZ_SERIALIZE_QTEST=1 to serialize\n"
            "QTest commands into an ASCII protocol. Useful for building crash\n"
-           "reproducers, but slows down execution.\n");
+           "reproducers, but slows down execution.\n\n"
+           "Set the environment variable QTEST_LOG=1 to log all qtest commands"
+           "\n");
     exit(0);
 }
 
@@ -182,6 +184,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
 
     /* Run QEMU's softmmu main with the fuzz-target dependent arguments */
     const char *init_cmdline = fuzz_target->get_init_cmdline(fuzz_target);
+    init_cmdline = g_strdup_printf("%s -qtest /dev/null -qtest-log %s",
+                                   init_cmdline,
+                                   getenv("QTEST_LOG") ? "/dev/fd/2"
+                                                       : "/dev/null");
+
 
     /* Split the runcmd into an argv and argc */
     wordexp_t result;
Signature · 1 line
2.26.2
#3 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 v3 0/2] fuzz: Skip QTest serialization
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 ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
690701b fuzz: Add support for logging QTest commands c833a8a fuzz: skip QTest serialization

=== OUTPUT BEGIN ===
1/2 Checking commit c833a8a44c55 (fuzz: skip QTest serialization)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #105:
new file mode 100644

ERROR: Macros with multiple statements should be enclosed in a do - while loop #131: FILE: tests/qtest/fuzz/qtest_wrappers.c:22:
+#define WRAP(RET_TYPE, NAME_AND_ARGS)\
+ RET_TYPE __wrap_##NAME_AND_ARGS;\
+ RET_TYPE __real_##NAME_AND_ARGS;

total: 1 errors, 1 warnings, 322 lines checked

Patch 1/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

2/2 Checking commit 690701bb2f91 (fuzz: Add support for logging QTest commands) === 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]

Reviewed-by on the v3 series
#4 lore raw
In reply to Alexander Bulekov

Hi Alex,

In general the series looks good, so:

But not sure how to handle the patchew output though, not sure if it is really a concern or not, since do/while won't work that context.

Thanks,

Darren.

Quoted 25 lines · Alexander Bulekov

In the same vein as Philippe's patch:

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

This uses linker trickery to wrap calls to libqtest functions and directly call the corresponding read/write functions, rather than relying on the ASCII-serialized QTest protocol.

v2: applies properly

v3: add missing qtest_wrappers.c file and fix formatting in fuzz.c

Alexander Bulekov (2):
fuzz: skip QTest serialization
fuzz: Add support for logging QTest commands

 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  20 ++-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
Signature · 1 line
2.26.2
#5 lore raw

Thank you Darren.

Quoted 10 lines · Darren Kenny

Hi Alex,

In general the series looks good, so:

But not sure how to handle the patchew output though, not sure if it is really a concern or not, since do/while won't work that context.

Yes - I was not really sure how to deal with those failures, so I sent the patch anyway. Maybe someone else knows a workaround. -Alex

Quoted 30 lines

Thanks,

Darren.

Quoted 25 lines · Alexander Bulekov

In the same vein as Philippe's patch:

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

This uses linker trickery to wrap calls to libqtest functions and directly call the corresponding read/write functions, rather than relying on the ASCII-serialized QTest protocol.

v2: applies properly

v3: add missing qtest_wrappers.c file and fix formatting in fuzz.c

Alexander Bulekov (2):
fuzz: skip QTest serialization
fuzz: Add support for logging QTest commands

 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  20 ++-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
Signature · 1 line
2.26.2
#6 lore raw
Quoted 10 lines · Alexander Bulekov

Thank you Darren.

Quoted 7 lines · Darren Kenny

Hi Alex,

In general the series looks good, so:

Quoted 7 lines
Quoted 3 lines

But not sure how to handle the patchew output though, not sure if it is really a concern or not, since do/while won't work that context.

Yes - I was not really sure how to deal with those failures, so I sent the patch anyway. Maybe someone else knows a workaround. -Alex

Don't worry, the checkpatch script is known to generate false warnings/errors in some cases. If you've got such a case, simply state it as a reply to the mail from patchew, and then the message from patchew can be simply ignored.

By the way, I'm finally back to the state where I can pick up qtest patches again (btw2, thanks for Stefan for picking up all the fuzzer patches in the past months). So question: With your two patches here, the patch from Philippe is not required anymore, right?

Thanks,
Thomas

Quoted 27 lines
Quoted 26 lines · Alexander Bulekov
Quoted 25 lines

In the same vein as Philippe's patch:

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

This uses linker trickery to wrap calls to libqtest functions and directly call the corresponding read/write functions, rather than relying on the ASCII-serialized QTest protocol.

v2: applies properly

v3: add missing qtest_wrappers.c file and fix formatting in fuzz.c

Alexander Bulekov (2):
fuzz: skip QTest serialization
fuzz: Add support for logging QTest commands

 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  20 ++-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
Signature · 1 line
2.26.2
#7 lore raw
Quoted 24 lines · Thomas Huth
Quoted 10 lines · Alexander Bulekov

Thank you Darren.

Quoted 7 lines · Darren Kenny

Hi Alex,

In general the series looks good, so:

Quoted 7 lines
Quoted 3 lines

But not sure how to handle the patchew output though, not sure if it is really a concern or not, since do/while won't work that context.

Yes - I was not really sure how to deal with those failures, so I sent the patch anyway. Maybe someone else knows a workaround. -Alex

Don't worry, the checkpatch script is known to generate false warnings/errors in some cases. If you've got such a case, simply state it as a reply to the mail from patchew, and then the message from patchew can be simply ignored.

Quoted 4 lines

By the way, I'm finally back to the state where I can pick up qtest patches again (btw2, thanks for Stefan for picking up all the fuzzer patches in the past months). So question: With your two patches here, the patch from Philippe is not required anymore, right?

Hi Thomas,
Yes - I think this series enables the same improvements as Philippe's patch.
Thank you
-Alex

Quoted 32 lines

Thanks,
Thomas

Quoted 27 lines
Quoted 26 lines · Alexander Bulekov
Quoted 25 lines

In the same vein as Philippe's patch:

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

This uses linker trickery to wrap calls to libqtest functions and directly call the corresponding read/write functions, rather than relying on the ASCII-serialized QTest protocol.

v2: applies properly

v3: add missing qtest_wrappers.c file and fix formatting in fuzz.c

Alexander Bulekov (2):
fuzz: skip QTest serialization
fuzz: Add support for logging QTest commands

 tests/qtest/fuzz/Makefile.include |  21 +++
 tests/qtest/fuzz/fuzz.c           |  20 ++-
 tests/qtest/fuzz/fuzz.h           |   3 +
 tests/qtest/fuzz/qtest_wrappers.c | 252 ++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/fuzz/qtest_wrappers.c
Signature · 1 line
2.26.2