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]);
79 printxval(prctl_options, tcp->u_arg[0], "PR_???");
81 switch (tcp->u_arg[0]) {
85 case PR_GET_TIMERSLACK:
89 case PR_GET_CHILD_SUBREAPER:
96 printnum_int(tcp, tcp->u_arg[1], "%u");
104 printaddr(tcp->u_arg[1]);
106 printstr(tcp, tcp->u_arg[1], -1);
110 case PR_GET_PDEATHSIG:
113 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
120 case PR_GET_SECUREBITS:
123 if (syserror(tcp) || tcp->u_rval == 0)
125 tcp->auxstr = sprintflags("", secbits, tcp->u_rval);
128 case PR_GET_TID_ADDRESS:
132 printnum_ptr(tcp, tcp->u_arg[1]);
138 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
140 printxval(pr_tsc, i, "PR_TSC_???");
148 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
150 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
155 /* PR_TASK_PERF_EVENTS_* take no arguments. */
156 case PR_TASK_PERF_EVENTS_DISABLE:
157 case PR_TASK_PERF_EVENTS_ENABLE:
160 case PR_SET_CHILD_SUBREAPER:
161 case PR_SET_DUMPABLE:
165 case PR_SET_KEEPCAPS:
167 tprintf(", %lu", tcp->u_arg[1]);
170 case PR_CAPBSET_DROP:
171 case PR_CAPBSET_READ:
173 printxval(cap, tcp->u_arg[1], "CAP_???");
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:
184 printxval(cap, tcp->u_arg[2], "CAP_???");
185 print_prctl_args(tcp, 3);
188 print_prctl_args(tcp, 2);
195 printxval(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???");
197 if (PR_MCE_KILL_SET == tcp->u_arg[1])
198 printxval(pr_mce_kill_policy, tcp->u_arg[2],
201 tprintf("%#lx", tcp->u_arg[2]);
202 print_prctl_args(tcp, 3);
207 printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
211 # ifndef PR_SET_VMA_ANON_NAME
212 # define PR_SET_VMA_ANON_NAME 0
215 if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
216 tprintf(", PR_SET_VMA_ANON_NAME, %#lx", tcp->u_arg[2]);
217 tprintf(", %lu, ", tcp->u_arg[3]);
218 printstr(tcp, tcp->u_arg[4], -1);
220 /* There are no other sub-options now, but there
221 * might be in future... */
222 print_prctl_args(tcp, 1);
229 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
230 print_prctl_args(tcp, 2);
233 case PR_SET_PDEATHSIG:
235 if ((unsigned long) tcp->u_arg[1] > 128)
236 tprintf("%lu", tcp->u_arg[1]);
238 tprints(signame(tcp->u_arg[1]));
243 if (tcp->u_arg[1] == -1)
244 tprints("PR_SET_PTRACER_ANY");
246 tprintf("%lu", tcp->u_arg[1]);
251 printxval(seccomp_mode, tcp->u_arg[1],
253 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
255 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
257 print_seccomp_filter(tcp, tcp->u_arg[2]);
260 print_prctl_args(tcp, 2);
263 case PR_SET_SECUREBITS:
265 printflags(secbits, tcp->u_arg[1], "SECBIT_???");
268 case PR_SET_TIMERSLACK:
269 tprintf(", %ld", tcp->u_arg[1]);
274 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
279 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
282 case PR_SET_NO_NEW_PRIVS:
283 case PR_SET_THP_DISABLE:
284 tprintf(", %lu", tcp->u_arg[1]);
285 print_prctl_args(tcp, 2);
288 case PR_MCE_KILL_GET:
290 print_prctl_args(tcp, 1);
295 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
296 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
298 case PR_GET_NO_NEW_PRIVS:
299 case PR_GET_THP_DISABLE:
300 case PR_MPX_DISABLE_MANAGEMENT:
301 case PR_MPX_ENABLE_MANAGEMENT:
303 print_prctl_args(tcp, 1);
309 #if defined X86_64 || defined X32
310 # include <asm/prctl.h>
311 # include "xlat/archvals.h"
316 printxval(archvals, tcp->u_arg[0], "ARCH_???");
318 switch (tcp->u_arg[0]) {
324 printnum_ptr(tcp, tcp->u_arg[1]);
328 tprintf(", %#lx", tcp->u_arg[1]);
331 #endif /* X86_64 || X32 */