Skip to content

Commit 3aa99d7

Browse files
committed
Merge branch 'for-next/entry' into for-next/core
* for-next/entry: arm64/ptrace: Return early for ptrace_report_syscall_entry() error arm64/ptrace: Split report_syscall() arm64: Remove unused _TIF_WORK_MASK arm64: Avoid memcpy() for syscall_get_arguments() syscall.h: Remove unused SYSCALL_MAX_ARGS
2 parents c258183 + a338630 commit 3aa99d7

5 files changed

Lines changed: 46 additions & 28 deletions

File tree

arch/arm/include/asm/syscall.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ static inline void syscall_set_nr(struct task_struct *task,
9292
(nr & __NR_SYSCALL_MASK);
9393
}
9494

95-
#define SYSCALL_MAX_ARGS 7
96-
9795
static inline void syscall_get_arguments(struct task_struct *task,
9896
struct pt_regs *regs,
9997
unsigned long *args)

arch/arm64/include/asm/syscall.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,29 @@ static inline void syscall_set_nr(struct task_struct *task,
7777
}
7878
}
7979

80-
#define SYSCALL_MAX_ARGS 6
81-
8280
static inline void syscall_get_arguments(struct task_struct *task,
8381
struct pt_regs *regs,
8482
unsigned long *args)
8583
{
8684
args[0] = regs->orig_x0;
87-
args++;
88-
89-
memcpy(args, &regs->regs[1], 5 * sizeof(args[0]));
85+
args[1] = regs->regs[1];
86+
args[2] = regs->regs[2];
87+
args[3] = regs->regs[3];
88+
args[4] = regs->regs[4];
89+
args[5] = regs->regs[5];
9090
}
9191

9292
static inline void syscall_set_arguments(struct task_struct *task,
9393
struct pt_regs *regs,
9494
const unsigned long *args)
9595
{
96-
memcpy(&regs->regs[0], args, 6 * sizeof(args[0]));
96+
regs->regs[0] = args[0];
97+
regs->regs[1] = args[1];
98+
regs->regs[2] = args[2];
99+
regs->regs[3] = args[3];
100+
regs->regs[4] = args[4];
101+
regs->regs[5] = args[5];
102+
97103
/*
98104
* Also copy the first argument into orig_x0
99105
* so that syscall_get_arguments() would return it

arch/arm64/include/asm/thread_info.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ void arch_setup_new_exec(void);
106106
#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
107107
#define _TIF_TSC_SIGSEGV (1 << TIF_TSC_SIGSEGV)
108108

109-
#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | \
110-
_TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
111-
_TIF_UPROBE | _TIF_MTE_ASYNC_FAULT | \
112-
_TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING | \
113-
_TIF_PATCH_PENDING)
114-
115109
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
116110
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
117111
_TIF_SYSCALL_EMU)

arch/arm64/kernel/ptrace.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,9 +2346,10 @@ enum ptrace_syscall_dir {
23462346
PTRACE_SYSCALL_EXIT,
23472347
};
23482348

2349-
static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
2349+
static __always_inline unsigned long ptrace_save_reg(struct pt_regs *regs,
2350+
enum ptrace_syscall_dir dir,
2351+
int *regno)
23502352
{
2351-
int regno;
23522353
unsigned long saved_reg;
23532354

23542355
/*
@@ -2367,15 +2368,34 @@ static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
23672368
* - Syscall stops behave differently to seccomp and pseudo-step traps
23682369
* (the latter do not nobble any registers).
23692370
*/
2370-
regno = (is_compat_task() ? 12 : 7);
2371-
saved_reg = regs->regs[regno];
2372-
regs->regs[regno] = dir;
2371+
*regno = (is_compat_task() ? 12 : 7);
2372+
saved_reg = regs->regs[*regno];
2373+
regs->regs[*regno] = dir;
23732374

2374-
if (dir == PTRACE_SYSCALL_ENTER) {
2375-
if (ptrace_report_syscall_entry(regs))
2376-
forget_syscall(regs);
2377-
regs->regs[regno] = saved_reg;
2378-
} else if (!test_thread_flag(TIF_SINGLESTEP)) {
2375+
return saved_reg;
2376+
}
2377+
2378+
static int report_syscall_entry(struct pt_regs *regs)
2379+
{
2380+
unsigned long saved_reg;
2381+
int regno, ret;
2382+
2383+
saved_reg = ptrace_save_reg(regs, PTRACE_SYSCALL_ENTER, &regno);
2384+
ret = ptrace_report_syscall_entry(regs);
2385+
if (ret)
2386+
forget_syscall(regs);
2387+
regs->regs[regno] = saved_reg;
2388+
2389+
return ret;
2390+
}
2391+
2392+
static void report_syscall_exit(struct pt_regs *regs)
2393+
{
2394+
unsigned long saved_reg;
2395+
int regno;
2396+
2397+
saved_reg = ptrace_save_reg(regs, PTRACE_SYSCALL_EXIT, &regno);
2398+
if (!test_thread_flag(TIF_SINGLESTEP)) {
23792399
ptrace_report_syscall_exit(regs, 0);
23802400
regs->regs[regno] = saved_reg;
23812401
} else {
@@ -2393,10 +2413,11 @@ static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
23932413
int syscall_trace_enter(struct pt_regs *regs)
23942414
{
23952415
unsigned long flags = read_thread_flags();
2416+
int ret;
23962417

23972418
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
2398-
report_syscall(regs, PTRACE_SYSCALL_ENTER);
2399-
if (flags & _TIF_SYSCALL_EMU)
2419+
ret = report_syscall_entry(regs);
2420+
if (ret || (flags & _TIF_SYSCALL_EMU))
24002421
return NO_SYSCALL;
24012422
}
24022423

@@ -2423,7 +2444,7 @@ void syscall_trace_exit(struct pt_regs *regs)
24232444
trace_sys_exit(regs, syscall_get_return_value(current, regs));
24242445

24252446
if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
2426-
report_syscall(regs, PTRACE_SYSCALL_EXIT);
2447+
report_syscall_exit(regs);
24272448

24282449
rseq_syscall(regs);
24292450
}

arch/xtensa/include/asm/syscall.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static inline void syscall_set_return_value(struct task_struct *task,
6161
regs->areg[2] = (long) error ? error : val;
6262
}
6363

64-
#define SYSCALL_MAX_ARGS 6
6564
#define XTENSA_SYSCALL_ARGUMENT_REGS {6, 3, 4, 5, 8, 9}
6665

6766
static inline void syscall_get_arguments(struct task_struct *task,

0 commit comments

Comments
 (0)