[PATCH v8 21/21] fuzz: add documentation to docs/devel/

2020-01-28 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- docs/devel/fuzzing.txt | 116 + 1 file changed, 116 insertions(+) create mode 100644 docs/devel/fuzzing.txt diff --git a/docs/devel/fuzzing.txt b/docs/devel/fuzzing.txt new file mode 10064

[PATCH v8 20/21] fuzz: add virtio-scsi fuzz target

2020-01-28 Thread Bulekov, Alexander
The virtio-scsi fuzz target sets up and fuzzes the available virtio-scsi queues. After an element is placed on a queue, the fuzzer can select whether to perform a kick, or continue adding elements. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.inclu

[PATCH v8 14/21] fuzz: support for fork-based fuzzing.

2020-01-28 Thread Bulekov, Alexander
fork() is a simple way to ensure that state does not leak in between fuzzing runs. Unfortunately, the fuzzer mutation engine relies on bitmaps which contain coverage information for each fuzzing run, and these bitmaps should be copied from the child to the parent(where the mutation occurs). These b

[PATCH v8 12/21] exec: keep ram block across fork when using qtest

2020-01-28 Thread Bulekov, Alexander
Ram blocks were marked MADV_DONTFORK breaking fuzzing-tests which execute each test-input in a forked process. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- exec.c | 12 ++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index d4b769d

[PATCH v8 18/21] fuzz: add i440fx fuzz targets

2020-01-28 Thread Bulekov, Alexander
These three targets should simply fuzz reads/writes to a couple ioports, but they mostly serve as examples of different ways to write targets. They demonstrate using qtest and qos for fuzzing, as well as using rebooting and forking to reset state, or not resetting it at all. Signed-off-by: Alexand

[PATCH v8 15/21] fuzz: add support for qos-assisted fuzz targets

2020-01-28 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 2 + tests/qtest/fuzz/qos_fuzz.c | 229 ++ tests/qtest/fuzz/qos_fuzz.h | 33 + 3 files changed, 264 insertions(+) create mode 100644 tests/qtest/f

[PATCH v8 19/21] fuzz: add virtio-net fuzz target

2020-01-28 Thread Bulekov, Alexander
The virtio-net fuzz target feeds inputs to all three virtio-net virtqueues, and uses forking to avoid leaking state between fuzz runs. Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_net_fuzz.c | 195 + 2 files

[PATCH v8 08/21] libqos: rename i2c_send and i2c_recv

2020-01-28 Thread Bulekov, Alexander
The names i2c_send and i2c_recv collide with functions defined in hw/i2c/core.c. This causes an error when linking against libqos and softmmu simultaneously (for example when using qtest inproc). Rename the libqos functions to avoid this. Signed-off-by: Alexander Bulekov Acked-by: Thomas Huth Re

[PATCH v8 17/21] fuzz: add configure flag --enable-fuzzing

2020-01-28 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- configure | 39 +++ 1 file changed, 39 insertions(+) diff --git a/configure b/configure index 08c3a1c1f0..1a1e57eb61 100755 --- a/configure +++ b/configure

[PATCH v8 16/21] fuzz: add target/fuzz makefile rules

2020-01-28 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi --- Makefile| 15 ++- Makefile.objs | 2 +- Makefile.target | 16 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e6de7a47bb.

[PATCH v8 11/21] fuzz: add fuzzer skeleton

2020-01-28 Thread Bulekov, Alexander
tests/fuzz/fuzz.c serves as the entry point for the virtual-device fuzzer. Namely, libfuzzer invokes the LLVMFuzzerInitialize and LLVMFuzzerTestOneInput functions, both of which are defined in this file. This change adds a "FuzzTarget" struct, along with the fuzz_add_target function, which should b

[PATCH v8 10/21] libqos: move useful qos-test funcs to qos_external

2020-01-28 Thread Bulekov, Alexander
The moved functions are not specific to qos-test and might be useful elsewhere. For example the virtual-device fuzzer makes use of them for qos-assisted fuzz-targets. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/Makefile.incl

[PATCH v8 04/21] qtest: add qtest_server_send abstraction

2020-01-28 Thread Bulekov, Alexander
qtest_server_send is a function pointer specifying the handler used to transmit data to the qtest client. In the standard configuration, this calls the CharBackend handler, but now it is possible for other types of handlers, e.g direct-function calls if the qtest client and server exist within the

[PATCH v8 06/21] libqtest: make bufwrite rely on the TransportOps

