blob: e74809d0d28cc7b6c183a8155f39b5460276e09f [file] [log] [blame]
Dmitry V. Levin53c993d2014-12-11 19:25:02 +00001#include "defs.h"
2
Dmitry V. Levin53c993d2014-12-11 19:25:02 +00003#include <sys/prctl.h>
4
5#include "xlat/prctl_options.h"
Dmitry V. Levin1e880732015-02-14 01:51:03 +00006#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"
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000011
Dmitry V. Levin1e880732015-02-14 01:51:03 +000012#ifndef TASK_COMM_LEN
13# define TASK_COMM_LEN 16
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000014#endif
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000015
Dmitry V. Levin2af69032015-02-04 23:50:50 +000016#ifdef HAVE_LINUX_SECCOMP_H
17# include <linux/seccomp.h>
18#endif
Dmitry V. Levin2af69032015-02-04 23:50:50 +000019#include "xlat/seccomp_mode.h"
20
Dmitry V. Levin1e880732015-02-14 01:51:03 +000021#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> */
27enum {
28#include "caps0.h"
29#include "caps1.h"
30};
31
32#include "xlat/cap.h"
33
34static int
35prctl_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
175static int
176prctl_exit(struct tcb *tcp)
177{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000178 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(", ");
Dmitry V. Levin850ba4b2015-07-13 20:44:01 +0000196 printnum_int(tcp, tcp->u_arg[1], "%u");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000197 break;
198
199 case PR_GET_NAME:
200 tprints(", ");
Dmitry V. Levin7c53e982015-07-17 21:14:16 +0000201 if (syserror(tcp))
202 printaddr(tcp->u_arg[1]);
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000203 else
204 printstr(tcp, tcp->u_arg[1], -1);
205 break;
206
207 case PR_GET_PDEATHSIG:
208 tprints(", ");
Dmitry V. Levin7c53e982015-07-17 21:14:16 +0000209 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000210 tprints("[");
211 tprints(signame(i));
212 tprints("]");
213 }
214 break;
215
216 case PR_GET_SECUREBITS:
217 if (syserror(tcp) || tcp->u_rval == 0)
218 return 0;
219 tcp->auxstr = sprintflags("", secbits, tcp->u_rval);
220 return RVAL_STR;
221
222 case PR_GET_TID_ADDRESS:
223 tprints(", ");
Dmitry V. Levin850ba4b2015-07-13 20:44:01 +0000224 printnum_long(tcp, tcp->u_arg[1], "%#lx");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000225 break;
226
227 case PR_GET_TSC:
228 tprints(", ");
Dmitry V. Levin7c53e982015-07-17 21:14:16 +0000229 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000230 tprints("[");
231 printxval(pr_tsc, i, "PR_TSC_???");
232 tprints("]");
233 }
234 break;
235
236 case PR_GET_UNALIGN:
237 tprints(", ");
Dmitry V. Levin7c53e982015-07-17 21:14:16 +0000238 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000239 tprints("[");
240 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
241 tprints("]");
242 }
243 break;
244
245 case PR_MCE_KILL_GET:
246 if (syserror(tcp))
247 return 0;
248 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
249 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
250
251 default:
252 break;
253 }
254 return 0;
255}
256
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000257SYS_FUNC(prctl)
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000258{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000259 return entering(tcp) ? prctl_enter(tcp) : prctl_exit(tcp);
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000260}
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000261
262#if defined X86_64 || defined X32
263# include <asm/prctl.h>
264# include "xlat/archvals.h"
265
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000266SYS_FUNC(arch_prctl)
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000267{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000268 if (entering(tcp))
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000269 printxval(archvals, tcp->u_arg[0], "ARCH_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000270
271 switch (tcp->u_arg[0]) {
272 case ARCH_GET_GS:
273 case ARCH_GET_FS:
274 if (exiting(tcp)) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000275 tprints(", ");
276 printnum_long(tcp, tcp->u_arg[1], "%#lx");
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000277 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000278 return 0;
279 default:
280 if (exiting(tcp))
281 return 0;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000282 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000283
284 tprintf(", %#lx", tcp->u_arg[1]);
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000285 return 0;
286}
287#endif /* X86_64 || X32 */