]> granicus.if.org Git - strace/blob - tests/prctl-seccomp-strict.c
Update copyright headers
[strace] / tests / prctl-seccomp-strict.c
1 /*
2  * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7
8 #include "tests.h"
9 #include <asm/unistd.h>
10 #ifdef HAVE_PRCTL
11 # include <sys/prctl.h>
12 #endif
13
14 #if defined HAVE_PRCTL && defined PR_SET_SECCOMP && defined __NR_exit
15
16 # include <stdio.h>
17 # include <unistd.h>
18
19 int
20 main(void)
21 {
22         static const char text1[] =
23                 "prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) = 0\n";
24         static const char text2[] = "+++ exited with 0 +++\n";
25
26         int rc = prctl(PR_SET_SECCOMP, -1L, 1, 2, 3);
27         printf("prctl(PR_SET_SECCOMP, %#lx /* SECCOMP_MODE_??? */, 0x1, 0x2, 0x3)"
28                " = %d %s (%m)\n", -1L, rc, errno2name());
29         fflush(stdout);
30
31         rc = prctl(PR_SET_SECCOMP, 1);
32         if (rc) {
33                 printf("prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT)"
34                        " = %d %s (%m)\n", rc, errno2name());
35                 fflush(stdout);
36                 rc = 0;
37         } else {
38                 /*
39                  * If kernel implementaton of SECCOMP_MODE_STRICT is buggy,
40                  * the following syscall will result to SIGKILL.
41                  */
42                 rc = write(1, text1, LENGTH_OF(text1)) != LENGTH_OF(text1);
43         }
44
45         rc += write(1, text2, LENGTH_OF(text2)) != LENGTH_OF(text2);
46         return !!syscall(__NR_exit, rc);
47 }
48
49 #else
50
51 SKIP_MAIN_UNDEFINED("HAVE_PRCTL && PR_SET_SECCOMP && __NR_exit")
52
53 #endif