2020-01-28 Thread Bulekov, Alexander
When using qtest "in-process" communication, qtest_sendf directly calls a function in the server (qtest.c). Previously, bufwrite used socket_send, which bypasses the TransportOps enabling the call into qtest.c. This change replaces the socket_send calls with ops->send, maintaining the benefits of t

[PATCH v8 13/21] main: keep rcu_atfork callback enabled for qtest

2020-01-28 Thread Bulekov, Alexander
The qtest-based fuzzer makes use of forking to reset-state between tests. Keep the callback enabled, so the call_rcu thread gets created within the child process. Signed-off-by: Alexander Bulekov --- vl.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c ind

[PATCH v8 07/21] qtest: add in-process incoming command handler

2020-01-28 Thread Bulekov, Alexander
The handler allows a qtest client to send commands to the server by directly calling a function, rather than using a file/CharBackend Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/sysemu/qtest.h | 1 + qtest.c| 13 + 2 files changed, 14 i

[PATCH v8 01/21] softmmu: split off vl.c:main() into main.c

2020-01-28 Thread Bulekov, Alexander
A program might rely on functions implemented in vl.c, but implement its own main(). By placing main into a separate source file, there are no complaints about duplicate main()s when linking against vl.o. For example, the virtual-device fuzzer uses a main() provided by libfuzzer, and needs to perfo

[PATCH v8 09/21] libqos: split qos-test and libqos makefile vars

2020-01-28 Thread Bulekov, Alexander
Most qos-related objects were specified in the qos-test-obj-y variable. qos-test-obj-y also included qos-test.o which defines a main(). This made it difficult to repurpose qos-test-obj-y to link anything beside tests/qos-test against libqos. This change separates objects that are libqos-specific an

[PATCH v8 02/21] module: check module wasn't already initialized

2020-01-28 Thread Bulekov, Alexander
The virtual-device fuzzer must initialize QOM, prior to running vl:qemu_init, so that it can use the qos_graph to identify the arguments required to initialize a guest for libqos-assisted fuzzing. This change prevents errors when vl:qemu_init tries to (re)initialize the previously initialized QOM m

[PATCH v8 00/21] Add virtual device fuzzing support

2020-01-28 Thread Bulekov, Alexander
This series adds a framework for coverage-guided fuzzing of virtual-devices. Fuzzing targets are based on qtest and can make use of the libqos abstractions. V8: * Small fixes to the virtio-net. * Keep rcu_atfork when not using qtest. V7: * virtio-net: add virtio-net-check-used which waits for

[PATCH v8 03/21] fuzz: add FUZZ_TARGET module type

2020-01-28 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/qemu/module.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/qemu/module.h b/include/qemu/module.h index 65ba596e46..684753d808 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h

[PATCH v8 05/21] libqtest: add a layer of abstraction to send/recv

2020-01-28 Thread Bulekov, Alexander
This makes it simple to swap the transport functions for qtest commands to and from the qtest client. For example, now it is possible to directly pass qtest commands to a server handler that exists within the same process, without the standard way of writing to a file descriptor. Signed-off-by: Al

[PATCH v7 20/20] fuzz: add documentation to docs/devel/

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- docs/devel/fuzzing.txt | 116 + 1 file changed, 116 insertions(+) create mode 100644 docs/devel/fuzzing.txt diff --git a/docs/devel/fuzzing.txt b/docs/devel/fuzzing.txt new file mode 10064

[PATCH v7 20/20] fuzz: add virtio-scsi fuzz target

2020-01-19 Thread Bulekov, Alexander
The virtio-scsi fuzz target sets up and fuzzes the available virtio-scsi queues. After an element is placed on a queue, the fuzzer can select whether to perform a kick, or continue adding elements. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.inclu

[PATCH v7 12/20] exec: keep ram block across fork when using qtest

2020-01-19 Thread Bulekov, Alexander
Ram blocks were marked MADV_DONTFORK breaking fuzzing-tests which execute each test-input in a forked process. Signed-off-by: Alexander Bulekov --- exec.c | 12 ++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index d4b769d0d4..99368f175b 100644 --- a/e

[PATCH v7 18/20] fuzz: add i440fx fuzz targets

2020-01-19 Thread Bulekov, Alexander
These three targets should simply fuzz reads/writes to a couple ioports, but they mostly serve as examples of different ways to write targets. They demonstrate using qtest and qos for fuzzing, as well as using rebooting and forking to reset state, or not resetting it at all. Signed-off-by: Alexand

[PATCH v7 09/20] libqos: move useful qos-test funcs to qos_external

