llvm-project/compiler-rt/test/dfsan/origin_invalid.c
Fangrui Song de5416cb59 [dfsan] Support Linux AArch64
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake:ALL_DFSAN_SUPPORTED_ARCH
allows AArch64 but currently the instrumentation will crash.

Port Linux AArch64 memory mappings from msan but use
SizeClassAllocator64 for a slightly more efficient allocator (used by
asan/lsan). Change dfsan/lit.cfg.py to allow Linux aarch64. All tests
should pass.

* dfsan/origin_invalid.c uses x86_64 assembly. Just make it x86_64 specific.
* dfsan/interceptors.c our mallinfo interceptor takes an argument
  instead of returning a struct. This does not work on AArch64 which
  uses different registers for the two function types. Disable AArch64
  as msan/Linux/mallinfo.cpp does.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140770
2023-01-03 13:17:39 -08:00

26 lines
901 B
C

// REQUIRES: target={{x86_64-.*}}
// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
// RUN: %run %t >%t.out 2>&1
// RUN: FileCheck %s < %t.out
#include <sanitizer/dfsan_interface.h>
int main(int argc, char *argv[]) {
uint64_t a = 10;
dfsan_set_label(1, &a, sizeof(a));
// 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.
asm("mov %0, %%rax": :"r"(origin_addr));
asm("movq $0, (%rax)");
dfsan_print_origin_trace(&a, "invalid");
}
// CHECK: Taint value 0x1 (at {{.*}}) origin tracking (invalid)
// CHECK: Taint value 0x1 (at {{.*}}) has invalid origin tracking. This can be a DFSan bug.