Previously on x86_64: +--------------------+ 0x800000000000 (top of memory) | application memory | +--------------------+ 0x700000008000 (kAppAddr) | | | unused | | | +--------------------+ 0x300000000000 (kUnusedAddr) | origin | +--------------------+ 0x200000008000 (kOriginAddr) | unused | +--------------------+ 0x200000000000 | shadow memory | +--------------------+ 0x100000008000 (kShadowAddr) | unused | +--------------------+ 0x000000010000 | reserved by kernel | +--------------------+ 0x000000000000 MEM_TO_SHADOW(mem) = mem & ~0x600000000000 SHADOW_TO_ORIGIN(shadow) = kOriginAddr - kShadowAddr + shadow Now for x86_64: +--------------------+ 0x800000000000 (top of memory) | application 3 | +--------------------+ 0x700000000000 | invalid | +--------------------+ 0x610000000000 | origin 1 | +--------------------+ 0x600000000000 | application 2 | +--------------------+ 0x510000000000 | shadow 1 | +--------------------+ 0x500000000000 | invalid | +--------------------+ 0x400000000000 | origin 3 | +--------------------+ 0x300000000000 | shadow 3 | +--------------------+ 0x200000000000 | origin 2 | +--------------------+ 0x110000000000 | invalid | +--------------------+ 0x100000000000 | shadow 2 | +--------------------+ 0x010000000000 | application 1 | +--------------------+ 0x000000000000 MEM_TO_SHADOW(mem) = mem ^ 0x500000000000 SHADOW_TO_ORIGIN(shadow) = shadow + 0x100000000000 Reviewed By: stephan.yichao.zhao, gbalats Differential Revision: https://reviews.llvm.org/D104896
27 lines
903 B
C
27 lines
903 B
C
// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
|
|
// RUN: %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s < %t.out
|
|
//
|
|
// REQUIRES: x86_64-target-arch
|
|
|
|
#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.
|