[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
This commit is contained in:
Andrew Browne 2021-12-22 16:56:37 -08:00
parent f66d602c3f
commit d39d2acfdd
3 changed files with 40 additions and 0 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;
}