2020-01-19 Thread Bulekov, Alexander
The moved functions are not specific to qos-test and might be useful elsewhere. For example the virtual-device fuzzer makes use of them for qos-assisted fuzz-targets. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/Makefile.incl

[PATCH v7 19/20] fuzz: add virtio-net fuzz target

2020-01-19 Thread Bulekov, Alexander
The virtio-net fuzz target feeds inputs to all three virtio-net virtqueues, and uses forking to avoid leaking state between fuzz runs. Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_net_fuzz.c | 190 + 2 files

[PATCH v7 17/20] fuzz: add i440fx fuzz targets

2020-01-19 Thread Bulekov, Alexander
These three targets should simply fuzz reads/writes to a couple ioports, but they mostly serve as examples of different ways to write targets. They demonstrate using qtest and qos for fuzzing, as well as using rebooting and forking to reset state, or not resetting it at all. Signed-off-by: Alexand

[PATCH v7 17/20] fuzz: add documentation to docs/devel/

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- docs/devel/fuzzing.txt | 119 + 1 file changed, 119 insertions(+) create mode 100644 docs/devel/fuzzing.txt diff --git a/docs/devel/fuzzing.txt b/docs/devel/fuzzing.txt new file mode 10064

[PATCH v7 09/20] libqos: split qos-test and libqos makefile vars

2020-01-19 Thread Bulekov, Alexander
Most qos-related objects were specified in the qos-test-obj-y variable. qos-test-obj-y also included qos-test.o which defines a main(). This made it difficult to repurpose qos-test-obj-y to link anything beside tests/qos-test against libqos. This change separates objects that are libqos-specific an

[PATCH v7 16/20] fuzz: add configure flag --enable-fuzzing

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- configure | 39 +++ 1 file changed, 39 insertions(+) diff --git a/configure b/configure index 08c3a1c1f0..17aa5d02ee 100755 --- a/configure +++ b/configure

[PATCH v7 18/20] fuzz: add virtio-net fuzz target

2020-01-19 Thread Bulekov, Alexander
The virtio-net fuzz target feeds inputs to all three virtio-net virtqueues, and uses forking to avoid leaking state between fuzz runs. Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_net_fuzz.c | 190 + 2 files

[PATCH v7 07/20] qtest: add in-process incoming command handler

2020-01-19 Thread Bulekov, Alexander
The handler allows a qtest client to send commands to the server by directly calling a function, rather than using a file/CharBackend Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/sysemu/qtest.h | 1 + qtest.c| 13 + 2 files changed, 14 i

[PATCH v7 14/20] fuzz: add support for qos-assisted fuzz targets

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 2 + tests/qtest/fuzz/qos_fuzz.c | 229 ++ tests/qtest/fuzz/qos_fuzz.h | 33 + 3 files changed, 264 insertions(+) create mode 100644 tests/qtest/f

[PATCH v7 13/20] fuzz: support for fork-based fuzzing.

2020-01-19 Thread Bulekov, Alexander
fork() is a simple way to ensure that state does not leak in between fuzzing runs. Unfortunately, the fuzzer mutation engine relies on bitmaps which contain coverage information for each fuzzing run, and these bitmaps should be copied from the child to the parent(where the mutation occurs). These b

[PATCH v7 05/20] libqtest: add a layer of abstraction to send/recv

2020-01-19 Thread Bulekov, Alexander
This makes it simple to swap the transport functions for qtest commands to and from the qtest client. For example, now it is possible to directly pass qtest commands to a server handler that exists within the same process, without the standard way of writing to a file descriptor. Signed-off-by: Al

[PATCH v7 10/20] libqos: move useful qos-test funcs to qos_external

2020-01-19 Thread Bulekov, Alexander
The moved functions are not specific to qos-test and might be useful elsewhere. For example the virtual-device fuzzer makes use of them for qos-assisted fuzz-targets. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/Makefile.incl

[PATCH v7 11/20] fuzz: add fuzzer skeleton

2020-01-19 Thread Bulekov, Alexander
tests/fuzz/fuzz.c serves as the entry point for the virtual-device fuzzer. Namely, libfuzzer invokes the LLVMFuzzerInitialize and LLVMFuzzerTestOneInput functions, both of which are defined in this file. This change adds a "FuzzTarget" struct, along with the fuzz_add_target function, which should b

[PATCH v7 19/20] fuzz: add virtio-scsi fuzz target

