Skip to content

[libfuzzer] Prevent MSan false positive when printing log with -jobs #91679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2024

Conversation

thurstond
Copy link
Contributor

@thurstond thurstond commented May 9, 2024

libfuzzer's -jobs option will, depending on the number of CPUs, spin up a
WorkerThread and end up printing the log file using CopyFileToErr.
This leads to an MSan false positive. This patch disables the MSan interceptor checks,
similarly to other instances in https://reviews.llvm.org/D48891

Side-note: this false positive issue first appeared when printf()
was replaced by puts() (90b4d1b).
The interceptor check was always present; however, MSan does not
check_printf by default.

The -jobs option will, depending on the number of CPUs, spin up a
WorkerThread and end up printing the log file using CopyFileToErr.
This leads to an MSan false positive. This patch disables the MSan interceptor checks,
similarly to other instances in https://reviews.llvm.org/D48891

Side-note: this false positive issue first appeared when printf()
was replaced by puts() (90b4d1b).
The interceptor check was always present; however, MSan does not
check_printf by default.
@llvmbot
Copy link
Member

llvmbot commented May 9, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Thurston Dang (thurstond)

Changes

The -jobs option will, depending on the number of CPUs, spin up a
WorkerThread and end up printing the log file using CopyFileToErr.
This leads to an MSan false positive. This patch disables the MSan interceptor checks,
similarly to other instances in https://reviews.llvm.org/D48891

Side-note: this false positive issue first appeared when printf()
was replaced by puts() (90b4d1b).
The interceptor check was always present; however, MSan does not
check_printf by default.


Full diff: https://github.com/llvm/llvm-project/pull/91679.diff

1 Files Affected:

  • (modified) compiler-rt/lib/fuzzer/FuzzerIO.cpp (+2)
diff --git a/compiler-rt/lib/fuzzer/FuzzerIO.cpp b/compiler-rt/lib/fuzzer/FuzzerIO.cpp
index 54cc4ee54be0a..9e9a93a0a48da 100644
--- a/compiler-rt/lib/fuzzer/FuzzerIO.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerIO.cpp
@@ -10,6 +10,7 @@
 
 #include "FuzzerDefs.h"
 #include "FuzzerExtFunctions.h"
+#include "FuzzerInternal.h"
 #include "FuzzerIO.h"
 #include "FuzzerUtil.h"
 #include <algorithm>
@@ -65,6 +66,7 @@ std::string FileToString(const std::string &Path) {
 }
 
 void CopyFileToErr(const std::string &Path) {
+  ScopedDisableMsanInterceptorChecks S;
   Puts(FileToString(Path).c_str());
 }
 

Copy link

github-actions bot commented May 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@eugenis
Copy link
Contributor

eugenis commented May 10, 2024

This looks reasonable, but I wonder if it would be safer to move the scoped-disable thing to the start of WorkerThread? The thread does not run any user code, so we never want any interceptor checks (and it may run some other interceptors, like fork/exec, mutex stuff, etc).

Copy link
Member

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@thurstond
Copy link
Contributor Author

This looks reasonable, but I wonder if it would be safer to move the scoped-disable thing to the start of WorkerThread? The thread does not run any user code, so we never want any interceptor checks (and it may run some other interceptors, like fork/exec, mutex stuff, etc).

Done, thanks for the review!

@thurstond thurstond merged commit d9ce33a into llvm:main May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants