From: Wei Liu Date: Wed, 7 Dec 2016 11:28:56 +0000 (+0000) Subject: tools/fuzz: introduce libelf target X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~3174 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4f62f31d257cf9e3ef20ee359d40b9728e9e9596;p=xen.git tools/fuzz: introduce libelf target Source code and Makefile to fuzz libelf in Google's oss-fuzz infrastructure. Introduce FUZZ_NO_LIBXC in libelf-private.h. That macro will be set when compiling libelf fuzzer target because libxc is not required in libelf fuzzing. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- diff --git a/tools/fuzz/libelf/Makefile b/tools/fuzz/libelf/Makefile new file mode 100644 index 0000000000..0e9d40a4a0 --- /dev/null +++ b/tools/fuzz/libelf/Makefile @@ -0,0 +1,31 @@ +XEN_ROOT = $(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +# libelf fuzz target +vpath %.c ../../../xen/common/libelf +CFLAGS += -I../../../xen/common/libelf +ELF_SRCS-y += libelf-tools.c libelf-loader.c libelf-dominfo.c +ELF_LIB_OBJS := $(patsubst %.c,%.o,$(ELF_SRCS-y)) + +$(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign + +$(ELF_LIB_OBJS): CFLAGS += -DFUZZ_NO_LIBXC $(CFLAGS_xeninclude) + +libelf-fuzzer.o: CFLAGS += $(CFLAGS_xeninclude) + +libelf.a: $(ELF_LIB_OBJS) + $(AR) rc $@ $^ + +.PHONY: libelf-fuzzer-all +libelf-fuzzer-all: libelf.a libelf-fuzzer.o + +# Common targets +.PHONY: all +all: libelf-fuzzer-all + +.PHONY: distclean +distclean: clean + +.PHONY: clean +clean: + rm -f *.o *.a diff --git a/tools/fuzz/libelf/libelf-fuzzer.c b/tools/fuzz/libelf/libelf-fuzzer.c new file mode 100644 index 0000000000..71561d3460 --- /dev/null +++ b/tools/fuzz/libelf/libelf-fuzzer.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + struct elf_binary elf_buf, *elf; + struct elf_dom_parms parms; + + elf = &elf_buf; + + memset(elf, 0, sizeof(*elf)); + elf_init(elf, (const char *)data, size); + elf_parse_binary(elf); + elf_xen_parse(elf, &parms); + + return 0; +} + + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/libelf/libelf-private.h b/xen/common/libelf/libelf-private.h index 388c3da34d..47db679966 100644 --- a/xen/common/libelf/libelf-private.h +++ b/xen/common/libelf/libelf-private.h @@ -72,8 +72,10 @@ #include #include +#ifndef FUZZ_NO_LIBXC #include "xenctrl.h" #include "xc_private.h" +#endif #define elf_msg(elf, fmt, args ... ) \ elf_call_log_callback(elf, 0, fmt , ## args );