Commit 9254139a authored by Dmitry Vyukov's avatar Dmitry Vyukov Committed by Ingo Molnar
Browse files

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

[   ] 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: default avatarCAI Qian <>
Tested-by: default avatarCAI Qian <>
Signed-off-by: default avatarDmitry Vyukov <>
Acked-by: default avatarMasami Hiramatsu <>
Cc: Alexander Potapenko <>
Cc: Alexander Shishkin <>
Cc: Ananth N Mavinakayanahalli <>
Cc: Andrew Morton <>
Cc: Andrey Ryabinin <>
Cc: Andy Lutomirski <>
Cc: Anil S Keshavamurthy <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Borislav Petkov <>
Cc: Brian Gerst <>
Cc: David S. Miller <>
Cc: Denys Vlasenko <>
Cc: H. Peter Anvin <>
Cc: Jiri Olsa <>
Cc: Josh Poimboeuf <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
[ Improved various details. ]
Signed-off-by: default avatarIngo Molnar <>
parent 1001354c
......@@ -1057,9 +1057,10 @@ int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
* tailcall optimization. So, to be absolutely safe
* we also save and restore enough stack bytes to cover
* the argument area.
* Use __memcpy() to avoid KASAN stack out-of-bounds reports as we copy
* raw stack chunk with redzones:
memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr,
__memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr, MIN_STACK_SIZE(addr));
regs->flags &= ~X86_EFLAGS_IF;
regs->ip = (unsigned long)(jp->entry);
......@@ -1118,7 +1119,7 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
/* It's OK to start function graph tracing again */
*regs = kcb->jprobe_saved_regs;
memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
__memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
return 1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment