[compiler-rt] d39d2ac - [DFSan] Make dfsan_read_origin_of_first_taint public.

Andrew Browne via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 22 23:47:10 PST 2021


Author: Andrew Browne
Date: 2021-12-22T23:45:30-08:00
New Revision: d39d2acfdd9f4d09d29752a75f37e756ddb60764

URL: https://github.com/llvm/llvm-project/commit/d39d2acfdd9f4d09d29752a75f37e756ddb60764
DIFF: https://github.com/llvm/llvm-project/commit/d39d2acfdd9f4d09d29752a75f37e756ddb60764.diff

LOG: [DFSan] Make dfsan_read_origin_of_first_taint public.

Makes origins easier to use with dfsan_read_label(addr, size).

Reviewed By: vitalybuka

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

Added: 
    compiler-rt/test/dfsan/origin_of_first_taint.c

Modified: 
    compiler-rt/include/sanitizer/dfsan_interface.h
    compiler-rt/lib/dfsan/done_abilist.txt

Removed: 
    


################################################################################
diff  --git a/compiler-rt/include/sanitizer/dfsan_interface.h b/compiler-rt/include/sanitizer/dfsan_interface.h
index 769aecfb0d705..bc0652c99a149 100644
--- a/compiler-rt/include/sanitizer/dfsan_interface.h
+++ b/compiler-rt/include/sanitizer/dfsan_interface.h
@@ -54,6 +54,10 @@ dfsan_origin dfsan_get_origin(long data);
 /// Retrieves the label associated with the data at the given address.
 dfsan_label dfsan_read_label(const void *addr, size_t size);
 
+/// Return the origin associated with the first taint byte in the size bytes
+/// from the address addr.
+dfsan_origin dfsan_read_origin_of_first_taint(const void *addr, size_t size);
+
 /// Returns whether the given label label contains the label elem.
 int dfsan_has_label(dfsan_label label, dfsan_label elem);
 

diff  --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index b944b799b152a..fc2dd02ccf5f6 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -40,6 +40,8 @@ fun:dfsan_sprint_stack_trace=uninstrumented
 fun:dfsan_sprint_stack_trace=discard
 fun:dfsan_get_origin=uninstrumented
 fun:dfsan_get_origin=custom
+fun:dfsan_read_origin_of_first_taint=uninstrumented
+fun:dfsan_read_origin_of_first_taint=discard
 fun:dfsan_get_init_origin=uninstrumented
 fun:dfsan_get_init_origin=discard
 fun:dfsan_get_track_origins=uninstrumented

diff  --git a/compiler-rt/test/dfsan/origin_of_first_taint.c b/compiler-rt/test/dfsan/origin_of_first_taint.c
new file mode 100644
index 0000000000000..45cd6146f0314
--- /dev/null
+++ b/compiler-rt/test/dfsan/origin_of_first_taint.c
@@ -0,0 +1,34 @@
+// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
+// RUN:     %run %t 2>&1 | FileCheck %s
+//
+// REQUIRES: x86_64-target-arch
+
+#include <assert.h>
+#include <sanitizer/dfsan_interface.h>
+#include <stdio.h>
+
+__attribute__((noinline)) uint64_t foo(uint64_t a, uint64_t b) { return a + b; }
+
+int main(int argc, char *argv[]) {
+  uint64_t a = 10;
+  uint64_t b = 20;
+  dfsan_set_label(8, &a, sizeof(a));
+  uint64_t c = foo(a, b);
+
+  dfsan_origin c_orig = dfsan_get_origin(c);
+  fprintf(stderr, "c_orig 0x%x\n", c_orig);
+  // CHECK: c_orig 0x[[#%x,C_ORIG:]]
+  assert(c_orig != 0);
+  dfsan_print_origin_id_trace(c_orig);
+  // CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at
+
+  uint64_t d[4] = {1, 2, 3, c};
+  dfsan_origin d_orig = dfsan_read_origin_of_first_taint(d, sizeof(d));
+  fprintf(stderr, "d_orig 0x%x\n", d_orig);
+  // CHECK: d_orig 0x[[#%x,D_ORIG:]]
+  assert(d_orig != 0);
+  dfsan_print_origin_id_trace(d_orig);
+  // CHECK: Origin value: 0x[[#%x,D_ORIG]], Taint value was stored to memory at
+  // CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at
+  return 0;
+}


        


More information about the llvm-commits mailing list