]> granicus.if.org Git - strace/blob - prctl.c
swapon.c: make use of RVAL_DECODED
[strace] / prctl.c
1 #include "defs.h"
2
3 #include <sys/prctl.h>
4
5 #include "xlat/prctl_options.h"
6 #include "xlat/pr_unalign_flags.h"
7 #include "xlat/pr_mce_kill.h"
8 #include "xlat/pr_mce_kill_policy.h"
9 #include "xlat/pr_set_mm.h"
10 #include "xlat/pr_tsc.h"
11
12 #ifndef TASK_COMM_LEN
13 # define TASK_COMM_LEN 16
14 #endif
15
16 #ifdef HAVE_LINUX_SECCOMP_H
17 # include <linux/seccomp.h>
18 #endif
19 #include "xlat/seccomp_mode.h"
20
21 #ifdef HAVE_LINUX_SECUREBITS_H
22 # include <linux/securebits.h>
23 #endif
24 #include "xlat/secbits.h"
25
26 /* these constants are the same as in <linux/capability.h> */
27 enum {
28 #include "caps0.h"
29 #include "caps1.h"
30 };
31
32 #include "xlat/cap.h"
33
34 static int
35 prctl_enter(struct tcb *tcp)
36 {
37         unsigned int i;
38
39         printxval(prctl_options, tcp->u_arg[0], "PR_???");
40
41         switch (tcp->u_arg[0]) {
42         /* PR_GET_* are decoded on exit. */
43         case PR_GET_CHILD_SUBREAPER:
44         case PR_GET_DUMPABLE:
45         case PR_GET_ENDIAN:
46         case PR_GET_FPEMU:
47         case PR_GET_FPEXC:
48         case PR_GET_KEEPCAPS:
49         case PR_GET_NAME:
50         case PR_GET_PDEATHSIG:
51         case PR_GET_SECCOMP:
52         case PR_GET_SECUREBITS:
53         case PR_GET_TID_ADDRESS:
54         case PR_GET_TIMERSLACK:
55         case PR_GET_TIMING:
56         case PR_GET_TSC:
57         case PR_GET_UNALIGN:
58         /* PR_TASK_PERF_EVENTS_* have nothing to decode on enter. */
59         case PR_TASK_PERF_EVENTS_DISABLE:
60         case PR_TASK_PERF_EVENTS_ENABLE:
61                 break;
62
63         case PR_SET_CHILD_SUBREAPER:
64         case PR_SET_DUMPABLE:
65         case PR_SET_ENDIAN:
66         case PR_SET_FPEMU:
67         case PR_SET_FPEXC:
68         case PR_SET_KEEPCAPS:
69         case PR_SET_TIMING:
70                 tprintf(", %lu", tcp->u_arg[1]);
71                 break;
72
73         case PR_CAPBSET_DROP:
74         case PR_CAPBSET_READ:
75                 tprints(", ");
76                 printxval(cap, tcp->u_arg[1], "CAP_???");
77                 break;
78
79         case PR_MCE_KILL:
80                 tprints(", ");
81                 printxval(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???");
82                 tprints(", ");
83                 if (PR_MCE_KILL_SET == tcp->u_arg[1])
84                         printxval(pr_mce_kill_policy, tcp->u_arg[2],
85                                    "PR_MCE_KILL_???");
86                 else
87                         tprintf("%#lx", tcp->u_arg[2]);
88                 for (i = 3; i < tcp->s_ent->nargs; i++)
89                         tprintf(", %#lx", tcp->u_arg[i]);
90                 break;
91
92         case PR_SET_NAME:
93                 tprints(", ");
94                 printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
95                 break;
96
97         case PR_SET_MM:
98                 tprints(", ");
99                 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
100                 for (i = 2; i < tcp->s_ent->nargs; i++)
101                         tprintf(", %#lx", tcp->u_arg[i]);
102                 break;
103
104         case PR_SET_PDEATHSIG:
105                 tprints(", ");
106                 if ((unsigned long) tcp->u_arg[1] > 128)
107                         tprintf("%lu", tcp->u_arg[1]);
108                 else
109                         tprints(signame(tcp->u_arg[1]));
110                 break;
111
112         case PR_SET_PTRACER:
113                 tprints(", ");
114                 if (tcp->u_arg[1] == -1)
115                         tprints("PR_SET_PTRACER_ANY");
116                 else
117                         tprintf("%lu", tcp->u_arg[1]);
118                 break;
119
120         case PR_SET_SECCOMP:
121                 tprints(", ");
122                 printxval(seccomp_mode, tcp->u_arg[1],
123                           "SECCOMP_MODE_???");
124                 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
125                         break;
126                 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
127                         tprints(", ");
128                         print_seccomp_filter(tcp, tcp->u_arg[2]);
129                         break;
130                 }
131                 for (i = 2; i < tcp->s_ent->nargs; i++)
132                         tprintf(", %#lx", tcp->u_arg[i]);
133                 break;
134
135         case PR_SET_SECUREBITS:
136                 tprints(", ");
137                 printflags(secbits, tcp->u_arg[1], "SECBIT_???");
138                 break;
139
140         case PR_SET_TIMERSLACK:
141                 tprintf(", %ld", tcp->u_arg[1]);
142                 break;
143
144         case PR_SET_TSC:
145                 tprints(", ");
146                 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
147                 break;
148
149         case PR_SET_UNALIGN:
150                 tprints(", ");
151                 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
152                 break;
153
154         case PR_SET_NO_NEW_PRIVS:
155         case PR_SET_THP_DISABLE:
156                 tprintf(", %lu", tcp->u_arg[1]);
157                 for (i = 2; i < tcp->s_ent->nargs; i++)
158                         tprintf(", %#lx", tcp->u_arg[i]);
159                 break;
160
161         case PR_GET_NO_NEW_PRIVS:
162         case PR_GET_THP_DISABLE:
163         case PR_MCE_KILL_GET:
164         /* Return code of "GET" commands will be decoded on exit */
165         case PR_MPX_DISABLE_MANAGEMENT:
166         case PR_MPX_ENABLE_MANAGEMENT:
167         default:
168                 for (i = 1; i < tcp->s_ent->nargs; i++)
169                         tprintf(", %#lx", tcp->u_arg[i]);
170                 break;
171         }
172         return 0;
173 }
174
175 static int
176 prctl_exit(struct tcb *tcp)
177 {
178         unsigned int i;
179
180         switch (tcp->u_arg[0]) {
181         case PR_CAPBSET_READ:
182         case PR_GET_DUMPABLE:
183         case PR_GET_KEEPCAPS:
184         case PR_GET_NO_NEW_PRIVS:
185         case PR_GET_SECCOMP:
186         case PR_GET_THP_DISABLE:
187         case PR_GET_TIMERSLACK:
188         case PR_GET_TIMING:
189                 return syserror(tcp) ? 0 : RVAL_UDECIMAL;
190
191         case PR_GET_CHILD_SUBREAPER:
192         case PR_GET_ENDIAN:
193         case PR_GET_FPEMU:
194         case PR_GET_FPEXC:
195                 tprints(", ");
196                 printnum_int(tcp, tcp->u_arg[1], "%u");
197                 break;
198
199         case PR_GET_NAME:
200                 tprints(", ");
201                 if (!tcp->u_arg[1])
202                         tprints("NULL");
203                 else if (syserror(tcp))
204                         tprintf("%#lx", tcp->u_arg[1]);
205                 else
206                         printstr(tcp, tcp->u_arg[1], -1);
207                 break;
208
209         case PR_GET_PDEATHSIG:
210                 tprints(", ");
211                 if (!tcp->u_arg[1])
212                         tprints("NULL");
213                 else if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
214                         tprintf("%#lx", tcp->u_arg[1]);
215                 else {
216                         tprints("[");
217                         tprints(signame(i));
218                         tprints("]");
219                 }
220                 break;
221
222         case PR_GET_SECUREBITS:
223                 if (syserror(tcp) || tcp->u_rval == 0)
224                         return 0;
225                 tcp->auxstr = sprintflags("", secbits, tcp->u_rval);
226                 return RVAL_STR;
227
228         case PR_GET_TID_ADDRESS:
229                 tprints(", ");
230                 printnum_long(tcp, tcp->u_arg[1], "%#lx");
231                 break;
232
233         case PR_GET_TSC:
234                 tprints(", ");
235                 if (!tcp->u_arg[1])
236                         tprints("NULL");
237                 else if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
238                         tprintf("%#lx", tcp->u_arg[1]);
239                 else {
240                         tprints("[");
241                         printxval(pr_tsc, i, "PR_TSC_???");
242                         tprints("]");
243                 }
244                 break;
245
246         case PR_GET_UNALIGN:
247                 tprints(", ");
248                 if (!tcp->u_arg[1])
249                         tprints("NULL");
250                 else if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
251                         tprintf("%#lx", tcp->u_arg[1]);
252                 else {
253                         tprints("[");
254                         printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
255                         tprints("]");
256                 }
257                 break;
258
259         case PR_MCE_KILL_GET:
260                 if (syserror(tcp))
261                         return 0;
262                 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
263                 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
264
265         default:
266                 break;
267         }
268         return 0;
269 }
270
271 SYS_FUNC(prctl)
272 {
273         return entering(tcp) ? prctl_enter(tcp) : prctl_exit(tcp);
274 }
275
276 #if defined X86_64 || defined X32
277 # include <asm/prctl.h>
278 # include "xlat/archvals.h"
279
280 SYS_FUNC(arch_prctl)
281 {
282         if (entering(tcp))
283                 printxval(archvals, tcp->u_arg[0], "ARCH_???");
284
285         switch (tcp->u_arg[0]) {
286         case ARCH_GET_GS:
287         case ARCH_GET_FS:
288                 if (exiting(tcp)) {
289                         tprints(", ");
290                         printnum_long(tcp, tcp->u_arg[1], "%#lx");
291                 }
292                 return 0;
293         default:
294                 if (exiting(tcp))
295                         return 0;
296         }
297
298         tprintf(", %#lx", tcp->u_arg[1]);
299         return 0;
300 }
301 #endif /* X86_64 || X32 */