This is an archive of the discontinued LLVM Phabricator instance.

[libc] add exception to atof differential fuzz
ClosedPublic

Authored by michaelrj on Apr 27 2023, 10:45 AM.

Details

Summary

The differential fuzzer for atof found a bug in glibc's handling of
hexadecimal rounding. Since we can't easily update glibc and we want to
avoid false positives when running the fuzzer, I've added an exception
to skip all hexadecimal subnormal cases.

Diff Detail

Event Timeline

michaelrj created this revision.Apr 27 2023, 10:45 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 27 2023, 10:45 AM
michaelrj requested review of this revision.Apr 27 2023, 10:45 AM
sivachandra added inline comments.Apr 27 2023, 11:21 AM
libc/fuzzing/stdlib/atof_differential_fuzz.cpp
41

Can there be a way to do this without using __llvm_libc::atof?

michaelrj added inline comments.Apr 27 2023, 12:06 PM
libc/fuzzing/stdlib/atof_differential_fuzz.cpp
41

Not really. We need to use some version of atof, either the system's or ours. The thing we're trying to detect here is hexadecimal subnormals, and the process for checking that is exactly the process for converting a string to a float.

sivachandra added inline comments.Apr 27 2023, 12:34 PM
libc/fuzzing/stdlib/atof_differential_fuzz.cpp
41

Let me rephrase my question: can you detect problem inputs using the system libc atof?

michaelrj updated this revision to Diff 517698.Apr 27 2023, 1:41 PM
michaelrj marked 2 inline comments as done.

switch to system atof for exception detection.

libc/fuzzing/stdlib/atof_differential_fuzz.cpp
41

yes, either atof will work.

sivachandra added inline comments.Apr 27 2023, 11:42 PM
libc/fuzzing/stdlib/atof_differential_fuzz.cpp
22

A normal way to do this would be to:

#ifdef LLVM_LIBC_...
...
#else
...
#endif

And, let users define that macro in the build system. Also, the name of the macro can be more suggestive I think: LLVM_LIBC_ATOF_DIF_FUZZ_SKIP_GLIBC_HEX_SUBNORMAL_ERR.

54

If the skip check function can take the size argument, can we skip before making the copy.

michaelrj marked 2 inline comments as done.

address comments

libc/fuzzing/stdlib/atof_differential_fuzz.cpp
54

not really, we need to add the null terminator to the string and to do that we need to copy it into something we can modify.

sivachandra accepted this revision.Apr 28 2023, 11:16 AM
This revision is now accepted and ready to land.Apr 28 2023, 11:16 AM
This revision was automatically updated to reflect the committed changes.