Skip to content

Commit

Permalink
kprobes: treewide: Make it harder to refer kretprobe_trampoline directly
Browse files Browse the repository at this point in the history
Since now there is kretprobe_trampoline_addr() for referring the
address of kretprobe trampoline code, we don't need to access
kretprobe_trampoline directly.

Make it harder to refer by renaming it to __kretprobe_trampoline().

Link: https://lkml.kernel.org/r/163163045446.489837.14510577516938803097.stgit@devnote2

Suggested-by: Ingo Molnar <[email protected]>
Signed-off-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
  • Loading branch information
mhiramat authored and rostedt committed Oct 1, 2021
1 parent 96fed8a commit adf8a61
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 75 deletions.
2 changes: 1 addition & 1 deletion arch/arc/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct kprobe_ctlblk {
};

int kprobe_fault_handler(struct pt_regs *regs, unsigned long cause);
void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);
void trap_is_kprobe(unsigned long address, struct pt_regs *regs);
#else
#define trap_is_kprobe(address, regs)
Expand Down
11 changes: 6 additions & 5 deletions arch/arc/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,

static void __used kretprobe_trampoline_holder(void)
{
__asm__ __volatile__(".global kretprobe_trampoline\n"
"kretprobe_trampoline:\n" "nop\n");
__asm__ __volatile__(".global __kretprobe_trampoline\n"
"__kretprobe_trampoline:\n"
"nop\n");
}

void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
Expand All @@ -375,7 +376,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
ri->fp = NULL;

/* Replace the return addr with trampoline addr */
regs->blink = (unsigned long)&kretprobe_trampoline;
regs->blink = (unsigned long)&__kretprobe_trampoline;
}

static int __kprobes trampoline_probe_handler(struct kprobe *p,
Expand All @@ -390,7 +391,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
}

static struct kprobe trampoline_p = {
.addr = (kprobe_opcode_t *) &kretprobe_trampoline,
.addr = (kprobe_opcode_t *) &__kretprobe_trampoline,
.pre_handler = trampoline_probe_handler
};

Expand All @@ -402,7 +403,7 @@ int __init arch_init_kprobes(void)

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
{
if (p->addr == (kprobe_opcode_t *) &kretprobe_trampoline)
if (p->addr == (kprobe_opcode_t *) &__kretprobe_trampoline)
return 1;

return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/arm/probes/kprobes/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
* for kretprobe handlers which should normally be interested in r0 only
* anyway.
*/
void __naked __kprobes kretprobe_trampoline(void)
void __naked __kprobes __kretprobe_trampoline(void)
{
__asm__ __volatile__ (
"stmdb sp!, {r0 - r11} \n\t"
Expand All @@ -389,7 +389,7 @@ void __naked __kprobes kretprobe_trampoline(void)
: : : "memory");
}

/* Called from kretprobe_trampoline */
/* Called from __kretprobe_trampoline */
static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
{
return (void *)kretprobe_trampoline_handler(regs, (void *)regs->ARM_fp);
Expand All @@ -402,7 +402,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
ri->fp = (void *)regs->ARM_fp;

/* Replace the return addr with trampoline addr. */
regs->ARM_lr = (unsigned long)&kretprobe_trampoline;
regs->ARM_lr = (unsigned long)&__kretprobe_trampoline;
}

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void arch_remove_kprobe(struct kprobe *);
int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr);
int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);
void __kprobes *trampoline_probe_handler(struct pt_regs *regs);

#endif /* CONFIG_KPROBES */
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/probes/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
ri->fp = (void *)kernel_stack_pointer(regs);

/* replace return addr (x30) with trampoline */
regs->regs[30] = (long)&kretprobe_trampoline;
regs->regs[30] = (long)&__kretprobe_trampoline;
}

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/kernel/probes/kprobes_trampoline.S
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
ldp x28, x29, [sp, #S_X28]
.endm

SYM_CODE_START(kretprobe_trampoline)
SYM_CODE_START(__kretprobe_trampoline)
sub sp, sp, #PT_REGS_SIZE

save_all_base_regs
Expand All @@ -79,4 +79,4 @@ SYM_CODE_START(kretprobe_trampoline)
add sp, sp, #PT_REGS_SIZE
ret

SYM_CODE_END(kretprobe_trampoline)
SYM_CODE_END(__kretprobe_trampoline)
2 changes: 1 addition & 1 deletion arch/csky/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void arch_remove_kprobe(struct kprobe *p);
int kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr);
int kprobe_breakpoint_handler(struct pt_regs *regs);
int kprobe_single_step_handler(struct pt_regs *regs);
void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);
void __kprobes *trampoline_probe_handler(struct pt_regs *regs);

#endif /* CONFIG_KPROBES */
Expand Down
2 changes: 1 addition & 1 deletion arch/csky/kernel/probes/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
{
ri->ret_addr = (kprobe_opcode_t *)regs->lr;
ri->fp = NULL;
regs->lr = (unsigned long) &kretprobe_trampoline;
regs->lr = (unsigned long) &__kretprobe_trampoline;
}

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
Expand Down
4 changes: 2 additions & 2 deletions arch/csky/kernel/probes/kprobes_trampoline.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <abi/entry.h>

