]> granicus.if.org Git - strace/blob - tests/seccomp-strict.c
strace: terminate itself if interrupted by a signal
[strace] / tests / seccomp-strict.c
1 /*
2  * Check how seccomp SECCOMP_SET_MODE_STRICT is decoded.
3  *
4  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include <asm/unistd.h>
12
13 #if defined __NR_seccomp && defined __NR_exit
14
15 # include <stdio.h>
16 # include <unistd.h>
17
18 int
19 main(void)
20 {
21         static const char text1[] =
22                 "seccomp(SECCOMP_SET_MODE_STRICT, 0, NULL) = 0\n";
23         static const char text2[] = "+++ exited with 0 +++\n";
24         const kernel_ulong_t addr = (kernel_ulong_t) 0xfacefeeddeadbeefULL;
25         long rc;
26
27         rc = syscall(__NR_seccomp, -1L, -1L, addr);
28         printf("seccomp(%#x /* SECCOMP_SET_MODE_??? */, %u, %#llx)"
29                " = %s\n", -1, -1, (unsigned long long) addr, sprintrc(rc));
30         fflush(stdout);
31
32         rc = syscall(__NR_seccomp, 0, 0, 0);
33         if (rc) {
34                 printf("seccomp(SECCOMP_SET_MODE_STRICT, 0, NULL) = %s\n",
35                        sprintrc(rc));
36                 fflush(stdout);
37                 rc = 0;
38         } else {
39                 /*
40                  * If kernel implementaton of SECCOMP_MODE_STRICT is buggy,
41                  * the following syscall will result to SIGKILL.
42                  */
43                 rc = write(1, text1, LENGTH_OF(text1)) != LENGTH_OF(text1);
44         }
45
46         rc += write(1, text2, LENGTH_OF(text2)) != LENGTH_OF(text2);
47         return !!syscall(__NR_exit, rc);
48 }
49
50 #else
51
52 SKIP_MAIN_UNDEFINED("__NR_seccomp && __NR_exit")
53
54 #endif