[PATCH] D35704: added reset feature to dfsan
Farah Hariri via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 20 15:47:16 PDT 2017
farahhariri created this revision.
Adding reset feature to dfsan. This is especially needed in the context of fuzzing. Otherwise, we would run out of labels very fast.
https://reviews.llvm.org/D35704
Files:
include/sanitizer/dfsan_interface.h
lib/dfsan/dfsan.cc
lib/dfsan/dfsan.h
lib/dfsan/done_abilist.txt
test/dfsan/reset.cc
Index: test/dfsan/reset.cc
===================================================================
--- /dev/null
+++ test/dfsan/reset.cc
@@ -0,0 +1,22 @@
+// RUN: %clang_dfsan %s -o %t && %run %t
+// RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t && %run %t
+
+// Tests that dfsan runtime is reset correctly.
+
+#include <sanitizer/dfsan_interface.h>
+#include <assert.h>
+
+int main(void) {
+ int i = 1;
+ int j = 1;
+ dfsan_label i_label = dfsan_create_label("i", 0);
+ dfsan_set_label(i_label, &i, sizeof(i));
+ dfsan_label j_label = dfsan_create_label("j", 0);
+ dfsan_add_label(j_label, &j, sizeof(j));
+ assert(dfsan_get_label_count() == 2);
+
+ dfsan_reset();
+ assert(dfsan_get_label_count() == 0);
+
+ return 0;
+}
Index: lib/dfsan/done_abilist.txt
===================================================================
--- lib/dfsan/done_abilist.txt
+++ lib/dfsan/done_abilist.txt
@@ -6,6 +6,8 @@
###############################################################################
fun:dfsan_union=uninstrumented
fun:dfsan_union=discard
+fun:dfsan_reset=uninstrumented
+fun:dfsan_reset=discard
fun:dfsan_create_label=uninstrumented
fun:dfsan_create_label=discard
fun:dfsan_set_label=uninstrumented
Index: lib/dfsan/dfsan.h
===================================================================
--- lib/dfsan/dfsan.h
+++ lib/dfsan/dfsan.h
@@ -34,6 +34,7 @@
extern "C" {
void dfsan_add_label(dfsan_label label, void *addr, uptr size);
void dfsan_set_label(dfsan_label label, void *addr, uptr size);
+void dfsan_reset(void);
dfsan_label dfsan_read_label(const void *addr, uptr size);
dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
} // extern "C"
Index: lib/dfsan/dfsan.cc
===================================================================
--- lib/dfsan/dfsan.cc
+++ lib/dfsan/dfsan.cc
@@ -158,6 +158,27 @@
}
}
+// Reset labels and shadow memory for dfsan to restart from clean.
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE
+void dfsan_reset(void) {
+ // reset shadow memory
+ MmapFixedNoReserve(ShadowAddr(), UnusedAddr() - ShadowAddr());
+
+ dfsan_label last_label =
+ atomic_load(&__dfsan_last_label, memory_order_relaxed);
+
+ // reset potentially polluted union table entries
+ for (uptr l = 0; l <= last_label; ++l) {
+ for (uptr m = 0; m <= last_label; ++m) {
+ atomic_dfsan_label *table_ent = union_table(l, m);
+ dfsan_label label = 0;
+ atomic_store(table_ent, label, memory_order_acquire);
+ }
+ }
+ // reset label count
+ atomic_store(&__dfsan_last_label, 0, memory_order_relaxed);
+}
+
// Resolves the union of two unequal labels. Nonequality is a precondition for
// this function (the instrumentation pass inlines the equality test).
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
Index: include/sanitizer/dfsan_interface.h
===================================================================
--- include/sanitizer/dfsan_interface.h
+++ include/sanitizer/dfsan_interface.h
@@ -52,6 +52,9 @@
/// Sets the label for each address in [addr,addr+size) to \c label.
void dfsan_set_label(dfsan_label label, void *addr, size_t size);
+/// In process reset of dfsan
+void dfsan_reset(void);
+
/// Sets the label for each address in [addr,addr+size) to the union of the
/// current label for that address and \c label.
void dfsan_add_label(dfsan_label label, void *addr, size_t size);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35704.107598.patch
Type: text/x-patch
Size: 3360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170720/6cd67083/attachment.bin>
More information about the llvm-commits
mailing list