Commit ad05711cec12131e1277ce749a99d08ecf233aa7
Committed by
Catalin Marinas
1 parent
7f1d642fbb
arm64: Remove stack duplicating code from jprobes
Because the arm64 calling standard allows stacked function arguments to be anywhere in the stack frame, do not attempt to duplicate the stack frame for jprobes handler functions. Documentation changes to describe this issue have been broken out into a separate patch in order to simultaneously address them in other architecture(s). Signed-off-by: David A. Long <dave.long@linaro.org> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Showing 2 changed files with 5 additions and 28 deletions Side-by-side Diff
arch/arm64/include/asm/kprobes.h
... | ... | @@ -22,7 +22,6 @@ |
22 | 22 | |
23 | 23 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
24 | 24 | #define MAX_INSN_SIZE 1 |
25 | -#define MAX_STACK_SIZE 128 | |
26 | 25 | |
27 | 26 | #define flush_insn_slot(p) do { } while (0) |
28 | 27 | #define kretprobe_blacklist_size 0 |
... | ... | @@ -47,7 +46,6 @@ |
47 | 46 | struct prev_kprobe prev_kprobe; |
48 | 47 | struct kprobe_step_ctx ss_ctx; |
49 | 48 | struct pt_regs jprobe_saved_regs; |
50 | - char jprobes_stack[MAX_STACK_SIZE]; | |
51 | 49 | }; |
52 | 50 | |
53 | 51 | void arch_remove_kprobe(struct kprobe *); |
arch/arm64/kernel/probes/kprobes.c
... | ... | @@ -41,18 +41,6 @@ |
41 | 41 | static void __kprobes |
42 | 42 | post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *); |
43 | 43 | |
44 | -static inline unsigned long min_stack_size(unsigned long addr) | |
45 | -{ | |
46 | - unsigned long size; | |
47 | - | |
48 | - if (on_irq_stack(addr, raw_smp_processor_id())) | |
49 | - size = IRQ_STACK_PTR(raw_smp_processor_id()) - addr; | |
50 | - else | |
51 | - size = (unsigned long)current_thread_info() + THREAD_START_SP - addr; | |
52 | - | |
53 | - return min(size, FIELD_SIZEOF(struct kprobe_ctlblk, jprobes_stack)); | |
54 | -} | |
55 | - | |
56 | 44 | static void __kprobes arch_prepare_ss_slot(struct kprobe *p) |
57 | 45 | { |
58 | 46 | /* prepare insn slot */ |
59 | 47 | |
60 | 48 | |
... | ... | @@ -489,20 +477,15 @@ |
489 | 477 | { |
490 | 478 | struct jprobe *jp = container_of(p, struct jprobe, kp); |
491 | 479 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
492 | - long stack_ptr = kernel_stack_pointer(regs); | |
493 | 480 | |
494 | 481 | kcb->jprobe_saved_regs = *regs; |
495 | 482 | /* |
496 | - * As Linus pointed out, gcc assumes that the callee | |
497 | - * owns the argument space and could overwrite it, e.g. | |
498 | - * tailcall optimization. So, to be absolutely safe | |
499 | - * we also save and restore enough stack bytes to cover | |
500 | - * the argument area. | |
483 | + * Since we can't be sure where in the stack frame "stacked" | |
484 | + * pass-by-value arguments are stored we just don't try to | |
485 | + * duplicate any of the stack. Do not use jprobes on functions that | |
486 | + * use more than 64 bytes (after padding each to an 8 byte boundary) | |
487 | + * of arguments, or pass individual arguments larger than 16 bytes. | |
501 | 488 | */ |
502 | - kasan_disable_current(); | |
503 | - memcpy(kcb->jprobes_stack, (void *)stack_ptr, | |
504 | - min_stack_size(stack_ptr)); | |
505 | - kasan_enable_current(); | |
506 | 489 | |
507 | 490 | instruction_pointer_set(regs, (unsigned long) jp->entry); |
508 | 491 | preempt_disable(); |
... | ... | @@ -554,10 +537,6 @@ |
554 | 537 | } |
555 | 538 | unpause_graph_tracing(); |
556 | 539 | *regs = kcb->jprobe_saved_regs; |
557 | - kasan_disable_current(); | |
558 | - memcpy((void *)stack_addr, kcb->jprobes_stack, | |
559 | - min_stack_size(stack_addr)); | |
560 | - kasan_enable_current(); | |
561 | 540 | preempt_enable_no_resched(); |
562 | 541 | return 1; |
563 | 542 | } |