History

syscall_user_dispatch: Make it configurable in Kconfig

Syscall User Dispatch is presently built under CONFIG_GENERIC_SYSCALL and cannot be disabled independently. Add CONFIG_SYSCALL_USER_DISPATCH to make it an optional feature.

Gregory Price committed 4 months ago

Commit ee935e81 parent 8cdeaa56 files · +42 −9Browse files

Unified · Split

6 files
  1. arch/Kconfig +10 −0
  2. include/linux/entry-common.h +2 −4
  3. include/linux/syscall_user_dispatch.h +26 −2
  4. include/linux/syscall_user_dispatch_types.h +1 −1
  5. kernel/entry/Makefile +2 −1
  6. tools/testing/selftests/syscall_user_dispatch/config +1 −1
arch/Kconfig+10−0
@@ -114,6 +114,16 @@ config GENERIC_ENTRY · 113 unmodified lines
114114 select GENERIC_IRQ_ENTRY
115115 select GENERIC_SYSCALL
116116
117+config SYSCALL_USER_DISPATCH
118+ bool "Syscall User Dispatch"
119+ depends on GENERIC_ENTRY
120+ default y
121+ help
122+ Syscall User Dispatch lets a thread have its own system calls
123+ intercepted and redirected to a userspace signal handler based
124+ on a prctl() configured instruction pointer range.
125+ If unsure, say Y.
126+
117127 config KPROBES
118128 bool "Kprobes"
119129 depends on HAVE_KPROBES
include/linux/entry-common.h+2−4
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <linux/resume_user_mode.h>
1010 #include <linux/seccomp.h>
1111 #include <linux/sched.h>
12+#include <linux/syscall_user_dispatch.h>
1213
1314 #include <asm/entry-common.h>
1415 #include <asm/syscall.h>
@@ -55,7 +56,6 @@ static __always_inline int arch_ptrace_report_syscall_entry(struct pt_regs *regs · 40 unmodified lines
5556 }
5657 #endif
5758
58−bool syscall_user_dispatch(struct pt_regs *regs);
5959 long trace_syscall_enter(struct pt_regs *regs, long syscall);
6060 void trace_syscall_exit(struct pt_regs *regs, long ret);
6161
@@ -232,10 +232,8 @@ static __always_inline void syscall_exit_work(struct pt_regs *regs, unsigned lon · 170 unmodified lines
232232 * of these syscalls is unknown.
233233 */
234234 if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) {
235− if (unlikely(current->syscall_dispatch.on_dispatch)) {
236− current->syscall_dispatch.on_dispatch = false;
235+ if (syscall_user_dispatch_clear_on_dispatch())
237236 return;
238− }
239237 }
240238
241239 audit_syscall_exit(regs);
include/linux/syscall_user_dispatch.h+26−2
@@ -6,9 +6,23 @@ · 5 unmodified lines
66 #define _SYSCALL_USER_DISPATCH_H
77
88 #include <linux/thread_info.h>
9+#include <linux/sched.h>
910 #include <linux/syscall_user_dispatch_types.h>
1011
11−#ifdef CONFIG_GENERIC_ENTRY
12+struct pt_regs;
13+
14+#ifdef CONFIG_SYSCALL_USER_DISPATCH
15+
16+bool syscall_user_dispatch(struct pt_regs *regs);
17+
18+static __always_inline bool syscall_user_dispatch_clear_on_dispatch(void)
19+{
20+ if (likely(!current->syscall_dispatch.on_dispatch))
21+ return false;
22+
23+ current->syscall_dispatch.on_dispatch = false;
24+ return true;
25+}
1226
1327 int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,
1428 unsigned long len, char __user *selector);
@@ -24,6 +38,16 @@ int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long siz · 9 unmodified lines
2438
2539 #else
2640
41+static __always_inline bool syscall_user_dispatch(struct pt_regs *regs)
42+{
43+ return false;
44+}
45+
46+static __always_inline bool syscall_user_dispatch_clear_on_dispatch(void)
47+{
48+ return false;
49+}
50+
2751 static inline int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,
2852 unsigned long len, char __user *selector)
2953 {
@@ -46,6 +70,6 @@ static inline int syscall_user_dispatch_set_config(struct task_struct *task, · 16 unmodified lines
4670 return -EINVAL;
4771 }
4872
49−#endif /* CONFIG_GENERIC_ENTRY */
73+#endif /* CONFIG_SYSCALL_USER_DISPATCH */
5074
5175 #endif /* _SYSCALL_USER_DISPATCH_H */
include/linux/syscall_user_dispatch_types.h+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44
55 #include <linux/types.h>
66
7−#ifdef CONFIG_GENERIC_ENTRY
7+#ifdef CONFIG_SYSCALL_USER_DISPATCH
88
99 struct syscall_user_dispatch {
1010 char __user *selector;
kernel/entry/Makefile+2−1
@@ -13,5 +13,6 @@ CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong · 12 unmodified lines
1313 CFLAGS_common.o += -fno-stack-protector
1414
1515 obj-$(CONFIG_GENERIC_IRQ_ENTRY) += common.o
16−obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o syscall_user_dispatch.o
16+obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o
17+obj-$(CONFIG_SYSCALL_USER_DISPATCH) += syscall_user_dispatch.o
1718 obj-$(CONFIG_VIRT_XFER_TO_GUEST_WORK) += virt.o
tools/testing/selftests/syscall_user_dispatch/config+1−1
@@ -1 +1 @@
1−CONFIG_GENERIC_ENTRY=y
1+CONFIG_SYSCALL_USER_DISPATCH=y

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t