diff --git a/compiler-rt/include/sanitizer/dfsan_interface.h b/compiler-rt/include/sanitizer/dfsan_interface.h --- a/compiler-rt/include/sanitizer/dfsan_interface.h +++ b/compiler-rt/include/sanitizer/dfsan_interface.h @@ -54,6 +54,10 @@ /// 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 --- 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=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 --- /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 +#include +#include + +__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; +}