[compiler-rt] r363321 - [dfsan] Introduce dfsan_flush().

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 13:11:07 PDT 2019


Author: kcc
Date: Thu Jun 13 13:11:06 2019
New Revision: 363321

URL: http://llvm.org/viewvc/llvm-project?rev=363321&view=rev
Log:
[dfsan] Introduce dfsan_flush().

Summary:
dfsan_flush() allows to restart tain tracking from scratch in the same process.
The primary purpose right now is to allow more efficient data flow tracing
for DFT fuzzing: https://github.com/google/oss-fuzz/issues/1632

Reviewers: pcc

Reviewed By: pcc

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

Added:
    compiler-rt/trunk/test/dfsan/flush.c
Modified:
    compiler-rt/trunk/include/sanitizer/dfsan_interface.h
    compiler-rt/trunk/lib/dfsan/dfsan.cc
    compiler-rt/trunk/lib/dfsan/done_abilist.txt

Modified: compiler-rt/trunk/include/sanitizer/dfsan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/dfsan_interface.h?rev=363321&r1=363320&r2=363321&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/dfsan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/dfsan_interface.h Thu Jun 13 13:11:06 2019
@@ -79,6 +79,12 @@ dfsan_label dfsan_has_label_with_desc(df
 /// Returns the number of labels allocated.
 size_t dfsan_get_label_count(void);
 
+/// Flushes the DFSan shadow, i.e. forgets about all labels currently associated
+/// with the application memory. Will work only if there are no other
+/// threads executing DFSan-instrumented code concurrently.
+/// Use this call to start over the taint tracking within the same procces.
+void dfsan_flush(void);
+
 /// Sets a callback to be invoked on calls to write().  The callback is invoked
 /// before the write is done.  The write is not guaranteed to succeed when the
 /// callback executes.  Pass in NULL to remove any callback.

Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=363321&r1=363320&r2=363321&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Thu Jun 13 13:11:06 2019
@@ -421,6 +421,12 @@ static void dfsan_fini() {
   }
 }
 
+extern "C" void dfsan_flush() {
+  UnmapOrDie((void*)ShadowAddr(), UnusedAddr() - ShadowAddr());
+  if (!MmapFixedNoReserve(ShadowAddr(), UnusedAddr() - ShadowAddr()))
+    Die();
+}
+
 static void dfsan_init(int argc, char **argv, char **envp) {
   InitializeFlags();
 

Modified: compiler-rt/trunk/lib/dfsan/done_abilist.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/done_abilist.txt?rev=363321&r1=363320&r2=363321&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/done_abilist.txt (original)
+++ compiler-rt/trunk/lib/dfsan/done_abilist.txt Thu Jun 13 13:11:06 2019
@@ -26,6 +26,8 @@ fun:dfsan_has_label_with_desc=uninstrume
 fun:dfsan_has_label_with_desc=discard
 fun:dfsan_set_write_callback=uninstrumented
 fun:dfsan_set_write_callback=custom
+fun:dfsan_flush=uninstrumented
+fun:dfsan_flush=discard
 
 ###############################################################################
 # glibc

Added: compiler-rt/trunk/test/dfsan/flush.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/dfsan/flush.c?rev=363321&view=auto
==============================================================================
--- compiler-rt/trunk/test/dfsan/flush.c (added)
+++ compiler-rt/trunk/test/dfsan/flush.c Thu Jun 13 13:11:06 2019
@@ -0,0 +1,28 @@
+// Tests dfsan_flush().
+// RUN: %clang_dfsan %s -o %t && %run %t
+#include <sanitizer/dfsan_interface.h>
+#include <assert.h>
+#include <stdlib.h>
+
+int global;
+
+int main() {
+  int local;
+  int *heap = (int*)malloc(sizeof(int));
+
+  dfsan_set_label(10, &global, sizeof(global));
+  dfsan_set_label(20, &local, sizeof(local));
+  dfsan_set_label(30, heap, sizeof(*heap));
+
+  assert(dfsan_get_label(global) == 10);
+  assert(dfsan_get_label(local) == 20);
+  assert(dfsan_get_label(*heap) == 30);
+
+  dfsan_flush();
+
+  assert(dfsan_get_label(global) == 0);
+  assert(dfsan_get_label(local) == 0);
+  assert(dfsan_get_label(*heap) == 0);
+
+  free(heap);
+}




More information about the llvm-commits mailing list