1 /*
2 * Check decoding of prctl PR_GET_DUMPABLE/PR_SET_DUMPABLE operations.
3 *
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016 Dmitry V. Levin <ldv@strace.io>
6 * Copyright (c) 2016-2021 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 __ia64__
17
18 # include <stdio.h>
19 # include <unistd.h>
20
21 static const char *errstr;
22
23 static long
24 prctl(kernel_ulong_t arg1, kernel_ulong_t arg2)
25 {
26 static const kernel_ulong_t bogus_arg =
27 (kernel_ulong_t) 0xdeadbeefbadc0dedULL;
28 long rc = syscall(__NR_prctl, arg1, arg2, bogus_arg);
29 errstr = sprintrc(rc);
30 return rc;
31 }
32
33 int
34 main(void)
35 {
36 static const kernel_ulong_t bogus_dumpable1 =
37 (kernel_ulong_t) 0xdeadc0de00000001ULL;
38 static const kernel_ulong_t bogus_dumpable2 =
39 (kernel_ulong_t) 0xdeadc0defacebeefULL;
40
41 static const char * const args[] = {
42 "SUID_DUMP_DISABLE",
43 "SUID_DUMP_USER",
44 "SUID_DUMP_ROOT",
45 };
46
47 prctl_marker();
48
49 prctl(PR_SET_DUMPABLE, 3);
50 printf("prctl(PR_SET_DUMPABLE, 0x3 /* SUID_DUMP_??? */) = %s\n",
51 errstr);
52
53 prctl(PR_SET_DUMPABLE, bogus_dumpable1);
54 if (bogus_dumpable1 == 1) {
55 printf("prctl(PR_SET_DUMPABLE, SUID_DUMP_USER) = %s\n", errstr);
56 } else {
57 printf("prctl(PR_SET_DUMPABLE, %#llx /* SUID_DUMP_??? */)"
58 " = %s\n",
59 (unsigned long long) bogus_dumpable1, errstr);
60 }
61
62 prctl(PR_SET_DUMPABLE, bogus_dumpable2);
63 printf("prctl(PR_SET_DUMPABLE, %#llx /* SUID_DUMP_??? */) = %s\n",
64 (unsigned long long) bogus_dumpable2, errstr);
65
66 for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) {
67 prctl(PR_SET_DUMPABLE, i);
68 printf("prctl(PR_SET_DUMPABLE, %s) = %s\n", args[i], errstr);
69
70 long rc = prctl(PR_GET_DUMPABLE, bogus_dumpable2);
71 if (rc >= 0 && rc < (long) ARRAY_SIZE(args)) {
72 printf("prctl(PR_GET_DUMPABLE) = %s (%s)\n",
73 errstr, args[rc]);
74 } else {
75 printf("prctl(PR_GET_DUMPABLE) = %s\n", errstr);
76 }
77 }
78
79 puts("+++ exited with 0 +++");
80 return 0;
81 }
82
83 #else
84
85 SKIP_MAIN_UNDEFINED("!__ia64__")
86
87 #endif