Skip to content

Commit 36a6c84

Browse files
krisman-at-collaboraKAGA-KOKO
authored andcommitted
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: Michael Kerrisk (man-pages) <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6342adc commit 36a6c84

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

Documentation/admin-guide/syscall-user-dispatch.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ trampoline code on the vDSO, that trampoline is never intercepted.
7070
[selector] is a pointer to a char-sized region in the process memory
7171
region, that provides a quick way to enable disable syscall redirection
7272
thread-wide, without the need to invoke the kernel directly. selector
73-
can be set to PR_SYS_DISPATCH_ON or PR_SYS_DISPATCH_OFF. Any other
74-
value should terminate the program with a SIGSYS.
73+
can be set to SYSCALL_DISPATCH_FILTER_ALLOW or SYSCALL_DISPATCH_FILTER_BLOCK.
74+
Any other value should terminate the program with a SIGSYS.
7575

7676
Security Notes
7777
--------------

include/uapi/linux/prctl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,8 @@ struct prctl_mm_map {
251251
#define PR_SET_SYSCALL_USER_DISPATCH 59
252252
# define PR_SYS_DISPATCH_OFF 0
253253
# define PR_SYS_DISPATCH_ON 1
254+
/* The control values for the user space selector when dispatch is enabled */
255+
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
256+
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
254257

255258
#endif /* _LINUX_PRCTL_H */

kernel/entry/syscall_user_dispatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ bool syscall_user_dispatch(struct pt_regs *regs)
5050
if (unlikely(__get_user(state, sd->selector)))
5151
do_exit(SIGSEGV);
5252

53-
if (likely(state == PR_SYS_DISPATCH_OFF))
53+
if (likely(state == SYSCALL_DISPATCH_FILTER_ALLOW))
5454
return false;
5555

56-
if (state != PR_SYS_DISPATCH_ON)
56+
if (state != SYSCALL_DISPATCH_FILTER_BLOCK)
5757
do_exit(SIGSYS);
5858
}
5959

tools/testing/selftests/syscall_user_dispatch/sud_benchmark.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# define PR_SET_SYSCALL_USER_DISPATCH 59
2323
# define PR_SYS_DISPATCH_OFF 0
2424
# define PR_SYS_DISPATCH_ON 1
25+
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
26+
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
2527
#endif
2628

2729
#ifdef __NR_syscalls
@@ -55,8 +57,8 @@ unsigned long trapped_call_count = 0;
5557
unsigned long native_call_count = 0;
5658

5759
char selector;
58-
#define SYSCALL_BLOCK (selector = PR_SYS_DISPATCH_ON)
59-
#define SYSCALL_UNBLOCK (selector = PR_SYS_DISPATCH_OFF)
60+
#define SYSCALL_BLOCK (selector = SYSCALL_DISPATCH_FILTER_BLOCK)
61+
#define SYSCALL_UNBLOCK (selector = SYSCALL_DISPATCH_FILTER_ALLOW)
6062

6163
#define CALIBRATION_STEP 100000
6264
#define CALIBRATE_TO_SECS 5
@@ -170,7 +172,7 @@ int main(void)
170172
syscall(MAGIC_SYSCALL_1);
171173

172174
#ifdef TEST_BLOCKED_RETURN
173-
if (selector == PR_SYS_DISPATCH_OFF) {
175+
if (selector == SYSCALL_DISPATCH_FILTER_ALLOW) {
174176
fprintf(stderr, "Failed to return with selector blocked.\n");
175177
exit(-1);
176178
}

tools/testing/selftests/syscall_user_dispatch/sud_test.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# define PR_SET_SYSCALL_USER_DISPATCH 59
1919
# define PR_SYS_DISPATCH_OFF 0
2020
# define PR_SYS_DISPATCH_ON 1
21+
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
22+
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
2123
#endif
2224

2325
#ifndef SYS_USER_DISPATCH
@@ -30,8 +32,8 @@
3032
# define MAGIC_SYSCALL_1 (0xff00) /* Bad Linux syscall number */
3133
#endif
3234

33-
#define SYSCALL_DISPATCH_ON(x) ((x) = 1)
34-
#define SYSCALL_DISPATCH_OFF(x) ((x) = 0)
35+
#define SYSCALL_DISPATCH_ON(x) ((x) = SYSCALL_DISPATCH_FILTER_BLOCK)
36+
#define SYSCALL_DISPATCH_OFF(x) ((x) = SYSCALL_DISPATCH_FILTER_ALLOW)
3537

3638
/* Test Summary:
3739
*
@@ -56,7 +58,7 @@
5658

5759
TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)
5860
{
59-
char sel = 0;
61+
char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
6062
struct sysinfo info;
6163
int ret;
6264

@@ -79,7 +81,7 @@ TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)
7981

8082
TEST(bad_prctl_param)
8183
{
82-
char sel = 0;
84+
char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
8385
int op;
8486

8587
/* Invalid op */
@@ -220,7 +222,7 @@ TEST_SIGNAL(bad_selector, SIGSYS)
220222
sigset_t mask;
221223
struct sysinfo info;
222224

223-
glob_sel = 0;
225+
glob_sel = SYSCALL_DISPATCH_FILTER_ALLOW;
224226
nr_syscalls_emulated = 0;
225227
si_code = 0;
226228
si_errno = 0;
@@ -288,7 +290,7 @@ TEST(direct_dispatch_range)
288290
{
289291
int ret = 0;
290292
struct sysinfo info;
291-
char sel = 0;
293+
char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
292294

293295
/*
294296
* Instead of calculating libc addresses; allow the entire

0 commit comments

Comments
 (0)