diff mbox series

[ovs-dev,1/2] oss-fuzz: Fix fuzzer flags in CFLAGS.

Message ID 1589296951-75730-1-git-send-email-u9012063@gmail.com
State Rejected
Headers show
Series [ovs-dev,1/2] oss-fuzz: Fix fuzzer flags in CFLAGS. | expand

Commit Message

William Tu May 12, 2020, 3:22 p.m. UTC
When running fuzzer locally by doing
 $ ./configure CC=clang CFLAGS="-g -O2 -fsanitize=fuzzer-no-link -Werror"
 $ make oss-fuzz-targets
fails due to "(.text+0x20): undefined reference to `main'"

The patch fixes it by replacing "fuzzer-no-link" to "fuzzer" so the
binary under tests/oss-fuzz/ can be generated.

Cc: Bhargava Shastry <bshastry@sect.tu-berlin.de>
Cc: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: William Tu <u9012063@gmail.com>
---
 tests/oss-fuzz/automake.mk | 3 +++
 1 file changed, 3 insertions(+)

Comments

Ilya Maximets May 12, 2020, 3:40 p.m. UTC | #1
On 5/12/20 5:22 PM, William Tu wrote:
> When running fuzzer locally by doing
>  $ ./configure CC=clang CFLAGS="-g -O2 -fsanitize=fuzzer-no-link -Werror"

Hmm... Why passing 'fuzzer-no-link' to replace it inside the make script?

>  $ make oss-fuzz-targets

AFAIK, oss-fuzz-targets are for Google's oss-fuzz project and not for
local usage.

> fails due to "(.text+0x20): undefined reference to `main'"
> 
> The patch fixes it by replacing "fuzzer-no-link" to "fuzzer" so the
> binary under tests/oss-fuzz/ can be generated.
> 
> Cc: Bhargava Shastry <bshastry@sect.tu-berlin.de>
> Cc: Yifeng Sun <pkusunyifeng@gmail.com>
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
>  tests/oss-fuzz/automake.mk | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tests/oss-fuzz/automake.mk b/tests/oss-fuzz/automake.mk
> index 2b116e7a51a1..66a5c3037f5d 100644
> --- a/tests/oss-fuzz/automake.mk
> +++ b/tests/oss-fuzz/automake.mk
> @@ -8,6 +8,9 @@ OSS_FUZZ_TARGETS = \
>  EXTRA_PROGRAMS += $(OSS_FUZZ_TARGETS)
>  oss-fuzz-targets: $(OSS_FUZZ_TARGETS)
>  
> +CFLAGS_FUZZER:=$(CFLAGS:fuzzer-no-link=fuzzer)
> +override CFLAGS=$(CFLAGS_FUZZER)
> +
>  tests_oss_fuzz_flow_extract_target_SOURCES = \
>  	tests/oss-fuzz/flow_extract_target.c \
>  	tests/oss-fuzz/fuzzer.h
>
William Tu May 12, 2020, 3:44 p.m. UTC | #2
Thanks for taking a look.

On Tue, May 12, 2020 at 8:41 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> On 5/12/20 5:22 PM, William Tu wrote:
> > When running fuzzer locally by doing
> >  $ ./configure CC=clang CFLAGS="-g -O2 -fsanitize=fuzzer-no-link -Werror"
>
> Hmm... Why passing 'fuzzer-no-link' to replace it inside the make script?

the configure fails i`f passing as "-fsanitize=fuzzer"
configure: error: C compiler cannot create executables
See `config.log' for more details

configure:4079: checking whether the C compiler works
configure:4101: clang -g -O2 -fsanitize=fuzzer -Werror   conftest.c  >&5
/tmp/conftest-67bd49.o: In function `main':
/root/ovs/conftest.c:14: multiple definition of `main'
/usr/lib/llvm-8/lib/clang/8.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):FuzzerMain.cpp:(.text.main+0x0):
first defined here
/usr/lib/llvm-8/lib/clang/8.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):
In function `main':
FuzzerMain.cpp:(.text.main+0x12): undefined reference to
`LLVMFuzzerTestOneInput'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:4105: $? = 1
configure:4143: result: no
configure: failed program was:

>
> >  $ make oss-fuzz-targets
>
> AFAIK, oss-fuzz-targets are for Google's oss-fuzz project and not for
> local usage.

We're thinking about adding more tests under tests/oss-fuzz/
so need to make it work locally first.

