Skip to content

Commit 9254139

Browse files
dvyukovIngo Molnar
authored andcommitted
kprobes: Avoid false KASAN reports during stack copy
Kprobes save and restore raw stack chunks with memcpy(). With KASAN these chunks can contain poisoned stack redzones, as the result memcpy() interceptor produces false stack out-of-bounds reports. Use __memcpy() instead of memcpy() for stack copying. __memcpy() is not instrumented by KASAN and does not lead to the false reports. Currently there is a spew of KASAN reports during boot if CONFIG_KPROBES_SANITY_TEST is enabled: [ ] Kprobe smoke test: started [ ] ================================================================== [ ] BUG: KASAN: stack-out-of-bounds in setjmp_pre_handler+0x17c/0x280 at addr ffff88085259fba8 [ ] Read of size 64 by task swapper/0/1 [ ] page:ffffea00214967c0 count:0 mapcount:0 mapping: (null) index:0x0 [ ] flags: 0x2fffff80000000() [ ] page dumped because: kasan: bad access detected [...] Reported-by: CAI Qian <[email protected]> Tested-by: CAI Qian <[email protected]> Signed-off-by: Dmitry Vyukov <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Anil S Keshavamurthy <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: David S. Miller <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] [ Improved various details. ] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 1001354 commit 9254139

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,9 +1057,10 @@ int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
10571057
* tailcall optimization. So, to be absolutely safe
10581058
* we also save and restore enough stack bytes to cover
10591059
* the argument area.
1060+
* Use __memcpy() to avoid KASAN stack out-of-bounds reports as we copy
1061+
* raw stack chunk with redzones:
10601062
*/
1061-
memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr,
1062-
MIN_STACK_SIZE(addr));
1063+
__memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr, MIN_STACK_SIZE(addr));
10631064
regs->flags &= ~X86_EFLAGS_IF;
10641065
trace_hardirqs_off();
10651066
regs->ip = (unsigned long)(jp->entry);
@@ -1118,7 +1119,7 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
11181119
/* It's OK to start function graph tracing again */
11191120
unpause_graph_tracing();
11201121
*regs = kcb->jprobe_saved_regs;
1121-
memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
1122+
__memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
11221123
preempt_enable_no_resched();
11231124
return 1;
11241125
}

0 commit comments

Comments
 (0)