]> granicus.if.org Git - strace/blob - tests/prctl-securebits.c
Remove XLAT_END
[strace] / tests / prctl-securebits.c
1 /*
2  * Check decoding of prctl PR_GET_SECUREBITS/PR_SET_SECUREBITS operations.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
6  * Copyright (c) 2016-2019 The strace developers.
7  * All rights reserved.
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "tests.h"
13 #include "scno.h"
14 #include <linux/prctl.h>
15
16 #if defined __NR_prctl && defined PR_GET_SECUREBITS && defined PR_SET_SECUREBITS
17
18 # include <stdio.h>
19 # include <unistd.h>
20
21 # include "xlat.h"
22 # include "xlat/secbits.h"
23
24 static const char *errstr;
25
26 static long
27 prctl(kernel_ulong_t arg1, kernel_ulong_t arg2)
28 {
29         static const kernel_ulong_t bogus_arg =
30                 (kernel_ulong_t) 0xdeadbeefbadc0dedULL;
31         long rc = syscall(__NR_prctl, arg1, arg2, bogus_arg);
32         errstr = sprintrc(rc);
33         return rc;
34 }
35
36 int
37 main(void)
38 {
39         static const kernel_ulong_t bits1 =
40                 (kernel_ulong_t) 0xdeadc0defacebeefULL;
41         static const kernel_ulong_t bits2 =
42                 (kernel_ulong_t) 0xbadc0ded00000000ULL;
43         static const kernel_ulong_t bits3 =
44                 (kernel_ulong_t) 0xffULL;
45
46         prctl(PR_SET_SECUREBITS, 0);
47         printf("prctl(PR_SET_SECUREBITS, 0) = %s\n", errstr);
48
49         prctl(PR_SET_SECUREBITS, bits1);
50         printf("prctl(PR_SET_SECUREBITS, SECBIT_NOROOT|SECBIT_NOROOT_LOCKED|"
51                "SECBIT_NO_SETUID_FIXUP|SECBIT_NO_SETUID_FIXUP_LOCKED|"
52                "SECBIT_KEEP_CAPS_LOCKED|SECBIT_NO_CAP_AMBIENT_RAISE|"
53                "SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED|%#llx) = %s\n",
54                (unsigned long long) bits1 & ~0xffULL, errstr);
55
56         if (bits2) {
57                 prctl(PR_SET_SECUREBITS, bits2);
58                 printf("prctl(PR_SET_SECUREBITS, %#llx /* SECBIT_??? */)"
59                        " = %s\n", (unsigned long long) bits2, errstr);
60         }
61
62         prctl(PR_SET_SECUREBITS, bits3);
63         printf("prctl(PR_SET_SECUREBITS, SECBIT_NOROOT|SECBIT_NOROOT_LOCKED|"
64                "SECBIT_NO_SETUID_FIXUP|SECBIT_NO_SETUID_FIXUP_LOCKED|"
65                "SECBIT_KEEP_CAPS|SECBIT_KEEP_CAPS_LOCKED|"
66                "SECBIT_NO_CAP_AMBIENT_RAISE|SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED)"
67                " = %s\n", errstr);
68
69         long rc = prctl(PR_GET_SECUREBITS, bits1);
70         printf("prctl(PR_GET_SECUREBITS) = %s", errstr);
71         if (rc > 0) {
72                 printf(" (");
73                 printflags(secbits, rc, NULL);
74                 printf(")");
75         }
76
77         puts("");
78
79         puts("+++ exited with 0 +++");
80         return 0;
81 }
82
83 #else
84
85 SKIP_MAIN_UNDEFINED("__NR_prctl && PR_GET_SECUREBITS && PR_SET_SECUREBITS")
86
87 #endif