[compiler-rt] r360390 - [libFuzzer] Unpoison parameters before calling user callback.

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Thu May 9 15:48:47 PDT 2019


Author: morehouse
Date: Thu May  9 15:48:46 2019
New Revision: 360390

URL: http://llvm.org/viewvc/llvm-project?rev=360390&view=rev
Log:
[libFuzzer] Unpoison parameters before calling user callback.

Summary:
Fixes an MSan false positive when compiling with
-fsanitize=memory,fuzzer.

See https://github.com/google/oss-fuzz/issues/2369 for more details.

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits, metzman, eugenis

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D61753

Added:
    compiler-rt/trunk/test/fuzzer/MsanParamUnpoison.cpp
    compiler-rt/trunk/test/fuzzer/msan-param-unpoison.test
Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctions.def
    compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctions.def
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctions.def?rev=360390&r1=360389&r2=360390&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctions.def (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctions.def Thu May  9 15:48:46 2019
@@ -46,3 +46,4 @@ EXT_FUNC(__sanitizer_set_report_fd, void
 EXT_FUNC(__msan_scoped_disable_interceptor_checks, void, (), false);
 EXT_FUNC(__msan_scoped_enable_interceptor_checks, void, (), false);
 EXT_FUNC(__msan_unpoison, void, (const volatile void *, size_t size), false);
+EXT_FUNC(__msan_unpoison_param, void, (size_t n), false);

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp?rev=360390&r1=360389&r2=360390&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp Thu May  9 15:48:46 2019
@@ -542,6 +542,8 @@ void Fuzzer::ExecuteCallback(const uint8
   memcpy(DataCopy, Data, Size);
   if (EF->__msan_unpoison)
     EF->__msan_unpoison(DataCopy, Size);
+  if (EF->__msan_unpoison_param)
+    EF->__msan_unpoison_param(2);
   if (CurrentUnitData && CurrentUnitData != Data)
     memcpy(CurrentUnitData, Data, Size);
   CurrentUnitSize = Size;
@@ -702,7 +704,7 @@ void Fuzzer::MutateAndTestOne() {
       break;  // We will mutate this input more in the next rounds.
     }
     if (Options.ReduceDepth && !FoundUniqFeatures)
-        break;
+      break;
   }
 }
 

Added: compiler-rt/trunk/test/fuzzer/MsanParamUnpoison.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/MsanParamUnpoison.cpp?rev=360390&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/MsanParamUnpoison.cpp (added)
+++ compiler-rt/trunk/test/fuzzer/MsanParamUnpoison.cpp Thu May  9 15:48:46 2019
@@ -0,0 +1,28 @@
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Triggers the bug described here:
+// https://github.com/google/oss-fuzz/issues/2369#issuecomment-490240627
+//
+// In a nutshell, MSan's parameter shadow does not get unpoisoned before calls
+// to LLVMFuzzerTestOneInput.  This test case causes the parameter shadow to be
+// poisoned by the call to foo(), which will trigger an MSan false positive on
+// the Size == 0 check if the parameter shadow is still poisoned.
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+volatile int zero = 0;
+__attribute__((noinline)) int foo(int arg1, int arg2) { return zero; }
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  if (Size == 0)
+    return 0;
+
+  // Pass uninitialized values to foo().  Since foo doesn't do anything with
+  // them, MSan should not report an error here.
+  int a, b;
+  return foo(a, b);
+}

Added: compiler-rt/trunk/test/fuzzer/msan-param-unpoison.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/msan-param-unpoison.test?rev=360390&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/msan-param-unpoison.test (added)
+++ compiler-rt/trunk/test/fuzzer/msan-param-unpoison.test Thu May  9 15:48:46 2019
@@ -0,0 +1,5 @@
+REQUIRES: msan
+RUN: %msan_compiler %S/MsanParamUnpoison.cpp -o %t
+RUN: %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s
+
+CHECK-NOT: MemorySanitizer: use-of-uninitialized-value




More information about the llvm-commits mailing list