1179ef035SGabriel Krisman Bertazi // SPDX-License-Identifier: GPL-2.0-only
2179ef035SGabriel Krisman Bertazi /*
3179ef035SGabriel Krisman Bertazi * Copyright (c) 2020 Collabora Ltd.
4179ef035SGabriel Krisman Bertazi *
5179ef035SGabriel Krisman Bertazi * Test code for syscall user dispatch
6179ef035SGabriel Krisman Bertazi */
7179ef035SGabriel Krisman Bertazi
8179ef035SGabriel Krisman Bertazi #define _GNU_SOURCE
9179ef035SGabriel Krisman Bertazi #include <sys/prctl.h>
10179ef035SGabriel Krisman Bertazi #include <sys/sysinfo.h>
11179ef035SGabriel Krisman Bertazi #include <sys/syscall.h>
12179ef035SGabriel Krisman Bertazi #include <signal.h>
13179ef035SGabriel Krisman Bertazi
14179ef035SGabriel Krisman Bertazi #include <asm/unistd.h>
15179ef035SGabriel Krisman Bertazi #include "../kselftest_harness.h"
16179ef035SGabriel Krisman Bertazi
17179ef035SGabriel Krisman Bertazi #ifndef PR_SET_SYSCALL_USER_DISPATCH
18179ef035SGabriel Krisman Bertazi # define PR_SET_SYSCALL_USER_DISPATCH 59
19179ef035SGabriel Krisman Bertazi # define PR_SYS_DISPATCH_OFF 0
20179ef035SGabriel Krisman Bertazi # define PR_SYS_DISPATCH_ON 1
2136a6c843SGabriel Krisman Bertazi # define SYSCALL_DISPATCH_FILTER_ALLOW 0
2236a6c843SGabriel Krisman Bertazi # define SYSCALL_DISPATCH_FILTER_BLOCK 1
23179ef035SGabriel Krisman Bertazi #endif
24179ef035SGabriel Krisman Bertazi
25179ef035SGabriel Krisman Bertazi #ifndef SYS_USER_DISPATCH
26179ef035SGabriel Krisman Bertazi # define SYS_USER_DISPATCH 2
27179ef035SGabriel Krisman Bertazi #endif
28179ef035SGabriel Krisman Bertazi
29179ef035SGabriel Krisman Bertazi #ifdef __NR_syscalls
30179ef035SGabriel Krisman Bertazi # define MAGIC_SYSCALL_1 (__NR_syscalls + 1) /* Bad Linux syscall number */
31179ef035SGabriel Krisman Bertazi #else
32179ef035SGabriel Krisman Bertazi # define MAGIC_SYSCALL_1 (0xff00) /* Bad Linux syscall number */
33179ef035SGabriel Krisman Bertazi #endif
34179ef035SGabriel Krisman Bertazi
3536a6c843SGabriel Krisman Bertazi #define SYSCALL_DISPATCH_ON(x) ((x) = SYSCALL_DISPATCH_FILTER_BLOCK)
3636a6c843SGabriel Krisman Bertazi #define SYSCALL_DISPATCH_OFF(x) ((x) = SYSCALL_DISPATCH_FILTER_ALLOW)
37179ef035SGabriel Krisman Bertazi
38179ef035SGabriel Krisman Bertazi /* Test Summary:
39179ef035SGabriel Krisman Bertazi *
40179ef035SGabriel Krisman Bertazi * - dispatch_trigger_sigsys: Verify if PR_SET_SYSCALL_USER_DISPATCH is
41179ef035SGabriel Krisman Bertazi * able to trigger SIGSYS on a syscall.
42179ef035SGabriel Krisman Bertazi *
43179ef035SGabriel Krisman Bertazi * - bad_selector: Test that a bad selector value triggers SIGSYS with
44179ef035SGabriel Krisman Bertazi * si_errno EINVAL.
45179ef035SGabriel Krisman Bertazi *
46179ef035SGabriel Krisman Bertazi * - bad_prctl_param: Test that the API correctly rejects invalid
47179ef035SGabriel Krisman Bertazi * parameters on prctl
48179ef035SGabriel Krisman Bertazi *
49179ef035SGabriel Krisman Bertazi * - dispatch_and_return: Test that a syscall is selectively dispatched
50179ef035SGabriel Krisman Bertazi * to userspace depending on the value of selector.
51179ef035SGabriel Krisman Bertazi *
52179ef035SGabriel Krisman Bertazi * - disable_dispatch: Test that the PR_SYS_DISPATCH_OFF correctly
53179ef035SGabriel Krisman Bertazi * disables the dispatcher
54179ef035SGabriel Krisman Bertazi *
55179ef035SGabriel Krisman Bertazi * - direct_dispatch_range: Test that a syscall within the allowed range
56179ef035SGabriel Krisman Bertazi * can bypass the dispatcher.
57179ef035SGabriel Krisman Bertazi */
58179ef035SGabriel Krisman Bertazi
TEST_SIGNAL(dispatch_trigger_sigsys,SIGSYS)59179ef035SGabriel Krisman Bertazi TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)
60179ef035SGabriel Krisman Bertazi {
6136a6c843SGabriel Krisman Bertazi char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
62179ef035SGabriel Krisman Bertazi struct sysinfo info;
63179ef035SGabriel Krisman Bertazi int ret;
64179ef035SGabriel Krisman Bertazi
65179ef035SGabriel Krisman Bertazi ret = sysinfo(&info);
66179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret);
67179ef035SGabriel Krisman Bertazi
68179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, 0, &sel);
69179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
70179ef035SGabriel Krisman Bertazi TH_LOG("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH");
71179ef035SGabriel Krisman Bertazi }
72179ef035SGabriel Krisman Bertazi
73179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_ON(sel);
74179ef035SGabriel Krisman Bertazi
75179ef035SGabriel Krisman Bertazi sysinfo(&info);
76179ef035SGabriel Krisman Bertazi
77179ef035SGabriel Krisman Bertazi EXPECT_FALSE(true) {
78179ef035SGabriel Krisman Bertazi TH_LOG("Unreachable!");
79179ef035SGabriel Krisman Bertazi }
80179ef035SGabriel Krisman Bertazi }
81179ef035SGabriel Krisman Bertazi
TEST(bad_prctl_param)82179ef035SGabriel Krisman Bertazi TEST(bad_prctl_param)
83179ef035SGabriel Krisman Bertazi {
8436a6c843SGabriel Krisman Bertazi char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
85179ef035SGabriel Krisman Bertazi int op;
86179ef035SGabriel Krisman Bertazi
87179ef035SGabriel Krisman Bertazi /* Invalid op */
88179ef035SGabriel Krisman Bertazi op = -1;
89179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0, 0, &sel);
90179ef035SGabriel Krisman Bertazi ASSERT_EQ(EINVAL, errno);
91179ef035SGabriel Krisman Bertazi
92179ef035SGabriel Krisman Bertazi /* PR_SYS_DISPATCH_OFF */
93179ef035SGabriel Krisman Bertazi op = PR_SYS_DISPATCH_OFF;
94179ef035SGabriel Krisman Bertazi
95179ef035SGabriel Krisman Bertazi /* offset != 0 */
96179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x1, 0x0, 0);
97179ef035SGabriel Krisman Bertazi EXPECT_EQ(EINVAL, errno);
98179ef035SGabriel Krisman Bertazi
99179ef035SGabriel Krisman Bertazi /* len != 0 */
100179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0xff, 0);
101179ef035SGabriel Krisman Bertazi EXPECT_EQ(EINVAL, errno);
102179ef035SGabriel Krisman Bertazi
103179ef035SGabriel Krisman Bertazi /* sel != NULL */
104179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0x0, &sel);
105179ef035SGabriel Krisman Bertazi EXPECT_EQ(EINVAL, errno);
106179ef035SGabriel Krisman Bertazi
107179ef035SGabriel Krisman Bertazi /* Valid parameter */
108179ef035SGabriel Krisman Bertazi errno = 0;
109179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0x0, 0x0);
110179ef035SGabriel Krisman Bertazi EXPECT_EQ(0, errno);
111179ef035SGabriel Krisman Bertazi
112179ef035SGabriel Krisman Bertazi /* PR_SYS_DISPATCH_ON */
113179ef035SGabriel Krisman Bertazi op = PR_SYS_DISPATCH_ON;
114179ef035SGabriel Krisman Bertazi
115179ef035SGabriel Krisman Bertazi /* Dispatcher region is bad (offset > 0 && len == 0) */
116179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x1, 0x0, &sel);
117179ef035SGabriel Krisman Bertazi EXPECT_EQ(EINVAL, errno);
118179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, -1L, 0x0, &sel);
119179ef035SGabriel Krisman Bertazi EXPECT_EQ(EINVAL, errno);
120179ef035SGabriel Krisman Bertazi
121179ef035SGabriel Krisman Bertazi /* Invalid selector */
122179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0x1, (void *) -1);
123179ef035SGabriel Krisman Bertazi ASSERT_EQ(EFAULT, errno);
124179ef035SGabriel Krisman Bertazi
125179ef035SGabriel Krisman Bertazi /*
126179ef035SGabriel Krisman Bertazi * Dispatcher range overflows unsigned long
127179ef035SGabriel Krisman Bertazi */
128179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 1, -1L, &sel);
129179ef035SGabriel Krisman Bertazi ASSERT_EQ(EINVAL, errno) {
130179ef035SGabriel Krisman Bertazi TH_LOG("Should reject bad syscall range");
131179ef035SGabriel Krisman Bertazi }
132179ef035SGabriel Krisman Bertazi
133179ef035SGabriel Krisman Bertazi /*
134179ef035SGabriel Krisman Bertazi * Allowed range overflows usigned long
135179ef035SGabriel Krisman Bertazi */
136179ef035SGabriel Krisman Bertazi prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, -1L, 0x1, &sel);
137179ef035SGabriel Krisman Bertazi ASSERT_EQ(EINVAL, errno) {
138179ef035SGabriel Krisman Bertazi TH_LOG("Should reject bad syscall range");
139179ef035SGabriel Krisman Bertazi }
140179ef035SGabriel Krisman Bertazi }
141179ef035SGabriel Krisman Bertazi
142179ef035SGabriel Krisman Bertazi /*
143179ef035SGabriel Krisman Bertazi * Use global selector for handle_sigsys tests, to avoid passing
144179ef035SGabriel Krisman Bertazi * selector to signal handler
145179ef035SGabriel Krisman Bertazi */
146179ef035SGabriel Krisman Bertazi char glob_sel;
147179ef035SGabriel Krisman Bertazi int nr_syscalls_emulated;
148179ef035SGabriel Krisman Bertazi int si_code;
149179ef035SGabriel Krisman Bertazi int si_errno;
150179ef035SGabriel Krisman Bertazi
handle_sigsys(int sig,siginfo_t * info,void * ucontext)151179ef035SGabriel Krisman Bertazi static void handle_sigsys(int sig, siginfo_t *info, void *ucontext)
152179ef035SGabriel Krisman Bertazi {
153179ef035SGabriel Krisman Bertazi si_code = info->si_code;
154179ef035SGabriel Krisman Bertazi si_errno = info->si_errno;
155179ef035SGabriel Krisman Bertazi
156179ef035SGabriel Krisman Bertazi if (info->si_syscall == MAGIC_SYSCALL_1)
157179ef035SGabriel Krisman Bertazi nr_syscalls_emulated++;
158179ef035SGabriel Krisman Bertazi
159179ef035SGabriel Krisman Bertazi /* In preparation for sigreturn. */
160179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_OFF(glob_sel);
161*1bb87514SClément Léger
162*1bb87514SClément Léger /*
163*1bb87514SClément Léger * The tests for argument handling assume that `syscall(x) == x`. This
164*1bb87514SClément Léger * is a NOP on x86 because the syscall number is passed in %rax, which
165*1bb87514SClément Léger * happens to also be the function ABI return register. Other
166*1bb87514SClément Léger * architectures may need to swizzle the arguments around.
167*1bb87514SClément Léger */
168*1bb87514SClément Léger #if defined(__riscv)
169*1bb87514SClément Léger /* REG_A7 is not defined in libc headers */
170*1bb87514SClément Léger # define REG_A7 (REG_A0 + 7)
171*1bb87514SClément Léger
172*1bb87514SClément Léger ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] =
173*1bb87514SClément Léger ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7];
174*1bb87514SClément Léger #endif
175179ef035SGabriel Krisman Bertazi }
176179ef035SGabriel Krisman Bertazi
TEST(dispatch_and_return)177179ef035SGabriel Krisman Bertazi TEST(dispatch_and_return)
178179ef035SGabriel Krisman Bertazi {
179179ef035SGabriel Krisman Bertazi long ret;
180179ef035SGabriel Krisman Bertazi struct sigaction act;
181179ef035SGabriel Krisman Bertazi sigset_t mask;
182179ef035SGabriel Krisman Bertazi
183179ef035SGabriel Krisman Bertazi glob_sel = 0;
184179ef035SGabriel Krisman Bertazi nr_syscalls_emulated = 0;
185179ef035SGabriel Krisman Bertazi si_code = 0;
186179ef035SGabriel Krisman Bertazi si_errno = 0;
187179ef035SGabriel Krisman Bertazi
188179ef035SGabriel Krisman Bertazi memset(&act, 0, sizeof(act));
189179ef035SGabriel Krisman Bertazi sigemptyset(&mask);
190179ef035SGabriel Krisman Bertazi
191179ef035SGabriel Krisman Bertazi act.sa_sigaction = handle_sigsys;
192179ef035SGabriel Krisman Bertazi act.sa_flags = SA_SIGINFO;
193179ef035SGabriel Krisman Bertazi act.sa_mask = mask;
194179ef035SGabriel Krisman Bertazi
195179ef035SGabriel Krisman Bertazi ret = sigaction(SIGSYS, &act, NULL);
196179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret);
197179ef035SGabriel Krisman Bertazi
198179ef035SGabriel Krisman Bertazi /* Make sure selector is good prior to prctl. */
199179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_OFF(glob_sel);
200179ef035SGabriel Krisman Bertazi
201179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, 0, &glob_sel);
202179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
203179ef035SGabriel Krisman Bertazi TH_LOG("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH");
204179ef035SGabriel Krisman Bertazi }
205179ef035SGabriel Krisman Bertazi
206179ef035SGabriel Krisman Bertazi /* MAGIC_SYSCALL_1 doesn't exist. */
207179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_OFF(glob_sel);
208179ef035SGabriel Krisman Bertazi ret = syscall(MAGIC_SYSCALL_1);
209179ef035SGabriel Krisman Bertazi EXPECT_EQ(-1, ret) {
210179ef035SGabriel Krisman Bertazi TH_LOG("Dispatch triggered unexpectedly");
211179ef035SGabriel Krisman Bertazi }
212179ef035SGabriel Krisman Bertazi
213179ef035SGabriel Krisman Bertazi /* MAGIC_SYSCALL_1 should be emulated. */
214179ef035SGabriel Krisman Bertazi nr_syscalls_emulated = 0;
215179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_ON(glob_sel);
216179ef035SGabriel Krisman Bertazi
217179ef035SGabriel Krisman Bertazi ret = syscall(MAGIC_SYSCALL_1);
218179ef035SGabriel Krisman Bertazi EXPECT_EQ(MAGIC_SYSCALL_1, ret) {
219179ef035SGabriel Krisman Bertazi TH_LOG("Failed to intercept syscall");
220179ef035SGabriel Krisman Bertazi }
221179ef035SGabriel Krisman Bertazi EXPECT_EQ(1, nr_syscalls_emulated) {
222179ef035SGabriel Krisman Bertazi TH_LOG("Failed to emulate syscall");
223179ef035SGabriel Krisman Bertazi }
224179ef035SGabriel Krisman Bertazi ASSERT_EQ(SYS_USER_DISPATCH, si_code) {
225179ef035SGabriel Krisman Bertazi TH_LOG("Bad si_code in SIGSYS");
226179ef035SGabriel Krisman Bertazi }
227179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, si_errno) {
228179ef035SGabriel Krisman Bertazi TH_LOG("Bad si_errno in SIGSYS");
229179ef035SGabriel Krisman Bertazi }
230179ef035SGabriel Krisman Bertazi }
231179ef035SGabriel Krisman Bertazi
TEST_SIGNAL(bad_selector,SIGSYS)232179ef035SGabriel Krisman Bertazi TEST_SIGNAL(bad_selector, SIGSYS)
233179ef035SGabriel Krisman Bertazi {
234179ef035SGabriel Krisman Bertazi long ret;
235179ef035SGabriel Krisman Bertazi struct sigaction act;
236179ef035SGabriel Krisman Bertazi sigset_t mask;
237179ef035SGabriel Krisman Bertazi struct sysinfo info;
238179ef035SGabriel Krisman Bertazi
23936a6c843SGabriel Krisman Bertazi glob_sel = SYSCALL_DISPATCH_FILTER_ALLOW;
240179ef035SGabriel Krisman Bertazi nr_syscalls_emulated = 0;
241179ef035SGabriel Krisman Bertazi si_code = 0;
242179ef035SGabriel Krisman Bertazi si_errno = 0;
243179ef035SGabriel Krisman Bertazi
244179ef035SGabriel Krisman Bertazi memset(&act, 0, sizeof(act));
245179ef035SGabriel Krisman Bertazi sigemptyset(&mask);
246179ef035SGabriel Krisman Bertazi
247179ef035SGabriel Krisman Bertazi act.sa_sigaction = handle_sigsys;
248179ef035SGabriel Krisman Bertazi act.sa_flags = SA_SIGINFO;
249179ef035SGabriel Krisman Bertazi act.sa_mask = mask;
250179ef035SGabriel Krisman Bertazi
251179ef035SGabriel Krisman Bertazi ret = sigaction(SIGSYS, &act, NULL);
252179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret);
253179ef035SGabriel Krisman Bertazi
254179ef035SGabriel Krisman Bertazi /* Make sure selector is good prior to prctl. */
255179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_OFF(glob_sel);
256179ef035SGabriel Krisman Bertazi
257179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, 0, &glob_sel);
258179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
259179ef035SGabriel Krisman Bertazi TH_LOG("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH");
260179ef035SGabriel Krisman Bertazi }
261179ef035SGabriel Krisman Bertazi
262179ef035SGabriel Krisman Bertazi glob_sel = -1;
263179ef035SGabriel Krisman Bertazi
264179ef035SGabriel Krisman Bertazi sysinfo(&info);
265179ef035SGabriel Krisman Bertazi
266179ef035SGabriel Krisman Bertazi /* Even though it is ready to catch SIGSYS, the signal is
267179ef035SGabriel Krisman Bertazi * supposed to be uncatchable.
268179ef035SGabriel Krisman Bertazi */
269179ef035SGabriel Krisman Bertazi
270179ef035SGabriel Krisman Bertazi EXPECT_FALSE(true) {
271179ef035SGabriel Krisman Bertazi TH_LOG("Unreachable!");
272179ef035SGabriel Krisman Bertazi }
273179ef035SGabriel Krisman Bertazi }
274179ef035SGabriel Krisman Bertazi
TEST(disable_dispatch)275179ef035SGabriel Krisman Bertazi TEST(disable_dispatch)
276179ef035SGabriel Krisman Bertazi {
277179ef035SGabriel Krisman Bertazi int ret;
278179ef035SGabriel Krisman Bertazi struct sysinfo info;
279179ef035SGabriel Krisman Bertazi char sel = 0;
280179ef035SGabriel Krisman Bertazi
281179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, 0, &sel);
282179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
283179ef035SGabriel Krisman Bertazi TH_LOG("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH");
284179ef035SGabriel Krisman Bertazi }
285179ef035SGabriel Krisman Bertazi
286179ef035SGabriel Krisman Bertazi /* MAGIC_SYSCALL_1 doesn't exist. */
287179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_OFF(glob_sel);
288179ef035SGabriel Krisman Bertazi
289179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_OFF, 0, 0, 0);
290179ef035SGabriel Krisman Bertazi EXPECT_EQ(0, ret) {
291179ef035SGabriel Krisman Bertazi TH_LOG("Failed to unset syscall user dispatch");
292179ef035SGabriel Krisman Bertazi }
293179ef035SGabriel Krisman Bertazi
294179ef035SGabriel Krisman Bertazi /* Shouldn't have any effect... */
295179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_ON(glob_sel);
296179ef035SGabriel Krisman Bertazi
297179ef035SGabriel Krisman Bertazi ret = syscall(__NR_sysinfo, &info);
298179ef035SGabriel Krisman Bertazi EXPECT_EQ(0, ret) {
299179ef035SGabriel Krisman Bertazi TH_LOG("Dispatch triggered unexpectedly");
300179ef035SGabriel Krisman Bertazi }
301179ef035SGabriel Krisman Bertazi }
302179ef035SGabriel Krisman Bertazi
TEST(direct_dispatch_range)303179ef035SGabriel Krisman Bertazi TEST(direct_dispatch_range)
304179ef035SGabriel Krisman Bertazi {
305179ef035SGabriel Krisman Bertazi int ret = 0;
306179ef035SGabriel Krisman Bertazi struct sysinfo info;
30736a6c843SGabriel Krisman Bertazi char sel = SYSCALL_DISPATCH_FILTER_ALLOW;
308179ef035SGabriel Krisman Bertazi
309179ef035SGabriel Krisman Bertazi /*
310179ef035SGabriel Krisman Bertazi * Instead of calculating libc addresses; allow the entire
311179ef035SGabriel Krisman Bertazi * memory map and lock the selector.
312179ef035SGabriel Krisman Bertazi */
313179ef035SGabriel Krisman Bertazi ret = prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, -1L, &sel);
314179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
315179ef035SGabriel Krisman Bertazi TH_LOG("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH");
316179ef035SGabriel Krisman Bertazi }
317179ef035SGabriel Krisman Bertazi
318179ef035SGabriel Krisman Bertazi SYSCALL_DISPATCH_ON(sel);
319179ef035SGabriel Krisman Bertazi
320179ef035SGabriel Krisman Bertazi ret = sysinfo(&info);
321179ef035SGabriel Krisman Bertazi ASSERT_EQ(0, ret) {
322179ef035SGabriel Krisman Bertazi TH_LOG("Dispatch triggered unexpectedly");
323179ef035SGabriel Krisman Bertazi }
324179ef035SGabriel Krisman Bertazi }
325179ef035SGabriel Krisman Bertazi
326179ef035SGabriel Krisman Bertazi TEST_HARNESS_MAIN
327