William
>
> > fails due to "(.text+0x20): undefined reference to `main'"
> >
> > The patch fixes it by replacing "fuzzer-no-link" to "fuzzer" so the
> > binary under tests/oss-fuzz/ can be generated.
> >
> > Cc: Bhargava Shastry <bshastry@sect.tu-berlin.de>
> > Cc: Yifeng Sun <pkusunyifeng@gmail.com>
> > Signed-off-by: William Tu <u9012063@gmail.com>
> > ---
> >  tests/oss-fuzz/automake.mk | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/tests/oss-fuzz/automake.mk b/tests/oss-fuzz/automake.mk
> > index 2b116e7a51a1..66a5c3037f5d 100644
> > --- a/tests/oss-fuzz/automake.mk
> > +++ b/tests/oss-fuzz/automake.mk
> > @@ -8,6 +8,9 @@ OSS_FUZZ_TARGETS = \
> >  EXTRA_PROGRAMS += $(OSS_FUZZ_TARGETS)
> >  oss-fuzz-targets: $(OSS_FUZZ_TARGETS)
> >
> > +CFLAGS_FUZZER:=$(CFLAGS:fuzzer-no-link=fuzzer)
> > +override CFLAGS=$(CFLAGS_FUZZER)
> > +
> >  tests_oss_fuzz_flow_extract_target_SOURCES = \
> >       tests/oss-fuzz/flow_extract_target.c \
> >       tests/oss-fuzz/fuzzer.h
> >
>
William Tu May 13, 2020, 1:06 p.m. UTC | #3
On Tue, May 12, 2020 at 8:44 AM William Tu <u9012063@gmail.com> wrote:
>
> Thanks for taking a look.
>
> On Tue, May 12, 2020 at 8:41 AM Ilya Maximets <i.maximets@ovn.org> wrote:
> >
> > On 5/12/20 5:22 PM, William Tu wrote:
> > > When running fuzzer locally by doing
> > >  $ ./configure CC=clang CFLAGS="-g -O2 -fsanitize=fuzzer-no-link -Werror"
> >
> > Hmm... Why passing 'fuzzer-no-link' to replace it inside the make script?
>
> the configure fails i`f passing as "-fsanitize=fuzzer"
> configure: error: C compiler cannot create executables
> See `config.log' for more details
>
> configure:4079: checking whether the C compiler works
> configure:4101: clang -g -O2 -fsanitize=fuzzer -Werror   conftest.c  >&5
> /tmp/conftest-67bd49.o: In function `main':
> /root/ovs/conftest.c:14: multiple definition of `main'
> /usr/lib/llvm-8/lib/clang/8.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):FuzzerMain.cpp:(.text.main+0x0):
> first defined here
> /usr/lib/llvm-8/lib/clang/8.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):
> In function `main':
> FuzzerMain.cpp:(.text.main+0x12): undefined reference to
> `LLVMFuzzerTestOneInput'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> configure:4105: $? = 1
> configure:4143: result: no
> configure: failed program was:
>
> >
> > >  $ make oss-fuzz-targets
> >
> > AFAIK, oss-fuzz-targets are for Google's oss-fuzz project and not for
> > local usage.
>
> We're thinking about adding more tests under tests/oss-fuzz/
> so need to make it work locally first.
>
Some context:
People told me that using fuzzer can detect integer wraparound/overflow
bug, something like this meter bucket issue.
https://mail.openvswitch.org/pipermail/ovs-dev/2020-May/370291.html

So I start to look at how clang fuzzer works in OVS. It requires us to pick
the fuzzer target function, and in this meter bucket case, it's pretty hard to
do it.

Regards,
William
diff mbox series

Patch

diff --git a/tests/oss-fuzz/automake.mk b/tests/oss-fuzz/automake.mk
index 2b116e7a51a1..66a5c3037f5d 100644
--- a/tests/oss-fuzz/automake.mk
+++ b/tests/oss-fuzz/automake.mk
@@ -8,6 +8,9 @@  OSS_FUZZ_TARGETS = \
 EXTRA_PROGRAMS += $(OSS_FUZZ_TARGETS)
 oss-fuzz-targets: $(OSS_FUZZ_TARGETS)
 
+CFLAGS_FUZZER:=$(CFLAGS:fuzzer-no-link=fuzzer)
+override CFLAGS=$(CFLAGS_FUZZER)
+
 tests_oss_fuzz_flow_extract_target_SOURCES = \
 	tests/oss-fuzz/flow_extract_target.c \
 	tests/oss-fuzz/fuzzer.h