Skip to content

Commit 7b425f5

Browse files
FlyGoatgregkh
authored andcommitted
ptrace: Introduce exception_ip arch hook
commit 11ba1728be3edb6928791f4c622f154ebe228ae6 upstream. On architectures with delay slot, architecture level instruction pointer (or program counter) in pt_regs may differ from where exception was triggered. Introduce exception_ip hook to invoke architecture code and determine actual instruction pointer to the exception. Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Jiaxun Yang <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]> Cc: Salvatore Bonaccorso <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ef3bc90 commit 7b425f5

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

arch/mips/include/asm/ptrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static inline long regs_return_value(struct pt_regs *regs)
155155
}
156156

157157
#define instruction_pointer(regs) ((regs)->cp0_epc)
158+
extern unsigned long exception_ip(struct pt_regs *regs);
159+
#define exception_ip(regs) exception_ip(regs)
158160
#define profile_pc(regs) instruction_pointer(regs)
159161

160162
extern asmlinkage long syscall_trace_enter(struct pt_regs *regs);

arch/mips/kernel/ptrace.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/seccomp.h>
3232
#include <linux/ftrace.h>
3333

34+
#include <asm/branch.h>
3435
#include <asm/byteorder.h>
3536
#include <asm/cpu.h>
3637
#include <asm/cpu-info.h>
@@ -48,6 +49,12 @@
4849
#define CREATE_TRACE_POINTS
4950
#include <trace/events/syscalls.h>
5051

52+
unsigned long exception_ip(struct pt_regs *regs)
53+
{
54+
return exception_epc(regs);
55+
}
56+
EXPORT_SYMBOL(exception_ip);
57+
5158
/*
5259
* Called by kernel/ptrace.c when detaching..
5360
*

include/linux/ptrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ static inline void user_single_step_report(struct pt_regs *regs)
402402
#define current_user_stack_pointer() user_stack_pointer(current_pt_regs())
403403
#endif
404404

405+
#ifndef exception_ip
406+
#define exception_ip(x) instruction_pointer(x)
407+
#endif
408+
405409
extern int task_current_syscall(struct task_struct *target, struct syscall_info *info);
406410

407411
extern void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact);

0 commit comments

Comments
 (0)