From: Paolo Bonzini <pbonzini@redhat.com>
To: "Oleinik, Alexander" <alxndr@bu.edu>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "bsd@redhat.com" <bsd@redhat.com>,
"superirishdonkey@gmail.com" <superirishdonkey@gmail.com>,
"stefanha@redhat.com" <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [RFC 08/19] fuzz: add shims to intercept libfuzzer init
Date: Thu, 25 Jul 2019 10:21:18 +0200 [thread overview]
Message-ID: <76dc362b-ae7c-6c81-f068-c7faf00d5b05@redhat.com> (raw)
In-Reply-To: <20190725032321.12721-9-alxndr@bu.edu>
On 25/07/19 05:23, Oleinik, Alexander wrote:
> Intercept coverage buffer registration calls and use this information to
> copy them to shared memory, if using fork() to avoid resetting device
> state.
>
> Signed-off-by: Alexander Oleinik <alxndr@bu.edu>
> ---
> tests/fuzz/fuzzer_hooks.c | 106 ++++++++++++++++++++++++++++++++++++++
> tests/fuzz/fuzzer_hooks.h | 9 ++++
> 2 files changed, 115 insertions(+)
> create mode 100644 tests/fuzz/fuzzer_hooks.c
> create mode 100644 tests/fuzz/fuzzer_hooks.h
>
> diff --git a/tests/fuzz/fuzzer_hooks.c b/tests/fuzz/fuzzer_hooks.c
> new file mode 100644
> index 0000000000..5a0bbec413
> --- /dev/null
> +++ b/tests/fuzz/fuzzer_hooks.c
> @@ -0,0 +1,106 @@
> +#include "qemu/osdep.h"
> +#include "qemu/units.h"
> +#include "qapi/error.h"
> +#include "qemu-common.h"
> +#include "fuzzer_hooks.h"
> +
> +#include <dlfcn.h>
> +#include <elf.h>
> +
> +
> +extern void* _ZN6fuzzer3TPCE;
Would it make sense to make this a C++ source, so that you can avoid
using the mangled names (in this case, "namespace fuzzer { extern void
*TPC; }" and then using fuzzer::TPC)? Even if it's just a single symbol.
> +// The libfuzzer handlers
> +void __real___sanitizer_cov_8bit_counters_init(uint8_t*, uint8_t*);
> +void __real___sanitizer_cov_trace_pc_guard_init(uint8_t*, uint8_t*);
> +
> +void __wrap___sanitizer_cov_8bit_counters_init(uint8_t *Start, uint8_t *Stop);
> +void __wrap___sanitizer_cov_trace_pc_guard_init(uint8_t *Start, uint8_t *Stop);
> +
> +
> +void* counter_shm;
> +
> +typedef struct CoverageRegion {
> + uint8_t* start;
> + size_t length;
> + bool store; /* Set this if it needs to be copied to the forked process */
> +} CoverageRegion;
> +
> +CoverageRegion regions[10];
> +int region_index = 0;
> +
> +void __wrap___sanitizer_cov_8bit_counters_init(uint8_t *Start, uint8_t *Stop)
> +{
> + regions[region_index].start = Start;
> + regions[region_index].length = Stop-Start;
> + regions[region_index].store = true;
> + region_index++;
> + __real___sanitizer_cov_8bit_counters_init(Start, Stop);
> +}
> +
> +void __wrap___sanitizer_cov_trace_pc_guard_init(uint8_t *Start, uint8_t *Stop)
> +{
> + regions[region_index].start = Start;
> + regions[region_index++].length = Stop-Start;
> + regions[region_index].store = true;
> + region_index++;
> + __real___sanitizer_cov_trace_pc_guard_init(Start, Stop);
> +}
> +
> +static void add_tpc_region(void)
> +{
> + /* Got symbol and length from readelf. Horrible way to do this! */
> + regions[region_index].start = (uint8_t*)(&_ZN6fuzzer3TPCE);
> + regions[region_index].length = 0x443c00;
> + regions[region_index].store = true;
> + region_index++;
> +}
> +
> +void counter_shm_init(void)
> +{
> + /*
> + * Add the internal libfuzzer object that gets modified by cmp, etc
> + * callbacks
> + */
> + add_tpc_region();
> +
> + size_t length = 0;
> + for(int i=0; i<region_index; i++){
> + printf("%d %lx\n", i, length);
> + length += regions[i].length;
> + }
> +
> + /*
> + * Map some shared memory. When we use a fork-server we can copy the
> + * libfuzzer-related counters
> + * */
> + counter_shm = mmap(NULL, length, PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_ANONYMOUS, -1, 0);
> + if(counter_shm == MAP_FAILED) {
> + printf("mmap() failed\n");
> + do { perror("error:"); exit(EXIT_FAILURE); } while (0);
> + exit(-1);
> + }
> +}
> +
> +void counter_shm_store(void)
> +{
> + size_t offset = 0;
> + for(int i=0; i<region_index; i++) {
> + if(regions[i].store) {
> + memcpy(counter_shm + offset, regions[i].start, regions[i].length);
> + }
> + offset+=regions[i].length;
> + }
> +}
> +
> +void counter_shm_load(void)
> +{
> + size_t offset = 0;
> + for(int i=0; i<region_index; i++) {
> + if(regions[i].store) {
> + memcpy(regions[i].start, counter_shm + offset, regions[i].length);
> + }
> + offset+=regions[i].length;
> + }
> +}
> +
> diff --git a/tests/fuzz/fuzzer_hooks.h b/tests/fuzz/fuzzer_hooks.h
> new file mode 100644
> index 0000000000..90dca254d4
> --- /dev/null
> +++ b/tests/fuzz/fuzzer_hooks.h
> @@ -0,0 +1,9 @@
> +#ifndef FUZZER_HOOKS_H
> +#define FUZZER_HOOKS_H
> +
> +void counter_shm_init(void);
> +void counter_shm_store(void);
> +void counter_shm_load(void);
> +
> +#endif
> +
>
next prev parent reply other threads:[~2019-07-25 8:21 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 3:23 [Qemu-devel] [RFC 00/19] Add virtual device fuzzing support Oleinik, Alexander
2019-07-25 3:23 ` [Qemu-devel] [RFC 01/19] fuzz: add configure option and linker objects Oleinik, Alexander
2019-07-25 9:39 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 02/19] fuzz: add FUZZ_TARGET type to qemu module system Oleinik, Alexander
2019-07-26 12:32 ` Stefan Hajnoczi
2019-07-25 3:23 ` [Qemu-devel] [RFC 03/19] fuzz: add fuzz accelerator Oleinik, Alexander
2019-07-26 10:33 ` Paolo Bonzini
2019-07-26 12:35 ` Stefan Hajnoczi
2019-07-25 3:23 ` [Qemu-devel] [RFC 04/19] fuzz: Add qos support to fuzz targets Oleinik, Alexander
2019-07-26 10:39 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 05/19] fuzz: expose qemu_savevm_state & skip state header Oleinik, Alexander
2019-07-25 13:22 ` Dr. David Alan Gilbert
2019-07-25 3:23 ` [Qemu-devel] [RFC 07/19] fuzz: Modify libqtest to directly invoke qtest.c Oleinik, Alexander
2019-07-25 9:04 ` Thomas Huth
2019-07-25 9:33 ` Paolo Bonzini
2019-07-26 12:49 ` Stefan Hajnoczi
2019-07-26 12:56 ` Stefan Hajnoczi
2019-07-26 21:50 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 06/19] fuzz: Add ramfile for fast vmstate/vmload Oleinik, Alexander
2019-07-26 12:47 ` Stefan Hajnoczi
2019-07-26 19:36 ` Oleinik, Alexander
2019-07-26 19:54 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 08/19] fuzz: add shims to intercept libfuzzer init Oleinik, Alexander
2019-07-25 8:21 ` Paolo Bonzini [this message]
2019-07-26 12:59 ` Stefan Hajnoczi
2019-07-25 3:23 ` [Qemu-devel] [RFC 09/19] fuzz: use mtree_info to find mapped addresses Oleinik, Alexander
2019-07-26 13:04 ` Stefan Hajnoczi
2019-07-26 21:51 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 10/19] fuzz: expose real_main (aka regular vl.c:main) Oleinik, Alexander
2019-07-25 9:38 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 11/19] fuzz: add direct send/receive in qtest client Oleinik, Alexander
2019-07-25 9:10 ` Thomas Huth
2019-07-25 3:23 ` [Qemu-devel] [RFC 12/19] fuzz: hard-code all of the needed files for build Oleinik, Alexander
2019-07-25 3:23 ` [Qemu-devel] [RFC 13/19] fuzz: add ctrl vq support to virtio-net in libqos Oleinik, Alexander
2019-07-25 16:25 ` John Snow
2019-07-25 17:05 ` Oleinik, Alexander
2019-07-26 13:09 ` Stefan Hajnoczi
2019-07-25 3:23 ` [Qemu-devel] [RFC 14/19] fuzz: hard-code a main-loop timeout Oleinik, Alexander
2019-07-25 9:40 ` Paolo Bonzini
2019-07-25 3:23 ` [Qemu-devel] [RFC 15/19] fuzz: add fuzz accelerator type Oleinik, Alexander
2019-07-25 3:23 ` [Qemu-devel] [RFC 16/19] fuzz: add general fuzzer entrypoints Oleinik, Alexander
2019-07-25 17:53 ` Philippe Mathieu-Daudé
2019-07-25 3:23 ` [Qemu-devel] [RFC 17/19] fuzz: add general qtest fuzz target Oleinik, Alexander
2019-07-25 3:24 ` [Qemu-devel] [RFC 19/19] fuzz: Add documentation about the fuzzer to docs/ Oleinik, Alexander
2019-07-26 13:19 ` Stefan Hajnoczi
2019-07-25 3:24 ` [Qemu-devel] [RFC 18/19] fuzz: Add virtio-net tx and ctrl fuzz targets Oleinik, Alexander
2019-07-25 3:41 ` [Qemu-devel] [RFC 00/19] Add virtual device fuzzing support no-reply
2019-07-26 13:24 ` Stefan Hajnoczi
2019-08-06 9:59 ` jiade zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76dc362b-ae7c-6c81-f068-c7faf00d5b05@redhat.com \
--to=pbonzini@redhat.com \
--cc=alxndr@bu.edu \
--cc=bsd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=superirishdonkey@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).