File tree Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ ENTRY(_cpu_resume)
135135
136136#ifdef CONFIG_KASAN
137137 mov x0 , sp
138- bl kasan_unpoison_remaining_stack
138+ bl kasan_unpoison_task_stack_below
139139#endif
140140
141141 ldp x19 , x20 , [ x29 , # 16 ]
Original file line number Diff line number Diff line change 5050#include <linux/kallsyms.h>
5151#include <linux/ftrace.h>
5252#include <linux/frame.h>
53+ #include <linux/kasan.h>
5354
5455#include <asm/text-patching.h>
5556#include <asm/cacheflush.h>
@@ -1081,6 +1082,9 @@ void jprobe_return(void)
10811082{
10821083 struct kprobe_ctlblk * kcb = get_kprobe_ctlblk ();
10831084
1085+ /* Unpoison stack redzones in the frames we are going to jump over. */
1086+ kasan_unpoison_stack_above_sp_to (kcb -> jprobe_saved_sp );
1087+
10841088 asm volatile (
10851089#ifdef CONFIG_X86_64
10861090 " xchg %%rbx,%%rsp \n"
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ static inline void kasan_disable_current(void)
4444void kasan_unpoison_shadow (const void * address , size_t size );
4545
4646void kasan_unpoison_task_stack (struct task_struct * task );
47+ void kasan_unpoison_stack_above_sp_to (const void * watermark );
4748
4849void kasan_alloc_pages (struct page * page , unsigned int order );
4950void kasan_free_pages (struct page * page , unsigned int order );
@@ -85,6 +86,7 @@ size_t kasan_metadata_size(struct kmem_cache *cache);
8586static inline void kasan_unpoison_shadow (const void * address , size_t size ) {}
8687
8788static inline void kasan_unpoison_task_stack (struct task_struct * task ) {}
89+ static inline void kasan_unpoison_stack_above_sp_to (const void * watermark ) {}
8890
8991static inline void kasan_enable_current (void ) {}
9092static inline void kasan_disable_current (void ) {}
Original file line number Diff line number Diff line change 3434#include <linux/string.h>
3535#include <linux/types.h>
3636#include <linux/vmalloc.h>
37+ #include <linux/bug.h>
3738
3839#include "kasan.h"
3940#include "../slab.h"
@@ -62,7 +63,7 @@ void kasan_unpoison_shadow(const void *address, size_t size)
6263 }
6364}
6465
65- static void __kasan_unpoison_stack (struct task_struct * task , void * sp )
66+ static void __kasan_unpoison_stack (struct task_struct * task , const void * sp )
6667{
6768 void * base = task_stack_page (task );
6869 size_t size = sp - base ;
@@ -77,9 +78,24 @@ void kasan_unpoison_task_stack(struct task_struct *task)
7778}
7879
7980/* Unpoison the stack for the current task beyond a watermark sp value. */
80- asmlinkage void kasan_unpoison_remaining_stack ( void * sp )
81+ asmlinkage void kasan_unpoison_task_stack_below ( const void * watermark )
8182{
82- __kasan_unpoison_stack (current , sp );
83+ __kasan_unpoison_stack (current , watermark );
84+ }
85+
86+ /*
87+ * Clear all poison for the region between the current SP and a provided
88+ * watermark value, as is sometimes required prior to hand-crafted asm function
89+ * returns in the middle of functions.
90+ */
91+ void kasan_unpoison_stack_above_sp_to (const void * watermark )
92+ {
93+ const void * sp = __builtin_frame_address (0 );
94+ size_t size = watermark - sp ;
95+
96+ if (WARN_ON (sp > watermark ))
97+ return ;
98+ kasan_unpoison_shadow (sp , size );
8399}
84100
85101/*
You can’t perform that action at this time.
0 commit comments