blob: da7d265ba0a536a002a4667cff307e19465d8d2f [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__
Elliott Hughes1d246ce2015-07-29 22:49:38 +0000211# ifndef PR_SET_VMA_ANON_NAME
212# define PR_SET_VMA_ANON_NAME 0
213# endif
214 case PR_SET_VMA:
215 if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
Elliott Hughes612368b2016-04-06 14:41:36 -0700216 tprintf(", PR_SET_VMA_ANON_NAME, %#lx", tcp->u_arg[2]);
Elliott Hughes1d246ce2015-07-29 22:49:38 +0000217 tprintf(", %lu, ", tcp->u_arg[3]);
218 printstr(tcp, tcp->u_arg[4], -1);
219 } else {
220 /* There are no other sub-options now, but there
221 * might be in future... */
222 print_prctl_args(tcp, 1);
223 }
224 return RVAL_DECODED;
225#endif
226
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000227 case PR_SET_MM:
228 tprints(", ");
229 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
Dmitry V. Levin36915622015-07-25 09:43:01 +0000230 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000231 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000232
233 case PR_SET_PDEATHSIG:
234 tprints(", ");
235 if ((unsigned long) tcp->u_arg[1] > 128)
236 tprintf("%lu", tcp->u_arg[1]);
237 else
238 tprints(signame(tcp->u_arg[1]));
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000239 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000240
241 case PR_SET_PTRACER:
242 tprints(", ");
243 if (tcp->u_arg[1] == -1)
244 tprints("PR_SET_PTRACER_ANY");
245 else
246 tprintf("%lu", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000247 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000248
249 case PR_SET_SECCOMP:
250 tprints(", ");
251 printxval(seccomp_mode, tcp->u_arg[1],
252 "SECCOMP_MODE_???");
253 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000254 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000255 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
256 tprints(", ");
257 print_seccomp_filter(tcp, tcp->u_arg[2]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000258 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000259 }
Dmitry V. Levin36915622015-07-25 09:43:01 +0000260 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000261 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000262
263 case PR_SET_SECUREBITS:
264 tprints(", ");
265 printflags(secbits, tcp->u_arg[1], "SECBIT_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000266 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000267
268 case PR_SET_TIMERSLACK:
269 tprintf(", %ld", tcp->u_arg[1]);
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_TSC:
273 tprints(", ");
274 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000275 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000276
277 case PR_SET_UNALIGN:
278 tprints(", ");
279 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000280 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000281
282 case PR_SET_NO_NEW_PRIVS:
283 case PR_SET_THP_DISABLE:
284 tprintf(", %lu", tcp->u_arg[1]);
Dmitry V. Levin36915622015-07-25 09:43:01 +0000285 print_prctl_args(tcp, 2);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000286 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000287
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000288 case PR_MCE_KILL_GET:
Dmitry V. Levin36915622015-07-25 09:43:01 +0000289 if (entering(tcp)) {
290 print_prctl_args(tcp, 1);
291 return 0;
292 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000293 if (syserror(tcp))
294 return 0;
295 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
296 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
297
Dmitry V. Levin1b283302015-12-06 15:29:04 +0000298 case PR_GET_NO_NEW_PRIVS:
299 case PR_GET_THP_DISABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000300 case PR_MPX_DISABLE_MANAGEMENT:
301 case PR_MPX_ENABLE_MANAGEMENT:
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000302 default:
Dmitry V. Levin36915622015-07-25 09:43:01 +0000303 print_prctl_args(tcp, 1);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000304 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000305 }
306 return 0;
307}
308
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000309#if defined X86_64 || defined X32
310# include <asm/prctl.h>
311# include "xlat/archvals.h"
312
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000313SYS_FUNC(arch_prctl)
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000314{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000315 if (entering(tcp))
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000316 printxval(archvals, tcp->u_arg[0], "ARCH_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000317
318 switch (tcp->u_arg[0]) {
319 case ARCH_GET_GS:
320 case ARCH_GET_FS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000321 if (entering(tcp))
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000322 tprints(", ");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000323 else
Dmitry V. Levin2479ef02015-08-18 14:58:27 +0000324 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000325 return 0;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000326 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000327
328 tprintf(", %#lx", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000329 return RVAL_DECODED;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000330}
331#endif /* X86_64 || X32 */