2021-06-05 06:34:02 +08:00
|
|
|
// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
|
2021-03-04 10:35:13 +08:00
|
|
|
// RUN: %run %t >%t.out 2>&1
|
2021-06-05 06:34:02 +08:00
|
|
|
// RUN: FileCheck %s < %t.out
|
2021-03-12 04:02:58 +08:00
|
|
|
//
|
|
|
|
// REQUIRES: x86_64-target-arch
|
2021-03-04 10:35:13 +08:00
|
|
|
|
|
|
|
#include <sanitizer/dfsan_interface.h>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
uint64_t a = 10;
|
2021-06-05 06:34:02 +08:00
|
|
|
dfsan_set_label(1, &a, sizeof(a));
|
2021-06-25 13:16:36 +08:00
|
|
|
|
|
|
|
// Manually compute origin address for &a.
|
|
|
|
// See x86 MEM_TO_ORIGIN macro for logic to replicate here.
|
|
|
|
// Alignment is also needed after to MEM_TO_ORIGIN.
|
|
|
|
uint64_t origin_addr =
|
|
|
|
(((uint64_t)&a ^ 0x500000000000ULL) + 0x100000000000ULL) & ~0x3ULL;
|
|
|
|
|
|
|
|
// Take the address we computed, and store 0 in it to mess it up.
|
2021-03-04 10:35:13 +08:00
|
|
|
asm("mov %0, %%rax": :"r"(origin_addr));
|
|
|
|
asm("movq $0, (%rax)");
|
|
|
|
dfsan_print_origin_trace(&a, "invalid");
|
|
|
|
}
|
|
|
|
|
2021-06-05 06:34:02 +08:00
|
|
|
// CHECK: Taint value 0x1 (at {{.*}}) origin tracking (invalid)
|
|
|
|
// CHECK: Taint value 0x1 (at {{.*}}) has invalid origin tracking. This can be a DFSan bug.
|