blob: 53ee56e3b730611fdf6d2dcd4794035b51b8e103 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 1994-1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
4 * Copyright (c) 2005-2007 Roland McGrath <roland@redhat.com>
5 * Copyright (c) 2008-2015 Dmitry V. Levin <ldv@altlinux.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000031#include "defs.h"
32
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000033#include <sys/prctl.h>
34
35#include "xlat/prctl_options.h"
Dmitry V. Levineb76c4b2015-12-06 15:33:53 +000036#include "xlat/pr_cap_ambient.h"
Dmitry V. Levin1e880732015-02-14 01:51:03 +000037#include "xlat/pr_mce_kill.h"
38#include "xlat/pr_mce_kill_policy.h"
39#include "xlat/pr_set_mm.h"
40#include "xlat/pr_tsc.h"
Dmitry V. Levineb76c4b2015-12-06 15:33:53 +000041#include "xlat/pr_unalign_flags.h"
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000042
Dmitry V. Levin1e880732015-02-14 01:51:03 +000043#ifndef TASK_COMM_LEN
44# define TASK_COMM_LEN 16
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000045#endif
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000046
Dmitry V. Levin2af69032015-02-04 23:50:50 +000047#ifdef HAVE_LINUX_SECCOMP_H
48# include <linux/seccomp.h>
49#endif
Dmitry V. Levin2af69032015-02-04 23:50:50 +000050#include "xlat/seccomp_mode.h"
51
Dmitry V. Levin1e880732015-02-14 01:51:03 +000052#ifdef HAVE_LINUX_SECUREBITS_H
53# include <linux/securebits.h>
54#endif
55#include "xlat/secbits.h"
56
57/* these constants are the same as in <linux/capability.h> */
58enum {
59#include "caps0.h"
60#include "caps1.h"
61};
62
63#include "xlat/cap.h"
64
Dmitry V. Levin36915622015-07-25 09:43:01 +000065static void
66print_prctl_args(struct tcb *tcp, const unsigned int first)
67{
68 unsigned int i;
69
70 for (i = first; i < tcp->s_ent->nargs; ++i)
71 tprintf(", %#lx", tcp->u_arg[i]);
72}
73
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000074SYS_FUNC(prctl)
Dmitry V. Levin1e880732015-02-14 01:51:03 +000075{
76 unsigned int i;
77
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000078 if (entering(tcp))
79 printxval(prctl_options, tcp->u_arg[0], "PR_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +000080
81 switch (tcp->u_arg[0]) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +000082 case PR_GET_DUMPABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000083 case PR_GET_KEEPCAPS:
84 case PR_GET_SECCOMP:
85 case PR_GET_TIMERSLACK:
86 case PR_GET_TIMING:
Dmitry V. Levin1b283302015-12-06 15:29:04 +000087 return RVAL_DECODED;
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000088
89 case PR_GET_CHILD_SUBREAPER:
Dmitry V. Levin1e880732015-02-14 01:51:03 +000090 case PR_GET_ENDIAN:
91 case PR_GET_FPEMU:
92 case PR_GET_FPEXC:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000093 if (entering(tcp))
94 tprints(", ");
95 else
96 printnum_int(tcp, tcp->u_arg[1], "%u");
97 break;
98
Dmitry V. Levin1e880732015-02-14 01:51:03 +000099 case PR_GET_NAME:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000100 if (entering(tcp))
101 tprints(", ");
102 else {
103 if (syserror(tcp))
104 printaddr(tcp->u_arg[1]);
105 else
106 printstr(tcp, tcp->u_arg[1], -1);
107 }
108 break;
109
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000110 case PR_GET_PDEATHSIG:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000111 if (entering(tcp))
112 tprints(", ");
113 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
114 tprints("[");
115 tprints(signame(i));
116 tprints("]");
117 }
118 break;
119
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000120 case PR_GET_SECUREBITS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000121 if (entering(tcp))
122 break;
123 if (syserror(tcp) || tcp->u_rval == 0)
124 return 0;
125 tcp->auxstr = sprintflags("", secbits, tcp->u_rval);
126 return RVAL_STR;
127
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000128 case PR_GET_TID_ADDRESS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000129 if (entering(tcp))
130 tprints(", ");
131 else
Dmitry V. Levin2479ef02015-08-18 14:58:27 +0000132 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000133 break;
134
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000135 case PR_GET_TSC:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000136 if (entering(tcp))
137 tprints(", ");
138 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
139 tprints("[");
140 printxval(pr_tsc, i, "PR_TSC_???");
141 tprints("]");
142 }
143 break;
144
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000145 case PR_GET_UNALIGN:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000146 if (entering(tcp))
147 tprints(", ");
148 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
149 tprints("[");
150 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
151 tprints("]");
152 }
153 break;
154
155 /* PR_TASK_PERF_EVENTS_* take no arguments. */
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000156 case PR_TASK_PERF_EVENTS_DISABLE:
157 case PR_TASK_PERF_EVENTS_ENABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000158 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000159
160 case PR_SET_CHILD_SUBREAPER:
161 case PR_SET_DUMPABLE:
162 case PR_SET_ENDIAN:
163 case PR_SET_FPEMU:
164 case PR_SET_FPEXC:
165 case PR_SET_KEEPCAPS:
166 case PR_SET_TIMING:
167 tprintf(", %lu", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000168 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000169
170 case PR_CAPBSET_DROP:
Dmitry V. Levin1b283302015-12-06 15:29:04 +0000171 case PR_CAPBSET_READ:
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000172 tprints(", ");
173 printxval(cap, tcp->u_arg[1], "CAP_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000174 return RVAL_DECODED;
175
Dmitry V. Levineb76c4b2015-12-06 15:33:53 +0000176 case PR_CAP_AMBIENT:
177 tprints(", ");
178 printxval(pr_cap_ambient, tcp->u_arg[1], "PR_CAP_AMBIENT_???");
179 switch (tcp->u_arg[1]) {
180 case PR_CAP_AMBIENT_RAISE:
181 case PR_CAP_AMBIENT_LOWER:
182 case PR_CAP_AMBIENT_IS_SET:
183 tprints(", ");
184 printxval(cap, tcp->u_arg[2], "CAP_???");
185 print_prctl_args(tcp, 3);
186 break;
187 default:
188 print_prctl_args(tcp, 2);
189 break;
190 }
191 return RVAL_DECODED;
192
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000193 case PR_MCE_KILL:
194 tprints(", ");
195 printxval(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???");
196 tprints(", ");
197 if (PR_MCE_KILL_SET == tcp->u_arg[1])
198 printxval(pr_mce_kill_policy, tcp->u_arg[2],
199 "PR_MCE_KILL_???");
200 else
201 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levin36915622015-07-25 09:43:01 +0000202 print_prctl_args(tcp, 3);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000203 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000204
205 case PR_SET_NAME:
206 tprints(", ");
207 printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000208 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000209
Elliott Hughes1d246ce2015-07-29 22:49:38 +0000210#ifdef __ANDROID__
211# ifndef PR_SET_VMA
212# define PR_SET_VMA 0x53564d41
213# endif
214# ifndef PR_SET_VMA_ANON_NAME
215# define PR_SET_VMA_ANON_NAME 0
216# endif
217 case PR_SET_VMA:
218 if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
219 tprintf(", %lu", tcp->u_arg[1]);
220 tprintf(", %#lx", tcp->u_arg[2]);
221 tprintf(", %lu, ", tcp->u_arg[3]);
222 printstr(tcp, tcp->u_arg[4], -1);
223 } else {
224 /* There are no other sub-options now, but there
225 * might be in future... */
226 print_prctl_args(tcp, 1);
227 }
228 return RVAL_DECODED;
229#endif
230
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000231 case PR_SET_MM:
232 tprints(", ");
233 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
Dmitry V. Levin36915622015-07-25 09:43:01 +0000234 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000235 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000236
237 case PR_SET_PDEATHSIG:
238 tprints(", ");
239 if ((unsigned long) tcp->u_arg[1] > 128)
240 tprintf("%lu", tcp->u_arg[1]);
241 else
242 tprints(signame(tcp->u_arg[1]));
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000243 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000244
245 case PR_SET_PTRACER:
246 tprints(", ");
247 if (tcp->u_arg[1] == -1)
248 tprints("PR_SET_PTRACER_ANY");
249 else
250 tprintf("%lu", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000251 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000252
253 case PR_SET_SECCOMP:
254 tprints(", ");
255 printxval(seccomp_mode, tcp->u_arg[1],
256 "SECCOMP_MODE_???");
257 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000258 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000259 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
260 tprints(", ");
261 print_seccomp_filter(tcp, tcp->u_arg[2]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000262 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000263 }
Dmitry V. Levin36915622015-07-25 09:43:01 +0000264 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000265 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000266
267 case PR_SET_SECUREBITS:
268 tprints(", ");
269 printflags(secbits, tcp->u_arg[1], "SECBIT_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000270 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000271
272 case PR_SET_TIMERSLACK:
273 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000274 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000275
276 case PR_SET_TSC:
277 tprints(", ");
278 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000279 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000280
281 case PR_SET_UNALIGN:
282 tprints(", ");
283 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000284 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000285
286 case PR_SET_NO_NEW_PRIVS:
287 case PR_SET_THP_DISABLE:
288 tprintf(", %lu", tcp->u_arg[1]);
Dmitry V. Levin36915622015-07-25 09:43:01 +0000289 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000290 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000291
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000292 case PR_MCE_KILL_GET:
Dmitry V. Levin36915622015-07-25 09:43:01 +0000293 if (entering(tcp)) {
294 print_prctl_args(tcp, 1);
295 return 0;
296 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000297 if (syserror(tcp))
298 return 0;
299 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
300 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
301
Dmitry V. Levin1b283302015-12-06 15:29:04 +0000302 case PR_GET_NO_NEW_PRIVS:
303 case PR_GET_THP_DISABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000304 case PR_MPX_DISABLE_MANAGEMENT:
305 case PR_MPX_ENABLE_MANAGEMENT:
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000306 default:
Dmitry V. Levin36915622015-07-25 09:43:01 +0000307 print_prctl_args(tcp, 1);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000308 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000309 }
310 return 0;
311}
312
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000313#if defined X86_64 || defined X32
314# include <asm/prctl.h>
315# include "xlat/archvals.h"
316
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000317SYS_FUNC(arch_prctl)
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000318{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000319 if (entering(tcp))
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000320 printxval(archvals, tcp->u_arg[0], "ARCH_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000321
322 switch (tcp->u_arg[0]) {
323 case ARCH_GET_GS:
324 case ARCH_GET_FS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000325 if (entering(tcp))
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000326 tprints(", ");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000327 else
Dmitry V. Levin2479ef02015-08-18 14:58:27 +0000328 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000329 return 0;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000330 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000331
332 tprintf(", %#lx", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000333 return RVAL_DECODED;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000334}
335#endif /* X86_64 || X32 */