lkml.org 
[lkml]   [2021]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/4] arm64: Enable userspace syscall dispatch
Date
From: Ryan Houdek <Houdek.Ryan@fex-emu.org>

When `PR_SET_SYSCALL_USER_DISPATCH` is used this will set the thread's
flags to enable `TIF_SYSCALL_USER_DISPATCH`.

This allows us to support userspace dispatch of syscalls through SIGSYS.
This has feature parity with what is available on x86-64

Signed-off-by: Ryan Houdek <Houdek.Ryan@fex-emu.org>
---
arch/arm64/Kconfig | 1 +
arch/arm64/include/asm/syscall.h | 2 ++
arch/arm64/include/asm/thread_info.h | 4 +++-
arch/arm64/kernel/ptrace.c | 24 ++++++++++++++++++++++++
arch/arm64/kernel/syscall.c | 9 +++++++++
5 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9f1d8566bbf9..8c5f2d1c7053 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -220,6 +220,7 @@ config ARM64
select SYSCTL_EXCEPTION_TRACE
select THREAD_INFO_IN_TASK
select HAVE_ARCH_USERFAULTFD_MINOR if USERFAULTFD
+ select SYSCALL_USER_DISPATCH
help
ARM 64-bit (AArch64) Linux support.

diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index cfc0672013f6..8f6417822139 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -94,4 +94,6 @@ static inline int syscall_get_arch(struct task_struct *task)
return AUDIT_ARCH_AARCH64;
}

+extern bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs);
+
#endif /* __ASM_SYSCALL_H */
diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
index 6623c99f0984..7b9c6225c3c7 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -81,6 +81,7 @@ int arch_dup_task_struct(struct task_struct *dst,
#define TIF_SVE_VL_INHERIT 24 /* Inherit sve_vl_onexec across exec */
#define TIF_SSBD 25 /* Wants SSB mitigation */
#define TIF_TAGGED_ADDR 26 /* Allow tagged user addresses */
+#define TIF_SYSCALL_USER_DISPATCH 27 /* Allow userspace syscall dispatch */

#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
@@ -97,6 +98,7 @@ int arch_dup_task_struct(struct task_struct *dst,
#define _TIF_SVE (1 << TIF_SVE)
#define _TIF_MTE_ASYNC_FAULT (1 << TIF_MTE_ASYNC_FAULT)
#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
+#define _TIF_SYSCALL_USER_DISPATCH (1 << TIF_SYSCALL_USER_DISPATCH)

#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
_TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
@@ -105,7 +107,7 @@ int arch_dup_task_struct(struct task_struct *dst,

#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
- _TIF_SYSCALL_EMU)
+ _TIF_SYSCALL_EMU | _TIF_SYSCALL_USER_DISPATCH)

#ifdef CONFIG_SHADOW_CALL_STACK
#define INIT_SCS \
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index eb2f73939b7b..ddff7d916592 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -13,6 +13,7 @@
#include <linux/kernel.h>
#include <linux/sched/signal.h>
#include <linux/sched/task_stack.h>
+#include <linux/syscall_user_dispatch.h>
#include <linux/mm.h>
#include <linux/nospec.h>
#include <linux/smp.h>
@@ -1836,6 +1837,16 @@ int syscall_trace_enter(struct pt_regs *regs)
{
unsigned long flags = READ_ONCE(current_thread_info()->flags);

+ /*
+ * Handle Syscall User Dispatch. This must comes first, since
+ * the ABI here can be something that doesn't make sense for
+ * other syscall_work features.
+ */
+ if (flags & _TIF_SYSCALL_USER_DISPATCH) {
+ if (syscall_user_dispatch(regs))
+ return NO_SYSCALL;
+ }
+
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
if (flags & _TIF_SYSCALL_EMU)
@@ -1859,6 +1870,19 @@ void syscall_trace_exit(struct pt_regs *regs)
{
unsigned long flags = READ_ONCE(current_thread_info()->flags);

+ /*
+ * If the syscall was rolled back due to syscall user dispatching,
+ * then the tracers below are not invoked for the same reason as
+ * the entry side was not invoked in syscall_trace_enter(): The ABI
+ * of these syscalls is unknown.
+ */
+ if (flags & _TIF_SYSCALL_USER_DISPATCH) {
+ if (unlikely(current->syscall_dispatch.on_dispatch)) {
+ current->syscall_dispatch.on_dispatch = false;
+ return;
+ }
+ }
+
audit_syscall_exit(regs);

if (flags & _TIF_SYSCALL_TRACEPOINT)
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index 263d6c1a525f..2630cffe5725 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -15,6 +15,7 @@
#include <asm/syscall.h>
#include <asm/thread_info.h>
#include <asm/unistd.h>
+#include <asm/vdso.h>

long compat_arm_syscall(struct pt_regs *regs, int scno);
long sys_ni_syscall(void);
@@ -191,3 +192,11 @@ void do_el0_svc_compat(struct pt_regs *regs)
compat_sys_call_table);
}
#endif
+
+bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
+{
+ if (regs->pc == (unsigned long)VDSO_SYMBOL(current->mm->context.vdso,
+ vdso_sigreturn_landing_pad))
+ return true;
+ return false;
+}
--
2.30.2
\
 
 \ /
  Last update: 2021-05-29 10:17    [W:0.187 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site