Skip to content

Commit ad05711

Browse files
David A. Longctmarinas
authored andcommitted
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>
1 parent 7f1d642 commit ad05711

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

arch/arm64/include/asm/kprobes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#define __ARCH_WANT_KPROBES_INSN_SLOT
2424
#define MAX_INSN_SIZE 1
25-
#define MAX_STACK_SIZE 128
2625

2726
#define flush_insn_slot(p) do { } while (0)
2827
#define kretprobe_blacklist_size 0
@@ -47,7 +46,6 @@ struct kprobe_ctlblk {
4746
struct prev_kprobe prev_kprobe;
4847
struct kprobe_step_ctx ss_ctx;
4948
struct pt_regs jprobe_saved_regs;
50-
char jprobes_stack[MAX_STACK_SIZE];
5149
};
5250

5351
void arch_remove_kprobe(struct kprobe *);

arch/arm64/kernel/probes/kprobes.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
4141
static void __kprobes
4242
post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
4343

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-
5644
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
5745
{
5846
/* prepare insn slot */
@@ -489,20 +477,15 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
489477
{
490478
struct jprobe *jp = container_of(p, struct jprobe, kp);
491479
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
492-
long stack_ptr = kernel_stack_pointer(regs);
493480

494481
kcb->jprobe_saved_regs = *regs;
495482
/*
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.
501488
*/
502-
kasan_disable_current();
503-
memcpy(kcb->jprobes_stack, (void *)stack_ptr,
504-
min_stack_size(stack_ptr));
505-
kasan_enable_current();
506489

507490
instruction_pointer_set(regs, (unsigned long) jp->entry);
508491
preempt_disable();
@@ -554,10 +537,6 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
554537
}
555538
unpause_graph_tracing();
556539
*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();
561540
preempt_enable_no_resched();
562541
return 1;
563542
}

0 commit comments

Comments
 (0)