diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/proc/.gitignore | 1 | ||||
-rw-r--r-- | tools/testing/selftests/proc/Makefile | 1 | ||||
-rw-r--r-- | tools/testing/selftests/proc/proc-pid-vm.c | 17 | ||||
-rw-r--r-- | tools/testing/selftests/proc/setns-sysvipc.c | 133 | ||||
-rw-r--r-- | tools/testing/selftests/ptrace/.gitignore | 1 | ||||
-rw-r--r-- | tools/testing/selftests/ptrace/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/ptrace/get_syscall_info.c | 271 | ||||
-rw-r--r-- | tools/testing/selftests/seccomp/seccomp_bpf.c | 13 |
8 files changed, 432 insertions, 7 deletions
diff --git a/tools/testing/selftests/proc/.gitignore b/tools/testing/selftests/proc/.gitignore index 444ad39d3700..66fab4c58ed4 100644 --- a/tools/testing/selftests/proc/.gitignore +++ b/tools/testing/selftests/proc/.gitignore | |||
@@ -12,4 +12,5 @@ | |||
12 | /read | 12 | /read |
13 | /self | 13 | /self |
14 | /setns-dcache | 14 | /setns-dcache |
15 | /setns-sysvipc | ||
15 | /thread-self | 16 | /thread-self |
diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile index 9f09fcd09ea3..a8ed0f684829 100644 --- a/tools/testing/selftests/proc/Makefile +++ b/tools/testing/selftests/proc/Makefile | |||
@@ -17,6 +17,7 @@ TEST_GEN_PROGS += proc-uptime-002 | |||
17 | TEST_GEN_PROGS += read | 17 | TEST_GEN_PROGS += read |
18 | TEST_GEN_PROGS += self | 18 | TEST_GEN_PROGS += self |
19 | TEST_GEN_PROGS += setns-dcache | 19 | TEST_GEN_PROGS += setns-dcache |
20 | TEST_GEN_PROGS += setns-sysvipc | ||
20 | TEST_GEN_PROGS += thread-self | 21 | TEST_GEN_PROGS += thread-self |
21 | 22 | ||
22 | include ../lib.mk | 23 | include ../lib.mk |
diff --git a/tools/testing/selftests/proc/proc-pid-vm.c b/tools/testing/selftests/proc/proc-pid-vm.c index 853aa164a401..18a3bde8bc96 100644 --- a/tools/testing/selftests/proc/proc-pid-vm.c +++ b/tools/testing/selftests/proc/proc-pid-vm.c | |||
@@ -215,6 +215,11 @@ static const char str_vsyscall[] = | |||
215 | "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n"; | 215 | "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n"; |
216 | 216 | ||
217 | #ifdef __x86_64__ | 217 | #ifdef __x86_64__ |
218 | static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___) | ||
219 | { | ||
220 | _exit(1); | ||
221 | } | ||
222 | |||
218 | /* | 223 | /* |
219 | * vsyscall page can't be unmapped, probe it with memory load. | 224 | * vsyscall page can't be unmapped, probe it with memory load. |
220 | */ | 225 | */ |
@@ -231,11 +236,19 @@ static void vsyscall(void) | |||
231 | if (pid == 0) { | 236 | if (pid == 0) { |
232 | struct rlimit rlim = {0, 0}; | 237 | struct rlimit rlim = {0, 0}; |
233 | (void)setrlimit(RLIMIT_CORE, &rlim); | 238 | (void)setrlimit(RLIMIT_CORE, &rlim); |
239 | |||
240 | /* Hide "segfault at ffffffffff600000" messages. */ | ||
241 | struct sigaction act; | ||
242 | memset(&act, 0, sizeof(struct sigaction)); | ||
243 | act.sa_flags = SA_SIGINFO; | ||
244 | act.sa_sigaction = sigaction_SIGSEGV; | ||
245 | (void)sigaction(SIGSEGV, &act, NULL); | ||
246 | |||
234 | *(volatile int *)0xffffffffff600000UL; | 247 | *(volatile int *)0xffffffffff600000UL; |
235 | exit(0); | 248 | exit(0); |
236 | } | 249 | } |
237 | wait(&wstatus); | 250 | waitpid(pid, &wstatus, 0); |
238 | if (WIFEXITED(wstatus)) { | 251 | if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) { |
239 | g_vsyscall = true; | 252 | g_vsyscall = true; |
240 | } | 253 | } |
241 | } | 254 | } |
diff --git a/tools/testing/selftests/proc/setns-sysvipc.c b/tools/testing/selftests/proc/setns-sysvipc.c new file mode 100644 index 000000000000..903890c5e587 --- /dev/null +++ b/tools/testing/selftests/proc/setns-sysvipc.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Copyright © 2019 Alexey Dobriyan <adobriyan@gmail.com> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | /* | ||
17 | * Test that setns(CLONE_NEWIPC) points to new /proc/sysvipc content even | ||
18 | * if old one is in dcache. | ||
19 | */ | ||
20 | #undef NDEBUG | ||
21 | #include <assert.h> | ||
22 | #include <errno.h> | ||
23 | #include <stdio.h> | ||
24 | #include <sched.h> | ||
25 | #include <signal.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | #include <unistd.h> | ||
29 | #include <sys/types.h> | ||
30 | #include <sys/stat.h> | ||
31 | #include <fcntl.h> | ||
32 | #include <sys/ipc.h> | ||
33 | #include <sys/shm.h> | ||
34 | |||
35 | static pid_t pid = -1; | ||
36 | |||
37 | static void f(void) | ||
38 | { | ||
39 | if (pid > 0) { | ||
40 | kill(pid, SIGTERM); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | int main(void) | ||
45 | { | ||
46 | int fd[2]; | ||
47 | char _ = 0; | ||
48 | int nsfd; | ||
49 | |||
50 | atexit(f); | ||
51 | |||
52 | /* Check for priviledges and syscall availability straight away. */ | ||
53 | if (unshare(CLONE_NEWIPC) == -1) { | ||
54 | if (errno == ENOSYS || errno == EPERM) { | ||
55 | return 4; | ||
56 | } | ||
57 | return 1; | ||
58 | } | ||
59 | /* Distinguisher between two otherwise empty IPC namespaces. */ | ||
60 | if (shmget(IPC_PRIVATE, 1, IPC_CREAT) == -1) { | ||
61 | return 1; | ||
62 | } | ||
63 | |||
64 | if (pipe(fd) == -1) { | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | pid = fork(); | ||
69 | if (pid == -1) { | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | if (pid == 0) { | ||
74 | if (unshare(CLONE_NEWIPC) == -1) { | ||
75 | return 1; | ||
76 | } | ||
77 | |||
78 | if (write(fd[1], &_, 1) != 1) { | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | pause(); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | if (read(fd[0], &_, 1) != 1) { | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | { | ||
92 | char buf[64]; | ||
93 | snprintf(buf, sizeof(buf), "/proc/%u/ns/ipc", pid); | ||
94 | nsfd = open(buf, O_RDONLY); | ||
95 | if (nsfd == -1) { | ||
96 | return 1; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /* Reliably pin dentry into dcache. */ | ||
101 | (void)open("/proc/sysvipc/shm", O_RDONLY); | ||
102 | |||
103 | if (setns(nsfd, CLONE_NEWIPC) == -1) { | ||
104 | return 1; | ||
105 | } | ||
106 | |||
107 | kill(pid, SIGTERM); | ||
108 | pid = 0; | ||
109 | |||
110 | { | ||
111 | char buf[4096]; | ||
112 | ssize_t rv; | ||
113 | int fd; | ||
114 | |||
115 | fd = open("/proc/sysvipc/shm", O_RDONLY); | ||
116 | if (fd == -1) { | ||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | #define S32 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n" | ||
121 | #define S64 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n" | ||
122 | rv = read(fd, buf, sizeof(buf)); | ||
123 | if (rv == strlen(S32)) { | ||
124 | assert(memcmp(buf, S32, strlen(S32)) == 0); | ||
125 | } else if (rv == strlen(S64)) { | ||
126 | assert(memcmp(buf, S64, strlen(S64)) == 0); | ||
127 | } else { | ||
128 | assert(0); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | return 0; | ||
133 | } | ||
diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index b3e59d41fd82..cfcc49a7def7 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | get_syscall_info | ||
1 | peeksiginfo | 2 | peeksiginfo |
diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index cb21c76a18ca..c0b7f89f0930 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # SPDX-License-Identifier: GPL-2.0-only | 1 | # SPDX-License-Identifier: GPL-2.0-only |
2 | CFLAGS += -iquote../../../../include/uapi -Wall | 2 | CFLAGS += -iquote../../../../include/uapi -Wall |
3 | 3 | ||
4 | TEST_GEN_PROGS := peeksiginfo | 4 | TEST_GEN_PROGS := get_syscall_info peeksiginfo |
5 | 5 | ||
6 | include ../lib.mk | 6 | include ../lib.mk |
diff --git a/tools/testing/selftests/ptrace/get_syscall_info.c b/tools/testing/selftests/ptrace/get_syscall_info.c new file mode 100644 index 000000000000..5bcd1c7b5be6 --- /dev/null +++ b/tools/testing/selftests/ptrace/get_syscall_info.c | |||
@@ -0,0 +1,271 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0+ | ||
2 | /* | ||
3 | * Copyright (c) 2018 Dmitry V. Levin <ldv@altlinux.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel | ||
7 | * matches userspace expectations. | ||
8 | */ | ||
9 | |||
10 | #include "../kselftest_harness.h" | ||
11 | #include <err.h> | ||
12 | #include <signal.h> | ||
13 | #include <asm/unistd.h> | ||
14 | #include "linux/ptrace.h" | ||
15 | |||
16 | static int | ||
17 | kill_tracee(pid_t pid) | ||
18 | { | ||
19 | if (!pid) | ||
20 | return 0; | ||
21 | |||
22 | int saved_errno = errno; | ||
23 | |||
24 | int rc = kill(pid, SIGKILL); | ||
25 | |||
26 | errno = saved_errno; | ||
27 | return rc; | ||
28 | } | ||
29 | |||
30 | static long | ||
31 | sys_ptrace(int request, pid_t pid, unsigned long addr, unsigned long data) | ||
32 | { | ||
33 | return syscall(__NR_ptrace, request, pid, addr, data); | ||
34 | } | ||
35 | |||
36 | #define LOG_KILL_TRACEE(fmt, ...) \ | ||
37 | do { \ | ||
38 | kill_tracee(pid); \ | ||
39 | TH_LOG("wait #%d: " fmt, \ | ||
40 | ptrace_stop, ##__VA_ARGS__); \ | ||
41 | } while (0) | ||
42 | |||
43 | TEST(get_syscall_info) | ||
44 | { | ||
45 | static const unsigned long args[][7] = { | ||
46 | /* a sequence of architecture-agnostic syscalls */ | ||
47 | { | ||
48 | __NR_chdir, | ||
49 | (unsigned long) "", | ||
50 | 0xbad1fed1, | ||
51 | 0xbad2fed2, | ||
52 | 0xbad3fed3, | ||
53 | 0xbad4fed4, | ||
54 | 0xbad5fed5 | ||
55 | }, | ||
56 | { | ||
57 | __NR_gettid, | ||
58 | 0xcaf0bea0, | ||
59 | 0xcaf1bea1, | ||
60 | 0xcaf2bea2, | ||
61 | 0xcaf3bea3, | ||
62 | 0xcaf4bea4, | ||
63 | 0xcaf5bea5 | ||
64 | }, | ||
65 | { | ||
66 | __NR_exit_group, | ||
67 | 0, | ||
68 | 0xfac1c0d1, | ||
69 | 0xfac2c0d2, | ||
70 | 0xfac3c0d3, | ||
71 | 0xfac4c0d4, | ||
72 | 0xfac5c0d5 | ||
73 | } | ||
74 | }; | ||
75 | const unsigned long *exp_args; | ||
76 | |||
77 | pid_t pid = fork(); | ||
78 | |||
79 | ASSERT_LE(0, pid) { | ||
80 | TH_LOG("fork: %m"); | ||
81 | } | ||
82 | |||
83 | if (pid == 0) { | ||
84 | /* get the pid before PTRACE_TRACEME */ | ||
85 | pid = getpid(); | ||
86 | ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { | ||
87 | TH_LOG("PTRACE_TRACEME: %m"); | ||
88 | } | ||
89 | ASSERT_EQ(0, kill(pid, SIGSTOP)) { | ||
90 | /* cannot happen */ | ||
91 | TH_LOG("kill SIGSTOP: %m"); | ||
92 | } | ||
93 | for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) { | ||
94 | syscall(args[i][0], | ||
95 | args[i][1], args[i][2], args[i][3], | ||
96 | args[i][4], args[i][5], args[i][6]); | ||
97 | } | ||
98 | /* unreachable */ | ||
99 | _exit(1); | ||
100 | } | ||
101 | |||
102 | const struct { | ||
103 | unsigned int is_error; | ||
104 | int rval; | ||
105 | } *exp_param, exit_param[] = { | ||
106 | { 1, -ENOENT }, /* chdir */ | ||
107 | { 0, pid } /* gettid */ | ||
108 | }; | ||
109 | |||
110 | unsigned int ptrace_stop; | ||
111 | |||
112 | for (ptrace_stop = 0; ; ++ptrace_stop) { | ||
113 | struct ptrace_syscall_info info = { | ||
114 | .op = 0xff /* invalid PTRACE_SYSCALL_INFO_* op */ | ||
115 | }; | ||
116 | const size_t size = sizeof(info); | ||
117 | const int expected_none_size = | ||
118 | (void *) &info.entry - (void *) &info; | ||
119 | const int expected_entry_size = | ||
120 | (void *) &info.entry.args[6] - (void *) &info; | ||
121 | const int expected_exit_size = | ||
122 | (void *) (&info.exit.is_error + 1) - | ||
123 | (void *) &info; | ||
124 | int status; | ||
125 | long rc; | ||
126 | |||
127 | ASSERT_EQ(pid, wait(&status)) { | ||
128 | /* cannot happen */ | ||
129 | LOG_KILL_TRACEE("wait: %m"); | ||
130 | } | ||
131 | if (WIFEXITED(status)) { | ||
132 | pid = 0; /* the tracee is no more */ | ||
133 | ASSERT_EQ(0, WEXITSTATUS(status)); | ||
134 | break; | ||
135 | } | ||
136 | ASSERT_FALSE(WIFSIGNALED(status)) { | ||
137 | pid = 0; /* the tracee is no more */ | ||
138 | LOG_KILL_TRACEE("unexpected signal %u", | ||
139 | WTERMSIG(status)); | ||
140 | } | ||
141 | ASSERT_TRUE(WIFSTOPPED(status)) { | ||
142 | /* cannot happen */ | ||
143 | LOG_KILL_TRACEE("unexpected wait status %#x", status); | ||
144 | } | ||
145 | |||
146 | switch (WSTOPSIG(status)) { | ||
147 | case SIGSTOP: | ||
148 | ASSERT_EQ(0, ptrace_stop) { | ||
149 | LOG_KILL_TRACEE("unexpected signal stop"); | ||
150 | } | ||
151 | ASSERT_EQ(0, sys_ptrace(PTRACE_SETOPTIONS, pid, 0, | ||
152 | PTRACE_O_TRACESYSGOOD)) { | ||
153 | LOG_KILL_TRACEE("PTRACE_SETOPTIONS: %m"); | ||
154 | } | ||
155 | ASSERT_LT(0, (rc = sys_ptrace(PTRACE_GET_SYSCALL_INFO, | ||
156 | pid, size, | ||
157 | (unsigned long) &info))) { | ||
158 | LOG_KILL_TRACEE("PTRACE_GET_SYSCALL_INFO: %m"); | ||
159 | } | ||
160 | ASSERT_EQ(expected_none_size, rc) { | ||
161 | LOG_KILL_TRACEE("signal stop mismatch"); | ||
162 | } | ||
163 | ASSERT_EQ(PTRACE_SYSCALL_INFO_NONE, info.op) { | ||
164 | LOG_KILL_TRACEE("signal stop mismatch"); | ||
165 | } | ||
166 | ASSERT_TRUE(info.arch) { | ||
167 | LOG_KILL_TRACEE("signal stop mismatch"); | ||
168 | } | ||
169 | ASSERT_TRUE(info.instruction_pointer) { | ||
170 | LOG_KILL_TRACEE("signal stop mismatch"); | ||
171 | } | ||
172 | ASSERT_TRUE(info.stack_pointer) { | ||
173 | LOG_KILL_TRACEE("signal stop mismatch"); | ||
174 | } | ||
175 | break; | ||
176 | |||
177 | case SIGTRAP | 0x80: | ||
178 | ASSERT_LT(0, (rc = sys_ptrace(PTRACE_GET_SYSCALL_INFO, | ||
179 | pid, size, | ||
180 | (unsigned long) &info))) { | ||
181 | LOG_KILL_TRACEE("PTRACE_GET_SYSCALL_INFO: %m"); | ||
182 | } | ||
183 | switch (ptrace_stop) { | ||
184 | case 1: /* entering chdir */ | ||
185 | case 3: /* entering gettid */ | ||
186 | case 5: /* entering exit_group */ | ||
187 | exp_args = args[ptrace_stop / 2]; | ||
188 | ASSERT_EQ(expected_entry_size, rc) { | ||
189 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
190 | } | ||
191 | ASSERT_EQ(PTRACE_SYSCALL_INFO_ENTRY, info.op) { | ||
192 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
193 | } | ||
194 | ASSERT_TRUE(info.arch) { | ||
195 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
196 | } | ||
197 | ASSERT_TRUE(info.instruction_pointer) { | ||
198 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
199 | } | ||
200 | ASSERT_TRUE(info.stack_pointer) { | ||
201 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
202 | } | ||
203 | ASSERT_EQ(exp_args[0], info.entry.nr) { | ||
204 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
205 | } | ||
206 | ASSERT_EQ(exp_args[1], info.entry.args[0]) { | ||
207 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
208 | } | ||
209 | ASSERT_EQ(exp_args[2], info.entry.args[1]) { | ||
210 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
211 | } | ||
212 | ASSERT_EQ(exp_args[3], info.entry.args[2]) { | ||
213 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
214 | } | ||
215 | ASSERT_EQ(exp_args[4], info.entry.args[3]) { | ||
216 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
217 | } | ||
218 | ASSERT_EQ(exp_args[5], info.entry.args[4]) { | ||
219 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
220 | } | ||
221 | ASSERT_EQ(exp_args[6], info.entry.args[5]) { | ||
222 | LOG_KILL_TRACEE("entry stop mismatch"); | ||
223 | } | ||
224 | break; | ||
225 | case 2: /* exiting chdir */ | ||
226 | case 4: /* exiting gettid */ | ||
227 | exp_param = &exit_param[ptrace_stop / 2 - 1]; | ||
228 | ASSERT_EQ(expected_exit_size, rc) { | ||
229 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
230 | } | ||
231 | ASSERT_EQ(PTRACE_SYSCALL_INFO_EXIT, info.op) { | ||
232 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
233 | } | ||
234 | ASSERT_TRUE(info.arch) { | ||
235 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
236 | } | ||
237 | ASSERT_TRUE(info.instruction_pointer) { | ||
238 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
239 | } | ||
240 | ASSERT_TRUE(info.stack_pointer) { | ||
241 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
242 | } | ||
243 | ASSERT_EQ(exp_param->is_error, | ||
244 | info.exit.is_error) { | ||
245 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
246 | } | ||
247 | ASSERT_EQ(exp_param->rval, info.exit.rval) { | ||
248 | LOG_KILL_TRACEE("exit stop mismatch"); | ||
249 | } | ||
250 | break; | ||
251 | default: | ||
252 | LOG_KILL_TRACEE("unexpected syscall stop"); | ||
253 | abort(); | ||
254 | } | ||
255 | break; | ||
256 | |||
257 | default: | ||
258 | LOG_KILL_TRACEE("unexpected stop signal %#x", | ||
259 | WSTOPSIG(status)); | ||
260 | abort(); | ||
261 | } | ||
262 | |||
263 | ASSERT_EQ(0, sys_ptrace(PTRACE_SYSCALL, pid, 0, 0)) { | ||
264 | LOG_KILL_TRACEE("PTRACE_SYSCALL: %m"); | ||
265 | } | ||
266 | } | ||
267 | |||
268 | ASSERT_EQ(ARRAY_SIZE(args) * 2, ptrace_stop); | ||
269 | } | ||
270 | |||
271 | TEST_HARNESS_MAIN | ||
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index dc66fe852768..6ef7f16c4cf5 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c | |||
@@ -1775,13 +1775,18 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee, | |||
1775 | unsigned long msg; | 1775 | unsigned long msg; |
1776 | static bool entry; | 1776 | static bool entry; |
1777 | 1777 | ||
1778 | /* Make sure we got an empty message. */ | 1778 | /* |
1779 | * The traditional way to tell PTRACE_SYSCALL entry/exit | ||
1780 | * is by counting. | ||
1781 | */ | ||
1782 | entry = !entry; | ||
1783 | |||
1784 | /* Make sure we got an appropriate message. */ | ||
1779 | ret = ptrace(PTRACE_GETEVENTMSG, tracee, NULL, &msg); | 1785 | ret = ptrace(PTRACE_GETEVENTMSG, tracee, NULL, &msg); |
1780 | EXPECT_EQ(0, ret); | 1786 | EXPECT_EQ(0, ret); |
1781 | EXPECT_EQ(0, msg); | 1787 | EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY |
1788 | : PTRACE_EVENTMSG_SYSCALL_EXIT, msg); | ||
1782 | 1789 | ||
1783 | /* The only way to tell PTRACE_SYSCALL entry/exit is by counting. */ | ||
1784 | entry = !entry; | ||
1785 | if (!entry) | 1790 | if (!entry) |
1786 | return; | 1791 | return; |
1787 | 1792 | ||