Commit 36a6c843 authored by Gabriel Krisman Bertazi's avatar Gabriel Krisman Bertazi Committed by Thomas Gleixner

entry: Use different define for selector variable in SUD

Michael Kerrisk suggested that, from an API perspective, it is a bad
idea to share the PR_SYS_DISPATCH_ defines between the prctl operation
and the selector variable.

Therefore, define two new constants to be used by SUD's selector variable
and update the corresponding documentation and test cases.

While this changes the API syscall user dispatch has never been part of a
Linux release, it will show up for the first time in 5.11.
Suggested-by: default avatarMichael Kerrisk (man-pages) <mtk.manpages@gmail.com>
Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210205184321.2062251-1-krisman@collabora.com
parent 6342adca
...@@ -70,8 +70,8 @@ trampoline code on the vDSO, that trampoline is never intercepted. ...@@ -70,8 +70,8 @@ trampoline code on the vDSO, that trampoline is never intercepted.
[selector] is a pointer to a char-sized region in the process memory [selector] is a pointer to a char-sized region in the process memory
region, that provides a quick way to enable disable syscall redirection region, that provides a quick way to enable disable syscall redirection
thread-wide, without the need to invoke the kernel directly. selector thread-wide, without the need to invoke the kernel directly. selector
can be set to PR_SYS_DISPATCH_ON or PR_SYS_DISPATCH_OFF. Any other can be set to SYSCALL_DISPATCH_FILTER_ALLOW or SYSCALL_DISPATCH_FILTER_BLOCK.
value should terminate the program with a SIGSYS. Any other value should terminate the program with a SIGSYS.
Security Notes Security Notes
-------------- --------------
......
...@@ -251,5 +251,8 @@ struct prctl_mm_map { ...@@ -251,5 +251,8 @@ struct prctl_mm_map {
#define PR_SET_SYSCALL_USER_DISPATCH 59 #define PR_SET_SYSCALL_USER_DISPATCH 59
# define PR_SYS_DISPATCH_OFF 0 # define PR_SYS_DISPATCH_OFF 0
# define PR_SYS_DISPATCH_ON 1 # define PR_SYS_DISPATCH_ON 1
/* The control values for the user space selector when dispatch is enabled */
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
#endif /* _LINUX_PRCTL_H */ #endif /* _LINUX_PRCTL_H */
...@@ -50,10 +50,10 @@ bool syscall_user_dispatch(struct pt_regs *regs) ...@@ -50,10 +50,10 @@ bool syscall_user_dispatch(struct pt_regs *regs)
if (unlikely(__get_user(state, sd->selector))) if (unlikely(__get_user(state, sd->selector)))
do_exit(SIGSEGV); do_exit(SIGSEGV);
if (likely(state == PR_SYS_DISPATCH_OFF)) if (likely(state == SYSCALL_DISPATCH_FILTER_ALLOW))
return false; return false;
if (state != PR_SYS_DISPATCH_ON) if (state != SYSCALL_DISPATCH_FILTER_BLOCK)
do_exit(SIGSYS); do_exit(SIGSYS);
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
# define PR_SET_SYSCALL_USER_DISPATCH 59 # define PR_SET_SYSCALL_USER_DISPATCH 59
# define PR_SYS_DISPATCH_OFF 0 # define PR_SYS_DISPATCH_OFF 0
# define PR_SYS_DISPATCH_ON 1 # define PR_SYS_DISPATCH_ON 1
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
#endif #endif
#ifdef __NR_syscalls #ifdef __NR_syscalls
...@@ -55,8 +57,8 @@ unsigned long trapped_call_count = 0; ...@@ -55,8 +57,8 @@ unsigned long trapped_call_count = 0;
unsigned long native_call_count = 0; unsigned long native_call_count = 0;
char selector; char selector;
#define SYSCALL_BLOCK (selector = PR_SYS_DISPATCH_ON) #define SYSCALL_BLOCK (selector = SYSCALL_DISPATCH_FILTER_BLOCK)
#define SYSCALL_UNBLOCK (selector = PR_SYS_DISPATCH_OFF) #define SYSCALL_UNBLOCK (selector = SYSCALL_DISPATCH_FILTER_ALLOW)
#define CALIBRATION_STEP 100000 #define CALIBRATION_STEP 100000
#define CALIBRATE_TO_SECS 5 #define CALIBRATE_TO_SECS 5
...@@ -170,7 +172,7 @@ int main(void) ...@@ -170,7 +172,7 @@ int main(void)
syscall(MAGIC_SYSCALL_1); syscall(MAGIC_SYSCALL_1);
#ifdef TEST_BLOCKED_RETURN #ifdef TEST_BLOCKED_RETURN
if (selector == PR_SYS_DISPATCH_OFF) { if (selector == SYSCALL_DISPATCH_FILTER_ALLOW) {
fprintf(stderr, "Failed to return with selector blocked.\n"); fprintf(stderr, "Failed to return with selector blocked.\n");
exit(-1); exit(-1);
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
# define PR_SET_SYSCALL_USER_DISPATCH 59 # define PR_SET_SYSCALL_USER_DISPATCH 59
# define PR_SYS_DISPATCH_OFF 0 # define PR_SYS_DISPATCH_OFF 0
# define PR_SYS_DISPATCH_ON 1 # define PR_SYS_DISPATCH_ON 1
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
#endif #endif
#ifndef SYS_USER_DISPATCH #ifndef SYS_USER_DISPATCH
...@@ -30,8 +32,8 @@ ...@@ -30,8 +32,8 @@
# define MAGIC_SYSCALL_1 (0xff00) /* Bad Linux syscall number */ # define MAGIC_SYSCALL_1 (0xff00) /* Bad Linux syscall number */
#endif #endif
#define SYSCALL_DISPATCH_ON(x) ((x) = 1) #define SYSCALL_DISPATCH_ON(x) ((x) = SYSCALL_DISPATCH_FILTER_BLOCK)
#define SYSCALL_DISPATCH_OFF(x) ((x) = 0) #define SYSCALL_DISPATCH_OFF(x) ((x) = SYSCALL_DISPATCH_FILTER_ALLOW)
/* Test Summary: /* Test Summary:
* *
...@@ -56,7 +58,7 @@ ...@@ -56,7 +58,7 @@
TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS) TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)
{ {
char sel = 0; char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
struct sysinfo info; struct sysinfo info;
int ret; int ret;
...@@ -79,7 +81,7 @@ TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS) ...@@ -79,7 +81,7 @@ TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)
TEST(bad_prctl_param) TEST(bad_prctl_param)
{ {
char sel = 0; char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
int op; int op;
/* Invalid op */ /* Invalid op */
...@@ -220,7 +222,7 @@ TEST_SIGNAL(bad_selector, SIGSYS) ...@@ -220,7 +222,7 @@ TEST_SIGNAL(bad_selector, SIGSYS)
sigset_t mask; sigset_t mask;
struct sysinfo info; struct sysinfo info;
glob_sel = 0; glob_sel = SYSCALL_DISPATCH_FILTER_ALLOW;
nr_syscalls_emulated = 0; nr_syscalls_emulated = 0;
si_code = 0; si_code = 0;
si_errno = 0; si_errno = 0;
...@@ -288,7 +290,7 @@ TEST(direct_dispatch_range) ...@@ -288,7 +290,7 @@ TEST(direct_dispatch_range)
{ {
int ret = 0; int ret = 0;
struct sysinfo info; struct sysinfo info;
char sel = 0; char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
/* /*
* Instead of calculating libc addresses; allow the entire * Instead of calculating libc addresses; allow the entire
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment