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 <sys/prctl.h>
35 #include "xlat/prctl_options.h"
36 #include "xlat/pr_cap_ambient.h"
37 #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"
41 #include "xlat/pr_unalign_flags.h"
44 # define TASK_COMM_LEN 16
47 #ifdef HAVE_LINUX_SECCOMP_H
48 # include <linux/seccomp.h>
50 #include "xlat/seccomp_mode.h"
52 #ifdef HAVE_LINUX_SECUREBITS_H
53 # include <linux/securebits.h>
55 #include "xlat/secbits.h"
57 /* these constants are the same as in <linux/capability.h> */
66 print_prctl_args(struct tcb *tcp, const unsigned int first)
70 for (i = first; i < tcp->s_ent->nargs; ++i)
71 tprintf(", %#lx", tcp->u_arg[i]);
76 const unsigned int option = tcp->u_arg[0];
80 printxval(prctl_options, option, "PR_???");
86 case PR_GET_TIMERSLACK:
90 case PR_GET_CHILD_SUBREAPER:
97 printnum_int(tcp, tcp->u_arg[1], "%u");
105 printaddr(tcp->u_arg[1]);
107 printstr(tcp, tcp->u_arg[1], -1);
111 case PR_GET_PDEATHSIG:
114 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
121 case PR_GET_SECUREBITS:
124 if (syserror(tcp) || tcp->u_rval == 0)
126 tcp->auxstr = sprintflags("", secbits,
127 (unsigned long) tcp->u_rval);
130 case PR_GET_TID_ADDRESS:
134 printnum_ptr(tcp, tcp->u_arg[1]);
140 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
142 printxval(pr_tsc, i, "PR_TSC_???");
150 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
152 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
157 /* PR_TASK_PERF_EVENTS_* take no arguments. */
158 case PR_TASK_PERF_EVENTS_DISABLE:
159 case PR_TASK_PERF_EVENTS_ENABLE:
162 case PR_SET_CHILD_SUBREAPER:
163 case PR_SET_DUMPABLE:
167 case PR_SET_KEEPCAPS:
169 tprintf(", %lu", tcp->u_arg[1]);
172 case PR_CAPBSET_DROP:
173 case PR_CAPBSET_READ:
175 printxval_long(cap, tcp->u_arg[1], "CAP_???");
180 printxval_long(pr_cap_ambient, tcp->u_arg[1],
181 "PR_CAP_AMBIENT_???");
182 switch (tcp->u_arg[1]) {
183 case PR_CAP_AMBIENT_RAISE:
184 case PR_CAP_AMBIENT_LOWER:
185 case PR_CAP_AMBIENT_IS_SET:
187 printxval_long(cap, tcp->u_arg[2], "CAP_???");
188 print_prctl_args(tcp, 3);
191 print_prctl_args(tcp, 2);
198 printxval_long(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???");
200 if (PR_MCE_KILL_SET == tcp->u_arg[1])
201 printxval_long(pr_mce_kill_policy, tcp->u_arg[2],
204 tprintf("%#lx", tcp->u_arg[2]);
205 print_prctl_args(tcp, 3);
210 printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
214 # ifndef PR_SET_VMA_ANON_NAME
215 # define PR_SET_VMA_ANON_NAME 0
218 if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
219 tprintf(", PR_SET_VMA_ANON_NAME, %#lx", tcp->u_arg[2]);
220 tprintf(", %lu, ", tcp->u_arg[3]);
221 printstr(tcp, tcp->u_arg[4], -1);
223 /* There are no other sub-options now, but there
224 * might be in future... */
225 print_prctl_args(tcp, 1);
232 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
233 print_prctl_args(tcp, 2);
236 case PR_SET_PDEATHSIG:
238 if ((unsigned long) tcp->u_arg[1] > 128)
239 tprintf("%lu", tcp->u_arg[1]);
241 tprints(signame(tcp->u_arg[1]));
246 if (tcp->u_arg[1] == -1)
247 tprints("PR_SET_PTRACER_ANY");
249 tprintf("%lu", tcp->u_arg[1]);
254 printxval_long(seccomp_mode, tcp->u_arg[1],
256 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
258 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
260 print_seccomp_filter(tcp, tcp->u_arg[2]);
263 print_prctl_args(tcp, 2);
266 case PR_SET_SECUREBITS:
268 printflags_long(secbits, tcp->u_arg[1], "SECBIT_???");
271 case PR_SET_TIMERSLACK:
272 tprintf(", %ld", tcp->u_arg[1]);
277 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
282 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
285 case PR_SET_NO_NEW_PRIVS:
286 case PR_SET_THP_DISABLE:
287 tprintf(", %lu", tcp->u_arg[1]);
288 print_prctl_args(tcp, 2);
291 case PR_MCE_KILL_GET:
293 print_prctl_args(tcp, 1);
298 tcp->auxstr = xlookup(pr_mce_kill_policy,
299 (unsigned long) tcp->u_rval);
300 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
302 case PR_GET_NO_NEW_PRIVS:
303 case PR_GET_THP_DISABLE:
304 case PR_MPX_DISABLE_MANAGEMENT:
305 case PR_MPX_ENABLE_MANAGEMENT:
307 print_prctl_args(tcp, 1);
313 #if defined X86_64 || defined X32
314 # include <asm/prctl.h>
315 # include "xlat/archvals.h"
319 const unsigned int option = tcp->u_arg[0];
322 printxval(archvals, option, "ARCH_???");
330 printnum_ptr(tcp, tcp->u_arg[1]);
334 tprintf(", %#lx", tcp->u_arg[1]);
337 #endif /* X86_64 || X32 */