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 * Copyright (c) 2014-2018 The strace developers.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <linux/prctl.h>
38 #include "xlat/prctl_options.h"
39 #include "xlat/pr_cap_ambient.h"
40 #include "xlat/pr_dumpable.h"
41 #include "xlat/pr_fp_mode.h"
42 #include "xlat/pr_mce_kill.h"
43 #include "xlat/pr_mce_kill_policy.h"
44 #include "xlat/pr_set_mm.h"
45 #include "xlat/pr_spec_cmds.h"
46 #include "xlat/pr_spec_get_store_bypass_flags.h"
47 #include "xlat/pr_spec_set_store_bypass_flags.h"
48 #include "xlat/pr_sve_vl_flags.h"
49 #include "xlat/pr_tsc.h"
50 #include "xlat/pr_unalign_flags.h"
53 # define TASK_COMM_LEN 16
56 #ifdef HAVE_LINUX_SECCOMP_H
57 # include <linux/seccomp.h>
59 #include "xlat/seccomp_mode.h"
61 #ifdef HAVE_LINUX_SECUREBITS_H
62 # include <linux/securebits.h>
64 #include "xlat/secbits.h"
66 /* these constants are the same as in <linux/capability.h> */
74 #ifndef PR_SVE_VL_LEN_MASK
75 # define PR_SVE_VL_LEN_MASK 0xffff
80 print_prctl_args(struct tcb *tcp, const unsigned int first)
84 for (i = first; i < tcp->s_ent->nargs; ++i)
85 tprintf(", %#" PRI_klx, tcp->u_arg[i]);
89 sprint_sve_val(kernel_ulong_t arg)
91 static char out[sizeof("PR_SVE_SET_VL_ONEXEC|PR_SVE_VL_INHERIT|0x") +
92 sizeof(kernel_ulong_t) * 2];
94 kernel_ulong_t vl = arg & PR_SVE_VL_LEN_MASK;
95 kernel_ulong_t flags = arg & ~PR_SVE_VL_LEN_MASK;
96 const char *flags_str = sprintflags("", pr_sve_vl_flags, flags);
98 xsprintf(out, "%s%s%#" PRI_klx,
99 flags_str ?: "", flags_str ? "|" : "", vl);
106 const unsigned int option = tcp->u_arg[0];
107 const kernel_ulong_t arg2 = tcp->u_arg[1];
108 const kernel_ulong_t arg3 = tcp->u_arg[2];
110 * PR_SET_VMA is the only command which actually uses these arguments
111 * currently, and it is available only on Android for now.
114 const kernel_ulong_t arg4 = tcp->u_arg[3];
115 const kernel_ulong_t arg5 = tcp->u_arg[4];
120 printxval(prctl_options, option, "PR_???");
123 case PR_GET_KEEPCAPS:
125 case PR_GET_TIMERSLACK:
129 case PR_GET_CHILD_SUBREAPER:
136 printnum_int(tcp, arg2, "%u");
139 case PR_GET_DUMPABLE:
144 tcp->auxstr = xlookup(pr_dumpable, (kernel_ulong_t) tcp->u_rval);
154 printstr_ex(tcp, arg2, TASK_COMM_LEN,
159 case PR_GET_PDEATHSIG:
162 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
169 case PR_GET_SECUREBITS:
172 if (syserror(tcp) || tcp->u_rval == 0)
174 tcp->auxstr = sprintflags("", secbits,
175 (kernel_ulong_t) tcp->u_rval);
178 case PR_GET_TID_ADDRESS:
182 printnum_kptr(tcp, arg2);
188 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
190 printxval(pr_tsc, i, "PR_TSC_???");
198 } else if (!umove_or_printaddr(tcp, arg2, &i)) {
200 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
208 if (syserror(tcp) || tcp->u_rval == 0)
210 tcp->auxstr = sprintflags("", pr_fp_mode,
211 (kernel_ulong_t) tcp->u_rval);
216 tprintf(", %s", sprint_sve_val(arg2));
219 ATTRIBUTE_FALLTHROUGH;
224 if (syserror(tcp) || tcp->u_rval == 0)
227 tcp->auxstr = sprint_sve_val(tcp->u_rval);
231 case PR_GET_SPECULATION_CTRL:
234 printxval64(pr_spec_cmds, arg2, "PR_SPEC_???");
243 case PR_SPEC_STORE_BYPASS:
244 tcp->auxstr = sprintflags("",
245 pr_spec_get_store_bypass_flags,
246 (kernel_ulong_t) tcp->u_rval);
252 /* PR_TASK_PERF_EVENTS_* take no arguments. */
253 case PR_TASK_PERF_EVENTS_DISABLE:
254 case PR_TASK_PERF_EVENTS_ENABLE:
257 case PR_SET_CHILD_SUBREAPER:
261 case PR_SET_KEEPCAPS:
263 tprintf(", %" PRI_klu, arg2);
266 case PR_SET_DUMPABLE:
268 printxval64(pr_dumpable, arg2, "SUID_DUMP_???");
271 case PR_CAPBSET_DROP:
272 case PR_CAPBSET_READ:
274 printxval64(cap, arg2, "CAP_???");
279 printxval64(pr_cap_ambient, arg2,
280 "PR_CAP_AMBIENT_???");
282 case PR_CAP_AMBIENT_RAISE:
283 case PR_CAP_AMBIENT_LOWER:
284 case PR_CAP_AMBIENT_IS_SET:
286 printxval64(cap, arg3, "CAP_???");
287 print_prctl_args(tcp, 3);
290 print_prctl_args(tcp, 2);
297 printxval64(pr_mce_kill, arg2, "PR_MCE_KILL_???");
299 if (PR_MCE_KILL_SET == arg2)
300 printxval64(pr_mce_kill_policy, arg3,
303 tprintf("%#" PRI_klx, arg3);
304 print_prctl_args(tcp, 3);
309 printstr_ex(tcp, arg2, TASK_COMM_LEN - 1,
314 # ifndef PR_SET_VMA_ANON_NAME
315 # define PR_SET_VMA_ANON_NAME 0
318 if (arg2 == PR_SET_VMA_ANON_NAME) {
319 tprintf(", PR_SET_VMA_ANON_NAME, %#" PRI_klx, arg3);
320 tprintf(", %" PRI_klu ", ", arg4);
323 /* There are no other sub-options now, but there
324 * might be in future... */
325 print_prctl_args(tcp, 1);
332 printxval(pr_set_mm, arg2, "PR_SET_MM_???");
333 print_prctl_args(tcp, 2);
336 case PR_SET_PDEATHSIG:
339 tprintf("%" PRI_klu, arg2);
341 tprints(signame(arg2));
346 if ((int) arg2 == -1) {
347 print_xlat_ex(arg2, "PR_SET_PTRACER_ANY",
350 tprintf("%" PRI_klu, arg2);
356 printxval64(seccomp_mode, arg2,
358 if (SECCOMP_MODE_STRICT == arg2)
360 if (SECCOMP_MODE_FILTER == arg2) {
362 decode_seccomp_fprog(tcp, arg3);
365 print_prctl_args(tcp, 2);
368 case PR_SET_SECUREBITS:
370 printflags64(secbits, arg2, "SECBIT_???");
373 case PR_SET_TIMERSLACK:
374 tprintf(", %" PRI_kld, arg2);
379 printxval(pr_tsc, arg2, "PR_TSC_???");
384 printflags(pr_unalign_flags, arg2, "PR_UNALIGN_???");
387 case PR_SET_NO_NEW_PRIVS:
388 case PR_SET_THP_DISABLE:
389 tprintf(", %" PRI_klu, arg2);
390 print_prctl_args(tcp, 2);
393 case PR_MCE_KILL_GET:
395 print_prctl_args(tcp, 1);
400 tcp->auxstr = xlookup(pr_mce_kill_policy,
401 (kernel_ulong_t) tcp->u_rval);
406 printflags(pr_fp_mode, arg2, "PR_FP_MODE_???");
409 case PR_SET_SPECULATION_CTRL:
411 printxval64(pr_spec_cmds, arg2, "PR_SPEC_???");
415 case PR_SPEC_STORE_BYPASS:
416 printxval64(pr_spec_set_store_bypass_flags, arg3,
421 tprintf("%#" PRI_klx, arg3);
426 case PR_GET_NO_NEW_PRIVS:
427 case PR_GET_THP_DISABLE:
428 case PR_MPX_DISABLE_MANAGEMENT:
429 case PR_MPX_ENABLE_MANAGEMENT:
431 print_prctl_args(tcp, 1);
437 #if defined X86_64 || defined X32 || defined I386
438 # include "xlat/archvals.h"
442 const unsigned int option = tcp->u_arg[0];
443 const kernel_ulong_t addr = tcp->u_arg[1];
446 printxval(archvals, option, "ARCH_???");
454 printnum_ptr(tcp, addr);
458 tprintf(", %#" PRI_klx, addr);
461 #endif /* X86_64 || X32 || I386 */