Re: [PATCH 1/3] Build target for emulate.o as a userspace binary
From: samcacc
Date: Wed Jun 12 2019 - 11:24:31 EST
On 5/31/19 10:02 AM, Alexander Graf wrote:
>
> On 21.05.19 17:39, Sam Caccavale wrote:
>> This commit contains the minimal set of functionality to build
>> afl-harness around arch/x86/emulate.c which allows exercising code
>> in that source file, like x86_emulate_insn. Resolving the
>> dependencies was done via GCC's -H flag by get_headers.py.
>>
>> ---
>> Â tools/MakefileÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 9 ++
>> Â .../fuzz/x86_instruction_emulation/.gitignore |ÂÂ 2 +
>> Â tools/fuzz/x86_instruction_emulation/Makefile |Â 57 +++++++
>>  .../fuzz/x86_instruction_emulation/README.md | 12 ++
>> Â .../x86_instruction_emulation/afl-harness.cÂÂ | 149 ++++++++++++++++++
>> Â tools/fuzz/x86_instruction_emulation/common.h |Â 87 ++++++++++
>>  .../x86_instruction_emulation/emulator_ops.c | 58 +++++++
>>  .../x86_instruction_emulation/emulator_ops.h | 117 ++++++++++++++
>> Â .../scripts/get_headers.pyÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |Â 95 +++++++++++
>> Â .../scripts/make_depsÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 4 +
>>  tools/fuzz/x86_instruction_emulation/stubs.c | 56 +++++++
>>  tools/fuzz/x86_instruction_emulation/stubs.h | 52 ++++++
>> Â 12 files changed, 698 insertions(+)
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/.gitignore
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/Makefile
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/README.md
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/afl-harness.c
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/common.h
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/emulator_ops.c
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/emulator_ops.h
>> Â create mode 100644
>> tools/fuzz/x86_instruction_emulation/scripts/get_headers.py
>> Â create mode 100755
>> tools/fuzz/x86_instruction_emulation/scripts/make_deps
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/stubs.c
>> Â create mode 100644 tools/fuzz/x86_instruction_emulation/stubs.h
>>
>> diff --git a/tools/Makefile b/tools/Makefile
>> index 3dfd72ae6c1a..4d68817b7e49 100644
>> --- a/tools/Makefile
>> +++ b/tools/Makefile
>> @@ -94,6 +94,12 @@ freefall: FORCE
>> Â kvm_stat: FORCE
>> ÂÂÂÂÂ $(call descend,kvm/$@)
>> Â +fuzz: FORCE
>> +ÂÂÂ $(call descend,fuzz/x86_instruction_emulation)
>> +
>> +fuzz_deps: FORCE
>> +ÂÂÂ $(call descend,fuzz/x86_instruction_emulation,fuzz_deps)
>> +
>> Â all: acpi cgroup cpupower gpio hv firewire liblockdep \
>> ÂÂÂÂÂÂÂÂÂ perf selftests spi turbostat usb \
>> ÂÂÂÂÂÂÂÂÂ virtio vm bpf x86_energy_perf_policy \
>> @@ -171,6 +177,9 @@ tmon_clean:
>> Â freefall_clean:
>> ÂÂÂÂÂ $(call descend,laptop/freefall,clean)
>> Â +fuzz_clean:
>> +ÂÂÂ $(call descend,fuzz/x86_instruction_emulation,clean)
>> +
>> Â build_clean:
>> ÂÂÂÂÂ $(call descend,build,clean)
>> Â diff --git a/tools/fuzz/x86_instruction_emulation/.gitignore
>> b/tools/fuzz/x86_instruction_emulation/.gitignore
>> new file mode 100644
>> index 000000000000..7d44f7ce266e
>> --- /dev/null
>> +++ b/tools/fuzz/x86_instruction_emulation/.gitignore
>> @@ -0,0 +1,2 @@
>> +*.o
>> +*-harness
>> diff --git a/tools/fuzz/x86_instruction_emulation/Makefile
>> b/tools/fuzz/x86_instruction_emulation/Makefile
>> new file mode 100644
>> index 000000000000..d2854a332605
>> --- /dev/null
>> +++ b/tools/fuzz/x86_instruction_emulation/Makefile
>> @@ -0,0 +1,57 @@
>> +ROOT_DIR=../../..
>> +THIS_DIR=tools/fuzz/x86_instruction_emulation
>> +
>> +include ../../scripts/Makefile.include
>> +
>> +.DEFAULT_GOAL := all
>> +
>> +INCLUDES := $(patsubst -I./%,-I./$(ROOT_DIR)/%, $(LINUXINCLUDE))
>> +INCLUDES := $(patsubst ./include/%,./$(ROOT_DIR)/include/%, $(INCLUDES))
>> +INCLUDES += -include ./$(ROOT_DIR)/include/linux/compiler_types.h
>> +
>> +$(ROOT_DIR)/.config:
>> +ÂÂÂ make -C $(ROOT_DIR) menuconfig
>> +ÂÂÂ sed -i -r 's/^#? *CONFIG_KVM(.*)=.*/CONFIG_KVM\1=y/'
>> $(ROOT_DIR)/.config
>> +
>> +
>> +ifdef DEBUG
>> +KBUILD_CFLAGS += -DDEBUG
>> +endif
>> +KBUILD_CFLAGS += -g -O0
>
>
> Why -O0? I would expect a some bugs to only emerge with optimization
> enabled.
>
> Alex
>
This was supposed to be the `ifdef` actually. Fixed in v2.
Sam