2020-01-19 Thread Bulekov, Alexander
The virtio-scsi fuzz target sets up and fuzzes the available virtio-scsi queues. After an element is placed on a queue, the fuzzer can select whether to perform a kick, or continue adding elements. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.inclu

[PATCH v7 06/20] libqtest: make bufwrite rely on the TransportOps

2020-01-19 Thread Bulekov, Alexander
When using qtest "in-process" communication, qtest_sendf directly calls a function in the server (qtest.c). Previously, bufwrite used socket_send, which bypasses the TransportOps enabling the call into qtest.c. This change replaces the socket_send calls with ops->send, maintaining the benefits of t

[PATCH v7 10/20] libqtest: make bufwrite rely on the TransportOps

2020-01-19 Thread Bulekov, Alexander
When using qtest "in-process" communication, qtest_sendf directly calls a function in the server (qtest.c). Previously, bufwrite used socket_send, which bypasses the TransportOps enabling the call into qtest.c. This change replaces the socket_send calls with ops->send, maintaining the benefits of t

[PATCH v7 08/20] libqos: rename i2c_send and i2c_recv

2020-01-19 Thread Bulekov, Alexander
The names i2c_send and i2c_recv collide with functions defined in hw/i2c/core.c. This causes an error when linking against libqos and softmmu simultaneously (for example when using qtest inproc). Rename the libqos functions to avoid this. Signed-off-by: Alexander Bulekov Acked-by: Thomas Huth Re

[PATCH v7 15/20] fuzz: add target/fuzz makefile rules

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi --- Makefile| 15 ++- Makefile.objs | 2 +- Makefile.target | 16 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e6de7a47bb.

[PATCH v7 03/20] fuzz: add FUZZ_TARGET module type

2020-01-19 Thread Bulekov, Alexander
Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/qemu/module.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/qemu/module.h b/include/qemu/module.h index 65ba596e46..684753d808 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h

[PATCH v7 02/20] module: check module wasn't already initialized

2020-01-19 Thread Bulekov, Alexander
The virtual-device fuzzer must initialize QOM, prior to running vl:qemu_init, so that it can use the qos_graph to identify the arguments required to initialize a guest for libqos-assisted fuzzing. This change prevents errors when vl:qemu_init tries to (re)initialize the previously initialized QOM m

[PATCH v7 06/20] module: check module wasn't already initialized

2020-01-19 Thread Bulekov, Alexander
The virtual-device fuzzer must initialize QOM, prior to running vl:qemu_init, so that it can use the qos_graph to identify the arguments required to initialize a guest for libqos-assisted fuzzing. This change prevents errors when vl:qemu_init tries to (re)initialize the previously initialized QOM m

[PATCH v7 08/20] libqos: split qos-test and libqos makefile vars

2020-01-19 Thread Bulekov, Alexander
Most qos-related objects were specified in the qos-test-obj-y variable. qos-test-obj-y also included qos-test.o which defines a main(). This made it difficult to repurpose qos-test-obj-y to link anything beside tests/qos-test against libqos. This change separates objects that are libqos-specific an

[PATCH v7 01/20] softmmu: split off vl.c:main() into main.c

2020-01-19 Thread Bulekov, Alexander
A program might rely on functions implemented in vl.c, but implement its own main(). By placing main into a separate source file, there are no complaints about duplicate main()s when linking against vl.o. For example, the virtual-device fuzzer uses a main() provided by libfuzzer, and needs to perfo

[PATCH v7 00/20] Add virtual device fuzzing support

2020-01-19 Thread Bulekov, Alexander
This series adds a framework for coverage-guided fuzzing of virtual-devices. Fuzzing targets are based on qtest and can make use of the libqos abstractions. This version mostly contains cleanup with some changes to the virtio-net fuzzer. V7: * virtio-net: add virtio-net-check-used which waits fo

[PATCH v7 04/20] qtest: add qtest_server_send abstraction

2020-01-19 Thread Bulekov, Alexander
qtest_server_send is a function pointer specifying the handler used to transmit data to the qtest client. In the standard configuration, this calls the CharBackend handler, but now it is possible for other types of handlers, e.g direct-function calls if the qtest client and server exist within the

[PATCH v7 02/20] libqos: rename i2c_send and i2c_recv

2020-01-19 Thread Bulekov, Alexander
The names i2c_send and i2c_recv collide with functions defined in hw/i2c/core.c. This causes an error when linking against libqos and softmmu simultaneously (for example when using qtest inproc). Rename the libqos functions to avoid this. Signed-off-by: Alexander Bulekov Acked-by: Thomas Huth Re