Adding kasan alloca support using clang
Also adding support for clang, since needed for this feature
gcc has kasan alloca support, but only post 7.2
[Patch v2 1/5] kasan: support alloca() poisoning
Tests moved to patch 2/5
__asan_alloca_unpoison():
Use precalculated rounded-up-size
Warning added if bottom is not aligned as expected
Parameter check added to make sure gcc builds don't fail
Now unpoisons partial chunks
get_shadow_bug_type():
Missing break added
[PATCH v2 2/5] kasan: Add tests for alloca poisonong
Tests moved here
kasan_alloca_oob_right():
No longer rounding up
[PATCH v2 3/5] kasan: added functions for unpoisoning stack variables
No change from v1. clang builds need f8
[PATCH v2 4/5] kasan: support LLVM-style asan parameters
Rejigged whole file. Old approach would not work except with ToT gcc
or clang. All parameters would be rejected if one was not known.
Also if both were empty, CFLAGS_KASAN would be " " which mostly
disabled kasan on older compilers.
Added support for gcc, tested on ToT compiler
[PATCH v2 5/5] kasan: add compiler support for clang
Made comments single line
Paul Lawrence (5):
kasan: support alloca() poisoning
kasan: Add tests for alloca poisonong
kasan: added functions for unpoisoning stack variables
kasan: support LLVM-style asan parameters
kasan: add compiler support for clang
include/linux/compiler-clang.h | 8 +++++++
lib/test_kasan.c | 22 ++++++++++++++++++++
mm/kasan/kasan.c | 47 ++++++++++++++++++++++++++++++++++++++++++
mm/kasan/kasan.h | 8 +++++++
mm/kasan/report.c | 4 ++++
scripts/Makefile.kasan | 39 ++++++++++++++++++++++++-----------
6 files changed, 116 insertions(+), 12 deletions(-)
--
2.15.0.531.g2ccb3012c9-goog
From 1585512537469620322@xxx Thu Nov 30 17:23:05 +0000 2017
X-GM-THRID: 1585484488483145453
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread
From: Alexander Potapenko <[email protected]>
As a code-size optimization, LLVM builds since r279383 may
bulk-manipulate the shadow region when (un)poisoning large memory
blocks. This requires new callbacks that simply do an uninstrumented
memset().
This fixes linking the Clang-built kernel when using KASAN.
Signed-off-by: Alexander Potapenko <[email protected]>
[[email protected]: fix memset() parameters, and tweak
commit message to describe new callbacks]
Signed-off-by: Greg Hackmann <[email protected]>
Signed-off-by: Paul Lawrence <[email protected]>
---
mm/kasan/kasan.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index f86f862f41f8..89565a1ec417 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -768,6 +768,21 @@ void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom)
}
EXPORT_SYMBOL(__asan_allocas_unpoison);
+/* Emitted by the compiler to [un]poison local variables. */
+#define DEFINE_ASAN_SET_SHADOW(byte) \
+ void __asan_set_shadow_##byte(const void *addr, size_t size) \
+ { \
+ __memset((void *)addr, 0x##byte, size); \
+ } \
+ EXPORT_SYMBOL(__asan_set_shadow_##byte)
+
+DEFINE_ASAN_SET_SHADOW(00);
+DEFINE_ASAN_SET_SHADOW(f1);
+DEFINE_ASAN_SET_SHADOW(f2);
+DEFINE_ASAN_SET_SHADOW(f3);
+DEFINE_ASAN_SET_SHADOW(f5);
+DEFINE_ASAN_SET_SHADOW(f8);
+
#ifdef CONFIG_MEMORY_HOTPLUG
static int __meminit kasan_mem_notifier(struct notifier_block *nb,
unsigned long action, void *data)
--
2.15.0.531.g2ccb3012c9-goog
From 1585334755741559608@xxx Tue Nov 28 18:17:19 +0000 2017
X-GM-THRID: 1585216063813693983
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread
Signed-off-by: Greg Hackmann <[email protected]>
Signed-off-by: Paul Lawrence <[email protected]>
lib/test_kasan.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index ef1a3ac1397e..2724f86c4cef 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -472,6 +472,26 @@ static noinline void __init use_after_scope_test(void)
p[1023] = 1;
}
+static noinline void __init kasan_alloca_oob_left(void)
+{
+ volatile int i = 10;
+ char alloca_array[i];
+ char *p = alloca_array - 1;
+
+ pr_info("out-of-bounds to left on alloca\n");
+ *(volatile char *)p;
+}
+
+static noinline void __init kasan_alloca_oob_right(void)
+{
+ volatile int i = 10;
+ char alloca_array[i];
+ char *p = alloca_array + i;
+
+ pr_info("out-of-bounds to right on alloca\n");
+ *(volatile char *)p;
+}
+
static int __init kmalloc_tests_init(void)
{
/*
@@ -502,6 +522,8 @@ static int __init kmalloc_tests_init(void)
memcg_accounted_kmem_cache();
kasan_stack_oob();
kasan_global_oob();
+ kasan_alloca_oob_left();
+ kasan_alloca_oob_right();
ksize_unpoisons_memory();
copy_user_test();
use_after_scope_test();
--
2.15.0.531.g2ccb3012c9-goog
From 1585316208112054162@xxx Tue Nov 28 13:22:31 +0000 2017
X-GM-THRID: 1585316208112054162
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread