google / sanitizers

AddressSanitizer, ThreadSanitizer, MemorySanitizer
Other
11.01k stars 998 forks source link

MSAN+libfuzzer reports error in libfuzzer code with '-jobs=X' (Uninitialized bytes in fputs) #1725

Open hannob opened 5 months ago

hannob commented 5 months ago

I am trying to track down a strange bug, it appears msan detects an error in libfuzzer's own code.

I reduced it to a minimal testcase, with a fuzz target that does nothing:

#include <stddef.h>
#include <stdint.h>
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  return 0;
}

Save as test.c, compile:

clang -fsanitize=memory,fuzzer test.c -o test

Run on any random input file:

touch empty
./test -jobs=1 empty

(1 is just an example, any other value works, just needs -jobs=n)

Output:

================== Job 0 exited with exit code 0 ============
Uninitialized bytes in fputs at offset 15 inside [0x718000000000, 609)
==2381==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5600b0ddd207 in fuzzer::CopyFileToErr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) (/tmp/t/test+0x4e207)
    #1 0x5600b0dd0fc6 in fuzzer::WorkerThread(fuzzer::Command const&, std::atomic<unsigned int>*, unsigned int, std::atomic<bool>*) FuzzerDriver.cpp.o
    #2 0x7fd02e7c394e  (/usr/lib/gcc/x86_64-pc-linux-gnu/13/libstdc++.so.6+0xe194e)
    #3 0x7fd02e47e9e8 in start_thread /var/tmp/portage/sys-libs/glibc-2.38-r9/work/glibc-2.38/nptl/pthread_create.c:444:8
    #4 0x7fd02e500ee7 in clone3 /var/tmp/portage/sys-libs/glibc-2.38-r9/work/glibc-2.38/misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/t/test+0x4e207) in fuzzer::CopyFileToErr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)

I have reproduced this independently in ubuntu and gentoo, so unlikely to be a distro issue.

(FWIW, here is where this showed up in a CI test: https://github.com/libexpat/libexpat/actions/runs/7575499089/job/20632233670 )

hartwork commented 5 months ago

It does not even seem to need -jobs=1, I get the same with -jobs=4 locally and it was -jobs=4 also in the CI run linked above. But that's a detail, thanks for taking this upstream! :+1: :+1:

I think it's fair to say that that makes fuzzing with MemorySanitizer tricky at best. Would be great to get fixed.