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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
33 #include <linux/prctl.h>
35 #include "xlat/prctl_options.h"
36 #include "xlat/pr_cap_ambient.h"
37 #include "xlat/pr_dumpable.h"
38 #include "xlat/pr_fp_mode.h"
39 #include "xlat/pr_mce_kill.h"
40 #include "xlat/pr_mce_kill_policy.h"
41 #include "xlat/pr_set_mm.h"
42 #include "xlat/pr_tsc.h"
43 #include "xlat/pr_unalign_flags.h"
46 # define TASK_COMM_LEN 16
49 #ifdef HAVE_LINUX_SECCOMP_H
50 # include <linux/seccomp.h>
52 #include "xlat/seccomp_mode.h"
54 #ifdef HAVE_LINUX_SECUREBITS_H
55 # include <linux/securebits.h>
57 #include "xlat/secbits.h"
59 /* these constants are the same as in <linux/capability.h> */
68 print_prctl_args(struct tcb *tcp, const unsigned int first)
72 for (i = first; i < tcp->s_ent->nargs; ++i)
73 tprintf(", %#" PRI_klx, tcp->u_arg[i]);
78 const unsigned int option = tcp->u_arg[0];
79 const kernel_ulong_t arg2 = tcp->u_arg[1];
80 const kernel_ulong_t arg3 = tcp->u_arg[2];
82 * PR_SET_VMA is the only command which actually uses these arguments
83 * currently, and it is available only on Android for now.
86 const kernel_ulong_t arg4 = tcp->u_arg[3];
87 const kernel_ulong_t arg5 = tcp->u_arg[4];
92 printxval(prctl_options, option, "PR_???");
97 case PR_GET_TIMERSLACK:
101 case PR_GET_CHILD_SUBREAPER:
108 printnum_int(tcp, arg2, "%u");
111 case PR_GET_DUMPABLE:
116 tcp->auxstr = xlookup(pr_dumpable, (kernel_ulong_t) tcp->u_rval);
126 printstr_ex(tcp, arg2, TASK_COMM_LEN,
131 case PR_GET_PDEATHSIG:
134 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
141 case PR_GET_SECUREBITS:
144 if (syserror(tcp) || tcp->u_rval == 0)
146 tcp->auxstr = sprintflags("", secbits,
147 (kernel_ulong_t) tcp->u_rval);
150 case PR_GET_TID_ADDRESS:
154 printnum_kptr(tcp, arg2);
160 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
162 printxval(pr_tsc, i, "PR_TSC_???");
170 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
172 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
180 if (syserror(tcp) || tcp->u_rval == 0)
182 tcp->auxstr = sprintflags("", pr_fp_mode,
183 (kernel_ulong_t) tcp->u_rval);
186 /* PR_TASK_PERF_EVENTS_* take no arguments. */
187 case PR_TASK_PERF_EVENTS_DISABLE:
188 case PR_TASK_PERF_EVENTS_ENABLE:
191 case PR_SET_CHILD_SUBREAPER:
195 case PR_SET_KEEPCAPS:
197 tprintf(", %" PRI_klu, arg2);
200 case PR_SET_DUMPABLE:
202 printxval64(pr_dumpable, arg2, "SUID_DUMP_???");
205 case PR_CAPBSET_DROP:
206 case PR_CAPBSET_READ:
208 printxval64(cap, arg2, "CAP_???");
213 printxval64(pr_cap_ambient, arg2,
214 "PR_CAP_AMBIENT_???");
216 case PR_CAP_AMBIENT_RAISE:
217 case PR_CAP_AMBIENT_LOWER:
218 case PR_CAP_AMBIENT_IS_SET:
220 printxval64(cap, arg3, "CAP_???");
221 print_prctl_args(tcp, 3);
224 print_prctl_args(tcp, 2);
231 printxval64(pr_mce_kill, arg2, "PR_MCE_KILL_???");
233 if (PR_MCE_KILL_SET == arg2)
234 printxval64(pr_mce_kill_policy, arg3,
237 tprintf("%#" PRI_klx, arg3);
238 print_prctl_args(tcp, 3);
243 printstr_ex(tcp, arg2, TASK_COMM_LEN - 1,
248 # ifndef PR_SET_VMA_ANON_NAME
249 # define PR_SET_VMA_ANON_NAME 0
252 if (arg2 == PR_SET_VMA_ANON_NAME) {
253 tprintf(", PR_SET_VMA_ANON_NAME, %#" PRI_klx, arg3);
254 tprintf(", %" PRI_klu ", ", arg4);
257 /* There are no other sub-options now, but there
258 * might be in future... */
259 print_prctl_args(tcp, 1);
266 printxval(pr_set_mm, arg2, "PR_SET_MM_???");
267 print_prctl_args(tcp, 2);
270 case PR_SET_PDEATHSIG:
273 tprintf("%" PRI_klu, arg2);
275 tprints(signame(arg2));
280 if ((int) arg2 == -1)
281 tprints("PR_SET_PTRACER_ANY");
283 tprintf("%" PRI_klu, arg2);
288 printxval64(seccomp_mode, arg2,
290 if (SECCOMP_MODE_STRICT == arg2)
292 if (SECCOMP_MODE_FILTER == arg2) {
294 print_seccomp_filter(tcp, arg3);
297 print_prctl_args(tcp, 2);
300 case PR_SET_SECUREBITS:
302 printflags64(secbits, arg2, "SECBIT_???");
305 case PR_SET_TIMERSLACK:
306 tprintf(", %" PRI_kld, arg2);
311 printxval(pr_tsc, arg2, "PR_TSC_???");
316 printflags(pr_unalign_flags, arg2, "PR_UNALIGN_???");
319 case PR_SET_NO_NEW_PRIVS:
320 case PR_SET_THP_DISABLE:
321 tprintf(", %" PRI_klu, arg2);
322 print_prctl_args(tcp, 2);
325 case PR_MCE_KILL_GET:
327 print_prctl_args(tcp, 1);
332 tcp->auxstr = xlookup(pr_mce_kill_policy,
333 (kernel_ulong_t) tcp->u_rval);
334 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
338 printflags(pr_fp_mode, arg2, "PR_FP_MODE_???");
341 case PR_GET_NO_NEW_PRIVS:
342 case PR_GET_THP_DISABLE:
343 case PR_MPX_DISABLE_MANAGEMENT:
344 case PR_MPX_ENABLE_MANAGEMENT:
346 print_prctl_args(tcp, 1);
352 #if defined X86_64 || defined X32
353 # include <asm/prctl.h>
354 # include "xlat/archvals.h"
358 const unsigned int option = tcp->u_arg[0];
359 const kernel_ulong_t addr = tcp->u_arg[1];
362 printxval(archvals, option, "ARCH_???");
370 printnum_ptr(tcp, addr);
374 tprintf(", %#" PRI_klx, addr);
377 #endif /* X86_64 || X32 */