Skip to content

Commit 5521eb4

Browse files
leitaompe
authored andcommitted
powerpc/ptrace: Add support for PTRACE_SYSEMU
This is a patch that adds support for PTRACE_SYSEMU ptrace request in PowerPC architecture. When ptrace(PTRACE_SYSEMU, ...) request is called, it will be handled by the arch independent function ptrace_resume(), which will tag the task with the TIF_SYSCALL_EMU flag. This flag needs to be handled from a platform dependent point of view, which is what this patch does. This patch adds this task's flag as part of the _TIF_SYSCALL_DOTRACE, which is the MACRO that is used to trace syscalls at entrance/exit. Since TIF_SYSCALL_EMU is now part of _TIF_SYSCALL_DOTRACE, if the task has _TIF_SYSCALL_DOTRACE set, it will hit do_syscall_trace_enter() at syscall entrance and do_syscall_trace_leave() at syscall leave. do_syscall_trace_enter() needs to handle the TIF_SYSCALL_EMU flag properly, which will interrupt the syscall executing if TIF_SYSCALL_EMU is set. The output values should not be changed, i.e. the return value (r3) should contain the original syscall argument on exit. With this flag set, the syscall is not executed fundamentally, because do_syscall_trace_enter() is returning -1 which is bigger than NR_syscall, thus, skipping the syscall execution and exiting userspace. Signed-off-by: Breno Leitao <leitao@debian.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 16d7c69 commit 5521eb4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

arch/powerpc/include/asm/thread_info.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src
8181
#define TIF_SIGPENDING 1 /* signal pending */
8282
#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
8383
#define TIF_FSCHECK 3 /* Check FS is USER_DS on return */
84+
#define TIF_SYSCALL_EMU 4 /* syscall emulation active */
8485
#define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
8586
#define TIF_PATCH_PENDING 6 /* pending live patching update */
8687
#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
@@ -120,9 +121,10 @@ extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src
120121
#define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
121122
#define _TIF_NOHZ (1<<TIF_NOHZ)
122123
#define _TIF_FSCHECK (1<<TIF_FSCHECK)
124+
#define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU)
123125
#define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
124126
_TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
125-
_TIF_NOHZ)
127+
_TIF_NOHZ | _TIF_SYSCALL_EMU)
126128

127129
#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
128130
_TIF_NOTIFY_RESUME | _TIF_UPROBE | \

arch/powerpc/include/uapi/asm/ptrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ struct pt_regs {
160160
#define PTRACE_GETVSRREGS 0x1b
161161
#define PTRACE_SETVSRREGS 0x1c
162162

163+
/* Syscall emulation defines */
164+
#define PTRACE_SYSEMU 0x1d
165+
#define PTRACE_SYSEMU_SINGLESTEP 0x1e
166+
163167
/*
164168
* Get or set a debug register. The first 16 are DABR registers and the
165169
* second 16 are IABR registers.

arch/powerpc/kernel/ptrace.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ void ptrace_disable(struct task_struct *child)
25082508
{
25092509
/* make sure the single step bit is not set. */
25102510
user_disable_single_step(child);
2511+
clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
25112512
}
25122513

25132514
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
@@ -3264,6 +3265,16 @@ long do_syscall_trace_enter(struct pt_regs *regs)
32643265
{
32653266
user_exit();
32663267

3268+
if (test_thread_flag(TIF_SYSCALL_EMU)) {
3269+
ptrace_report_syscall(regs);
3270+
/*
3271+
* Returning -1 will skip the syscall execution. We want to
3272+
* avoid clobbering any register also, thus, not 'gotoing'
3273+
* skip label.
3274+
*/
3275+
return -1;
3276+
}
3277+
32673278
/*
32683279
* The tracer may decide to abort the syscall, if so tracehook
32693280
* will return !0. Note that the tracer may also just change

0 commit comments

Comments
 (0)