]> git.puffer.fish Git - mirror/frr.git/commit
enable libfuzzer for bgpd
authorQuentin Young <qlyoung@cumulusnetworks.com>
Sat, 11 Jan 2020 03:20:33 +0000 (22:20 -0500)
committerQuentin Young <qlyoung@nvidia.com>
Mon, 15 Nov 2021 19:52:42 +0000 (14:52 -0500)
commit8dc9e729cc2a82776d9a880835ad3ab70c1d55c6
tree45d161873b919f37cb0fd45b8d174a2836a0b81e
parent0de6c4cced1a1b1b37a788fa0f0a349cfda3e505
enable libfuzzer for bgpd

Wow that was painful

libFuzzer replaces main(), so while we can compile with
-fsanitize=fuzzer, we can't link with it unless we have a way to
undefine main(). So I've added a #define, FUZZING_LIBFUZZER, that
daemons who want to support libfuzzer need to guard their main() with.
This also means we can't use the SAN_FLAGS automake variable, since that
is included in both AM_CFLAGS and AM_LDFLAGS, to add -fsanitize=fuzzer
to. We need new daemon specific flags. Actually, we can add
-fsanitize=fuzzer-no-link to SAN_FLAGS, but we need daemon specific
LDFLAGS so we can control who links with -fsanitize=fuzzer.

Also, compiling with libfuzzer also requires that you define a function
named LLVMFuzzerTestOneInput(). So I defined a stub version in libfrr.c
and added a macro to undefine it for daemons who actually implement it.
Now that I write it down this probably isn't necessary at all given the
previous paragraph. I think that function is only checked for at link
time.

For bgpd, because libfuzzer is in-process, we now need to actuall clean
up after ourselves each fuzz run to avoid leaking memory.  We also can't
touch global state. This also means we run slower because we have to
create and destroy a peer struct every iteration.

Finally I've almost certainly broken afl for now, will fix later.
bgpd/bgp_io.c
bgpd/bgp_keepalives.c
bgpd/bgp_main.c
bgpd/subdir.am
configure.ac
lib/libfrr.c