Skip to content

Commit d56a9ef

Browse files
xairytorvalds
authored andcommitted
kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK
There's a config option CONFIG_KASAN_STACK that has to be enabled for KASAN to use stack instrumentation and perform validity checks for stack variables. There's no need to unpoison stack when CONFIG_KASAN_STACK is not enabled. Only call kasan_unpoison_task_stack[_below]() when CONFIG_KASAN_STACK is enabled. Note, that CONFIG_KASAN_STACK is an option that is currently always defined when CONFIG_KASAN is enabled, and therefore has to be tested with #if instead of #ifdef. Link: https://lkml.kernel.org/r/d09dd3f8abb388da397fd11598c5edeaa83fe559.1606162397.git.andreyknvl@google.com Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 Signed-off-by: Andrey Konovalov <[email protected]> Reviewed-by: Marco Elver <[email protected]> Acked-by: Catalin Marinas <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]> Tested-by: Vincenzo Frascino <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Branislav Rankov <[email protected]> Cc: Evgenii Stepanov <[email protected]> Cc: Kevin Brodsky <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8bb0009 commit d56a9ef

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

arch/arm64/kernel/sleep.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ SYM_FUNC_START(_cpu_resume)
133133
*/
134134
bl cpu_do_resume
135135

136-
#ifdef CONFIG_KASAN
136+
#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK
137137
mov x0, sp
138138
bl kasan_unpoison_task_stack_below
139139
#endif

arch/x86/kernel/acpi/wakeup_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ SYM_FUNC_START(do_suspend_lowlevel)
112112
movq pt_regs_r14(%rax), %r14
113113
movq pt_regs_r15(%rax), %r15
114114

115-
#ifdef CONFIG_KASAN
115+
#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK
116116
/*
117117
* The suspend path may have poisoned some areas deeper in the stack,
118118
* which we now need to unpoison.

include/linux/kasan.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ static inline void kasan_disable_current(void) {}
7777

7878
void kasan_unpoison_range(const void *address, size_t size);
7979

80-
void kasan_unpoison_task_stack(struct task_struct *task);
81-
8280
void kasan_alloc_pages(struct page *page, unsigned int order);
8381
void kasan_free_pages(struct page *page, unsigned int order);
8482

@@ -123,8 +121,6 @@ void kasan_restore_multi_shot(bool enabled);
123121

124122
static inline void kasan_unpoison_range(const void *address, size_t size) {}
125123

126-
static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
127-
128124
static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
129125
static inline void kasan_free_pages(struct page *page, unsigned int order) {}
130126

@@ -176,6 +172,12 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; }
176172

177173
#endif /* CONFIG_KASAN */
178174

175+
#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK
176+
void kasan_unpoison_task_stack(struct task_struct *task);
177+
#else
178+
static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
179+
#endif
180+
179181
#ifdef CONFIG_KASAN_GENERIC
180182

181183
void kasan_cache_shrink(struct kmem_cache *cache);

mm/kasan/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void kasan_unpoison_range(const void *address, size_t size)
6363
unpoison_range(address, size);
6464
}
6565

66+
#if CONFIG_KASAN_STACK
6667
static void __kasan_unpoison_stack(struct task_struct *task, const void *sp)
6768
{
6869
void *base = task_stack_page(task);
@@ -89,6 +90,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark)
8990

9091
unpoison_range(base, watermark - base);
9192
}
93+
#endif /* CONFIG_KASAN_STACK */
9294

9395
void kasan_alloc_pages(struct page *page, unsigned int order)
9496
{

0 commit comments

Comments
 (0)