ENTRY(kretprobe_trampoline)
ENTRY(__kretprobe_trampoline)
SAVE_REGS_FTRACE

mov a0, sp /* pt_regs */
Expand All @@ -16,4 +16,4 @@ ENTRY(kretprobe_trampoline)

RESTORE_REGS_FTRACE
rts
ENDPROC(kretprobe_trampoline)
ENDPROC(__kretprobe_trampoline)
8 changes: 4 additions & 4 deletions arch/ia64/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p,
__this_cpu_write(current_kprobe, p);
}

void kretprobe_trampoline(void)
void __kretprobe_trampoline(void)
{
}

Expand All @@ -414,7 +414,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
ri->fp = NULL;

/* Replace the return addr with trampoline addr */
regs->b0 = (unsigned long)dereference_function_descriptor(kretprobe_trampoline);
regs->b0 = (unsigned long)dereference_function_descriptor(__kretprobe_trampoline);
}

/* Check the instruction in the slot is break */
Expand Down Expand Up @@ -897,14 +897,14 @@ static struct kprobe trampoline_p = {
int __init arch_init_kprobes(void)
{
trampoline_p.addr =
dereference_function_descriptor(kretprobe_trampoline);
dereference_function_descriptor(__kretprobe_trampoline);
return register_kprobe(&trampoline_p);
}

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
{
if (p->addr ==
dereference_function_descriptor(kretprobe_trampoline))
dereference_function_descriptor(__kretprobe_trampoline))
return 1;

return 0;
Expand Down
12 changes: 6 additions & 6 deletions arch/mips/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ static void __used kretprobe_trampoline_holder(void)
/* Keep the assembler from reordering and placing JR here. */
".set noreorder\n\t"
"nop\n\t"
".global kretprobe_trampoline\n"
"kretprobe_trampoline:\n\t"
".global __kretprobe_trampoline\n"
"__kretprobe_trampoline:\n\t"
"nop\n\t"
".set pop"
: : : "memory");
}

void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);

void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
struct pt_regs *regs)
Expand All @@ -476,7 +476,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
ri->fp = NULL;

/* Replace the return addr with trampoline addr */
regs->regs[31] = (unsigned long)kretprobe_trampoline;
regs->regs[31] = (unsigned long)__kretprobe_trampoline;
}

/*
Expand All @@ -496,14 +496,14 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
{
if (p->addr == (kprobe_opcode_t *)kretprobe_trampoline)
if (p->addr == (kprobe_opcode_t *)__kretprobe_trampoline)
return 1;

return 0;
}

static struct kprobe trampoline_p = {
.addr = (kprobe_opcode_t *)kretprobe_trampoline,
.addr = (kprobe_opcode_t *)__kretprobe_trampoline,
.pre_handler = trampoline_probe_handler
};

Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int __kprobes parisc_kprobe_ss_handler(struct pt_regs *regs)
return 1;
}

void kretprobe_trampoline(void)
void __kretprobe_trampoline(void)
{
asm volatile("nop");
asm volatile("nop");
Expand Down Expand Up @@ -217,6 +217,6 @@ int __kprobes arch_trampoline_kprobe(struct kprobe *p)
int __init arch_init_kprobes(void)
{
trampoline_p.addr = (kprobe_opcode_t *)
dereference_function_descriptor(kretprobe_trampoline);
dereference_function_descriptor(__kretprobe_trampoline);
return register_kprobe(&trampoline_p);
}
2 changes: 1 addition & 1 deletion arch/powerpc/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern kprobe_opcode_t optprobe_template_end[];
#define flush_insn_slot(p) do { } while (0)
#define kretprobe_blacklist_size 0

void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);
extern void arch_remove_kprobe(struct kprobe *p);

/* Architecture specific copy of original instruction */
Expand Down
16 changes: 8 additions & 8 deletions arch/powerpc/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
ri->fp = NULL;

/* Replace the return addr with trampoline addr */
regs->link = (unsigned long)kretprobe_trampoline;
regs->link = (unsigned long)__kretprobe_trampoline;
}
NOKPROBE_SYMBOL(arch_prepare_kretprobe);

Expand Down Expand Up @@ -403,12 +403,12 @@ NOKPROBE_SYMBOL(kprobe_handler);
* - When the probed function returns, this probe
* causes the handlers to fire
*/
asm(".global kretprobe_trampoline\n"
".type kretprobe_trampoline, @function\n"
"kretprobe_trampoline:\n"
asm(".global __kretprobe_trampoline\n"
".type __kretprobe_trampoline, @function\n"
"__kretprobe_trampoline:\n"
"nop\n"
"blr\n"
".size kretprobe_trampoline, .-kretprobe_trampoline\n");
".size __kretprobe_trampoline, .-__kretprobe_trampoline\n");

