brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 865b37c Raw
60 lines · c
1// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,WITHOUT %s2// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=memory | FileCheck -check-prefixes CHECK,MSAN %s3// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=kernel-memory | FileCheck -check-prefixes CHECK,KMSAN %s4// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - %s -fsanitize=memory -fno-sanitize-memory-param-retval | FileCheck -check-prefixes CHECK,MSAN,RETTLS %s5 6// Instrumented function.7// MSan uses memset(addr, -1, size) to poison allocas and stores shadow of the return value in8// __msan_retval_tls. KMSAN uses __msan_poison_alloca() to poison allocas and calls9// __msan_get_context_state() at function prologue to access the task context struct (including the10// shadow of the return value).11//12// CHECK-LABEL: i32 @instrumented113// KMSAN: __msan_get_context_state14// WITHOUT-NOT: __msan_poison_alloca15// WITHOUT-NOT: @llvm.memset16// MSAN: @llvm.memset{{.*}}({{.*}}, i8 -117// KMSAN: __msan_poison_alloca18// WITHOUT-NOT: __msan_retval_tls19// RETTLS: __msan_retval_tls20// CHECK: ret i3221int instrumented1(int *a) {22  volatile char buf[8];23  return *a;24}25 26// Function with no_sanitize("memory")/no_sanitize("kernel-memory"): no shadow propagation, but27// unpoisons memory to prevent false positives.28// MSan uses memset(addr, 0, size) to unpoison locals, KMSAN uses __msan_unpoison_alloca(). Both29// tools still access the retval shadow to write 0 to it.30//31// CHECK-LABEL: i32 @no_false_positives132// KMSAN: __msan_get_context_state33// WITHOUT-NOT: __msan_unpoison_alloca34// WITHOUT-NOT: @llvm.memset35// MSAN: @llvm.memset{{.*}}({{.*}}, i8 036// KMSAN: __msan_unpoison_alloca37// WITHOUT-NOT: __msan_retval_tls38// RETTLS: __msan_retval_tls39// CHECK: ret i3240__attribute__((no_sanitize("memory"))) __attribute__((no_sanitize("kernel-memory"))) int no_false_positives1(int *a) {41  volatile char buf[8];42  return *a;43}44 45// Function with disable_sanitizer_instrumentation: no instrumentation at all.46//47// CHECK-LABEL: i32 @no_instrumentation148// KMSAN-NOT: __msan_get_context_state49// WITHOUT-NOT: __msan_poison_alloca50// WITHOUT-NOT: @llvm.memset51// MSAN-NOT: @llvm.memset{{.*}}({{.*}}, i8 052// KMSAN-NOT: __msan_unpoison_alloca53// WITHOUT-NOT: __msan_retval_tls54// MSAN-NOT: __msan_retval_tls55// CHECK: ret i3256__attribute__((disable_sanitizer_instrumentation)) int no_instrumentation1(int *a) {57  volatile char buf[8];58  return *a;59}60