mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 10:31:33 -04:00
Merge branch 'for-next/ptrace' into for-next/core
* for-next/ptrace: arm64: syscall: Pass 'orig_x0' as first argument to native system call arm64: ptrace: Keep 'orig_x0' in-sync with x0 on syscall entry arm64/fpsimd: ptrace: Fix inactive SVE and SSVE regsets
This commit is contained in:
@@ -10,13 +10,13 @@
|
||||
|
||||
#include <asm/ptrace.h>
|
||||
|
||||
#define SC_ARM64_REGS_TO_ARGS(x, ...) \
|
||||
#ifdef CONFIG_COMPAT
|
||||
|
||||
#define COMPAT_SC_ARM64_REGS_TO_ARGS(x, ...) \
|
||||
__MAP(x,__SC_ARGS \
|
||||
,,regs->regs[0],,regs->regs[1],,regs->regs[2] \
|
||||
,,regs->regs[3],,regs->regs[4],,regs->regs[5])
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
|
||||
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
|
||||
asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs); \
|
||||
ALLOW_ERROR_INJECTION(__arm64_compat_sys##name, ERRNO); \
|
||||
@@ -24,7 +24,7 @@
|
||||
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
|
||||
asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs) \
|
||||
{ \
|
||||
return __se_compat_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__)); \
|
||||
return __se_compat_sys##name(COMPAT_SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__)); \
|
||||
} \
|
||||
static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
|
||||
{ \
|
||||
@@ -46,6 +46,11 @@
|
||||
|
||||
#endif /* CONFIG_COMPAT */
|
||||
|
||||
#define SC_ARM64_REGS_TO_ARGS(x, ...) \
|
||||
__MAP(x,__SC_ARGS \
|
||||
,,regs->orig_x0,,regs->regs[1],,regs->regs[2] \
|
||||
,,regs->regs[3],,regs->regs[4],,regs->regs[5])
|
||||
|
||||
#define __SYSCALL_DEFINEx(x, name, ...) \
|
||||
asmlinkage long __arm64_sys##name(const struct pt_regs *regs); \
|
||||
ALLOW_ERROR_INJECTION(__arm64_sys##name, ERRNO); \
|
||||
|
||||
@@ -560,6 +560,42 @@ static int gpr_get(struct task_struct *target,
|
||||
return membuf_write(&to, uregs, sizeof(*uregs));
|
||||
}
|
||||
|
||||
static void update_syscall_orig_x0_after_ptrace(struct task_struct *target)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(target);
|
||||
struct kernel_siginfo *info = target->last_siginfo;
|
||||
|
||||
/*
|
||||
* Skip the update for NO_SYSCALL (set either by the user or the
|
||||
* tracer), as regs[0] holds the return value (see the comment in
|
||||
* el0_svc_common()) and can be unwound using syscall_rollback().
|
||||
*/
|
||||
if (regs->syscallno == NO_SYSCALL)
|
||||
return;
|
||||
|
||||
/* We should only be called when target is in a ptrace stop */
|
||||
if (WARN_ON_ONCE(!info))
|
||||
return;
|
||||
|
||||
/*
|
||||
* For compat tasks, orig_r0 is provided directly through GPR index
|
||||
* 17.
|
||||
*/
|
||||
if (is_compat_thread(task_thread_info(target)))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Don't update orig_x0 for a syscall-exit-stop, as x0 now contains the
|
||||
* return value of the system call.
|
||||
*/
|
||||
if ((info->si_code & ~0x80) == SIGTRAP &&
|
||||
target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
regs->orig_x0 = regs->regs[0];
|
||||
}
|
||||
|
||||
static int gpr_set(struct task_struct *target, const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
@@ -575,6 +611,14 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset,
|
||||
return -EINVAL;
|
||||
|
||||
task_pt_regs(target)->user_regs = newregs;
|
||||
|
||||
/*
|
||||
* Keep orig_x0 authoritative so that seccomp (via
|
||||
* syscall_get_arguments()), audit and the restart path all see the same
|
||||
* first argument the syscall is dispatched with, even if it has been
|
||||
* updated by a tracer.
|
||||
*/
|
||||
update_syscall_orig_x0_after_ptrace(target);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -753,6 +797,12 @@ static int system_call_set(struct task_struct *target,
|
||||
return ret;
|
||||
|
||||
task_pt_regs(target)->syscallno = syscallno;
|
||||
|
||||
/*
|
||||
* Re-sync orig_x0 in case the syscall number has been changed
|
||||
* from NO_SYSCALL.
|
||||
*/
|
||||
update_syscall_orig_x0_after_ptrace(target);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -801,7 +851,7 @@ static void sve_init_header_from_task(struct user_sve_header *header,
|
||||
if (active)
|
||||
header->size = SVE_PT_SIZE(vq, header->flags);
|
||||
else
|
||||
header->size = sizeof(header);
|
||||
header->size = sizeof(*header);
|
||||
header->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),
|
||||
SVE_PT_REGS_SVE);
|
||||
}
|
||||
@@ -837,7 +887,7 @@ static int sve_get_common(struct task_struct *target,
|
||||
* from the other mode to userspace.
|
||||
*/
|
||||
if (header.size == sizeof(header))
|
||||
return 0;
|
||||
return to.left;
|
||||
|
||||
switch ((header.flags & SVE_PT_REGS_MASK)) {
|
||||
case SVE_PT_REGS_FPSIMD:
|
||||
|
||||
Reference in New Issue
Block a user