linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: houdek.ryan@fex-emu.org
To: unlisted-recipients:; (no To-header on input)
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Ryan Houdek <Houdek.Ryan@fex-emu.org>
Subject: [PATCH 3/4] arm64: Enable userspace syscall dispatch
Date: Sat, 29 May 2021 01:16:19 -0700	[thread overview]
Message-ID: <20210529081620.164422-4-Houdek.Ryan@fex-emu.org> (raw)
In-Reply-To: <20210529081620.164422-1-Houdek.Ryan@fex-emu.org>

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


  parent reply	other threads:[~2021-05-29  8:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-29  8:16 [PATCH 0/4] arm64: Implement userspace syscall dispatch houdek.ryan
2021-05-29  8:16 ` [PATCH 1/4] Move userspace syscall dispatch outside of common entry houdek.ryan
2021-06-02 15:41   ` Thomas Gleixner
2021-06-03 10:58     ` Ryan Houdek
2021-05-29  8:16 ` [PATCH 2/4] arm64: Track the sigreturn landing pad location houdek.ryan
2021-05-29  8:16 ` houdek.ryan [this message]
2021-05-29  8:16 ` [PATCH 4/4] arm64: tools: Update syscall user dispatch tests houdek.ryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210529081620.164422-4-Houdek.Ryan@fex-emu.org \
    --to=houdek.ryan@fex-emu.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).