/*
* Called when the probe at kretprobe trampoline is hit
Expand All @@ -427,7 +427,7 @@ static int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
* as it is used to determine the return address from the trap.
* For (2), since nip is not honoured with optprobes, we instead setup
* the link register properly so that the subsequent 'blr' in
* kretprobe_trampoline jumps back to the right instruction.
* __kretprobe_trampoline jumps back to the right instruction.
*
* For nip, we should set the address to the previous instruction since
* we end up emulating it in kprobe_handler(), which increments the nip
Expand Down Expand Up @@ -543,7 +543,7 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
NOKPROBE_SYMBOL(kprobe_fault_handler);

static struct kprobe trampoline_p = {
.addr = (kprobe_opcode_t *) &kretprobe_trampoline,
.addr = (kprobe_opcode_t *) &__kretprobe_trampoline,
.pre_handler = trampoline_probe_handler
};

Expand All @@ -554,7 +554,7 @@ int __init arch_init_kprobes(void)

int arch_trampoline_kprobe(struct kprobe *p)
{
if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
if (p->addr == (kprobe_opcode_t *)&__kretprobe_trampoline)
return 1;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/optprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static unsigned long can_optimize(struct kprobe *p)
* has a 'nop' instruction, which can be emulated.
* So further checks can be skipped.
*/
if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
if (p->addr == (kprobe_opcode_t *)&__kretprobe_trampoline)
return addr + sizeof(kprobe_opcode_t);

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int __no_sanitize_address arch_stack_walk_reliable(stack_trace_consume_fn consum
* Mark stacktraces with kretprobed functions on them
* as unreliable.
*/
if (ip == (unsigned long)kretprobe_trampoline)
if (ip == (unsigned long)__kretprobe_trampoline)
return -EINVAL;
#endif

Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void arch_remove_kprobe(struct kprobe *p);
int kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr);
bool kprobe_breakpoint_handler(struct pt_regs *regs);
bool kprobe_single_step_handler(struct pt_regs *regs);
void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);
void __kprobes *trampoline_probe_handler(struct pt_regs *regs);

#endif /* CONFIG_KPROBES */
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/kernel/probes/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
{
ri->ret_addr = (kprobe_opcode_t *)regs->ra;
ri->fp = NULL;
regs->ra = (unsigned long) &kretprobe_trampoline;
regs->ra = (unsigned long) &__kretprobe_trampoline;
}

int __kprobes arch_trampoline_kprobe(struct kprobe *p)
Expand Down
4 changes: 2 additions & 2 deletions arch/riscv/kernel/probes/kprobes_trampoline.S
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
REG_L x31, PT_T6(sp)
.endm

ENTRY(kretprobe_trampoline)
ENTRY(__kretprobe_trampoline)
addi sp, sp, -(PT_SIZE_ON_STACK)
save_all_base_regs

Expand All @@ -90,4 +90,4 @@ ENTRY(kretprobe_trampoline)
addi sp, sp, PT_SIZE_ON_STACK

ret
ENDPROC(kretprobe_trampoline)
ENDPROC(__kretprobe_trampoline)
2 changes: 1 addition & 1 deletion arch/s390/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct kprobe_ctlblk {
};

void arch_remove_kprobe(struct kprobe *p);
void kretprobe_trampoline(void);
void __kretprobe_trampoline(void);

int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
int kprobe_exceptions_notify(struct notifier_block *self,
Expand Down
10 changes: 5 additions & 5 deletions arch/s390/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
ri->fp = NULL;

/* Replace the return addr with trampoline addr */
regs->gprs[14] = (unsigned long) &kretprobe_trampoline;
regs->gprs[14] = (unsigned long) &__kretprobe_trampoline;
}
NOKPROBE_SYMBOL(arch_prepare_kretprobe);

Expand Down Expand Up @@ -334,8 +334,8 @@ NOKPROBE_SYMBOL(kprobe_handler);
*/
static void __used kretprobe_trampoline_holder(void)
{
asm volatile(".global kretprobe_trampoline\n"
"kretprobe_trampoline: bcr 0,0\n");
asm volatile(".global __kretprobe_trampoline\n"
"__kretprobe_trampoline: bcr 0,0\n");
}

/*
Expand Down Expand Up @@ -509,7 +509,7 @@ int kprobe_exceptions_notify(struct notifier_block *self,
NOKPROBE_SYMBOL(kprobe_exceptions_notify);

static struct kprobe trampoline = {
.addr = (kprobe_opcode_t *) &kretprobe_trampoline,
.addr = (kprobe_opcode_t *) &__kretprobe_trampoline,
.pre_handler = trampoline_probe_handler
};

Expand All @@ -520,6 +520,6 @@ int __init arch_init_kprobes(void)

int arch_trampoline_kprobe(struct kprobe *p)
{
return p->addr == (kprobe_opcode_t *) &kretprobe_trampoline;
return p->addr == (kprobe_opcode_t *) &__kretprobe_trampoline;
}
NOKPROBE_SYMBOL(arch_trampoline_kprobe);
Loading

0 comments on commit adf8a61

Please sign in to comment.