From b9b73ef9067371fbe78c34e0f3b23d014413a2f8 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Fri, 19 Jun 2015 12:19:07 +0000 Subject: [ASan] Initial support for Kernel AddressSanitizer This patch adds initial support for the -fsanitize=kernel-address flag to Clang. Right now it's quite restricted: only out-of-line instrumentation is supported, globals are not instrumented, some GCC kasan flags are not supported. Using this patch I am able to build and boot the KASan tree with LLVMLinux patches from github.com/ramosian-glider/kasan/tree/kasan_llvmlinux. To disable KASan instrumentation for a certain function attribute((no_sanitize("kernel-address"))) can be used. llvm-svn: 240131 --- clang/test/CodeGen/address-safety-attr-kasan.cpp | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 clang/test/CodeGen/address-safety-attr-kasan.cpp (limited to 'clang/test/CodeGen') diff --git a/clang/test/CodeGen/address-safety-attr-kasan.cpp b/clang/test/CodeGen/address-safety-attr-kasan.cpp new file mode 100644 index 00000000000..c84ba88291d --- /dev/null +++ b/clang/test/CodeGen/address-safety-attr-kasan.cpp @@ -0,0 +1,38 @@ +// Make sure the sanitize_address attribute is emitted when using both ASan and KASan. +// Also document that __attribute__((no_sanitize_address)) doesn't disable KASan instrumentation. + +/// RUN: %clang_cc1 -triple i386-unknown-linux -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-NOASAN %s +/// RUN: %clang_cc1 -triple i386-unknown-linux -fsanitize=address -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-ASAN %s +/// RUN: %clang_cc1 -triple i386-unknown-linux -fsanitize=kernel-address -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-KASAN %s + +int HasSanitizeAddress() { + return 1; +} +// CHECK-NOASAN: {{Function Attrs: nounwind$}} +// CHECK-ASAN: Function Attrs: nounwind sanitize_address +// CHECK-KASAN: Function Attrs: nounwind sanitize_address + +__attribute__((no_sanitize("address"))) +int NoSanitizeQuoteAddress() { + return 0; +} +// CHECK-NOASAN: {{Function Attrs: nounwind$}} +// CHECK-ASAN: {{Function Attrs: nounwind$}} +// CHECK-KASAN: {{Function Attrs: nounwind sanitize_address$}} + +__attribute__((no_sanitize_address)) +int NoSanitizeAddress() { + return 0; +} +// CHECK-NOASAN: {{Function Attrs: nounwind$}} +// CHECK-ASAN: {{Function Attrs: nounwind$}} +// CHECK-KASAN: {{Function Attrs: nounwind sanitize_address$}} + +__attribute__((no_sanitize("kernel-address"))) +int NoSanitizeKernelAddress() { + return 0; +} + +// CHECK-NOASAN: {{Function Attrs: nounwind$}} +// CHECK-ASAN: {{Function Attrs: nounwind sanitize_address$}} +// CHECK-KASAN: {{Function Attrs: nounwind$}} -- cgit v1.2.3