blob: ae36d5bea9e5a0a7367e4e10b3749aa7235e099f [file] [log] [blame]
Dmitry V. Levin53c993d2014-12-11 19:25:02 +00001#include "defs.h"
2
Dmitry V. Levin53c993d2014-12-11 19:25:02 +00003#include <sys/prctl.h>
4
5#include "xlat/prctl_options.h"
Dmitry V. Levin1e880732015-02-14 01:51:03 +00006#include "xlat/pr_unalign_flags.h"
7#include "xlat/pr_mce_kill.h"
8#include "xlat/pr_mce_kill_policy.h"
9#include "xlat/pr_set_mm.h"
10#include "xlat/pr_tsc.h"
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000011
Dmitry V. Levin1e880732015-02-14 01:51:03 +000012#ifndef TASK_COMM_LEN
13# define TASK_COMM_LEN 16
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000014#endif
Dmitry V. Levin53c993d2014-12-11 19:25:02 +000015
Dmitry V. Levin2af69032015-02-04 23:50:50 +000016#ifdef HAVE_LINUX_SECCOMP_H
17# include <linux/seccomp.h>
18#endif
Dmitry V. Levin2af69032015-02-04 23:50:50 +000019#include "xlat/seccomp_mode.h"
20
Dmitry V. Levin1e880732015-02-14 01:51:03 +000021#ifdef HAVE_LINUX_SECUREBITS_H
22# include <linux/securebits.h>
23#endif
24#include "xlat/secbits.h"
25
26/* these constants are the same as in <linux/capability.h> */
27enum {
28#include "caps0.h"
29#include "caps1.h"
30};
31
32#include "xlat/cap.h"
33
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000034SYS_FUNC(prctl)
Dmitry V. Levin1e880732015-02-14 01:51:03 +000035{
36 unsigned int i;
37
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000038 if (entering(tcp))
39 printxval(prctl_options, tcp->u_arg[0], "PR_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +000040
41 switch (tcp->u_arg[0]) {
Dmitry V. Levin1e880732015-02-14 01:51:03 +000042 case PR_GET_DUMPABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000043 case PR_GET_KEEPCAPS:
44 case PR_GET_SECCOMP:
45 case PR_GET_TIMERSLACK:
46 case PR_GET_TIMING:
47 if (entering(tcp))
48 break;
49 return syserror(tcp) ? 0 : RVAL_UDECIMAL;
50
51 case PR_GET_CHILD_SUBREAPER:
Dmitry V. Levin1e880732015-02-14 01:51:03 +000052 case PR_GET_ENDIAN:
53 case PR_GET_FPEMU:
54 case PR_GET_FPEXC:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000055 if (entering(tcp))
56 tprints(", ");
57 else
58 printnum_int(tcp, tcp->u_arg[1], "%u");
59 break;
60
Dmitry V. Levin1e880732015-02-14 01:51:03 +000061 case PR_GET_NAME:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000062 if (entering(tcp))
63 tprints(", ");
64 else {
65 if (syserror(tcp))
66 printaddr(tcp->u_arg[1]);
67 else
68 printstr(tcp, tcp->u_arg[1], -1);
69 }
70 break;
71
Dmitry V. Levin1e880732015-02-14 01:51:03 +000072 case PR_GET_PDEATHSIG:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000073 if (entering(tcp))
74 tprints(", ");
75 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
76 tprints("[");
77 tprints(signame(i));
78 tprints("]");
79 }
80 break;
81
Dmitry V. Levin1e880732015-02-14 01:51:03 +000082 case PR_GET_SECUREBITS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000083 if (entering(tcp))
84 break;
85 if (syserror(tcp) || tcp->u_rval == 0)
86 return 0;
87 tcp->auxstr = sprintflags("", secbits, tcp->u_rval);
88 return RVAL_STR;
89
Dmitry V. Levin1e880732015-02-14 01:51:03 +000090 case PR_GET_TID_ADDRESS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000091 if (entering(tcp))
92 tprints(", ");
93 else
94 printnum_long(tcp, tcp->u_arg[1], "%#lx");
95 break;
96
Dmitry V. Levin1e880732015-02-14 01:51:03 +000097 case PR_GET_TSC:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +000098 if (entering(tcp))
99 tprints(", ");
100 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
101 tprints("[");
102 printxval(pr_tsc, i, "PR_TSC_???");
103 tprints("]");
104 }
105 break;
106
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000107 case PR_GET_UNALIGN:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000108 if (entering(tcp))
109 tprints(", ");
110 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) {
111 tprints("[");
112 printflags(pr_unalign_flags, i, "PR_UNALIGN_???");
113 tprints("]");
114 }
115 break;
116
117 /* PR_TASK_PERF_EVENTS_* take no arguments. */
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000118 case PR_TASK_PERF_EVENTS_DISABLE:
119 case PR_TASK_PERF_EVENTS_ENABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000120 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000121
122 case PR_SET_CHILD_SUBREAPER:
123 case PR_SET_DUMPABLE:
124 case PR_SET_ENDIAN:
125 case PR_SET_FPEMU:
126 case PR_SET_FPEXC:
127 case PR_SET_KEEPCAPS:
128 case PR_SET_TIMING:
129 tprintf(", %lu", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000130 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000131
132 case PR_CAPBSET_DROP:
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000133 tprints(", ");
134 printxval(cap, tcp->u_arg[1], "CAP_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000135 return RVAL_DECODED;
136
137 case PR_CAPBSET_READ:
138 if (entering(tcp)) {
139 tprints(", ");
140 printxval(cap, tcp->u_arg[1], "CAP_???");
141 break;
142 }
143 return syserror(tcp) ? 0 : RVAL_UDECIMAL;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000144
145 case PR_MCE_KILL:
146 tprints(", ");
147 printxval(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???");
148 tprints(", ");
149 if (PR_MCE_KILL_SET == tcp->u_arg[1])
150 printxval(pr_mce_kill_policy, tcp->u_arg[2],
151 "PR_MCE_KILL_???");
152 else
153 tprintf("%#lx", tcp->u_arg[2]);
154 for (i = 3; i < tcp->s_ent->nargs; i++)
155 tprintf(", %#lx", tcp->u_arg[i]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000156 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000157
158 case PR_SET_NAME:
159 tprints(", ");
160 printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000161 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000162
163 case PR_SET_MM:
164 tprints(", ");
165 printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
166 for (i = 2; i < tcp->s_ent->nargs; i++)
167 tprintf(", %#lx", tcp->u_arg[i]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000168 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000169
170 case PR_SET_PDEATHSIG:
171 tprints(", ");
172 if ((unsigned long) tcp->u_arg[1] > 128)
173 tprintf("%lu", tcp->u_arg[1]);
174 else
175 tprints(signame(tcp->u_arg[1]));
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000176 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000177
178 case PR_SET_PTRACER:
179 tprints(", ");
180 if (tcp->u_arg[1] == -1)
181 tprints("PR_SET_PTRACER_ANY");
182 else
183 tprintf("%lu", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000184 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000185
186 case PR_SET_SECCOMP:
187 tprints(", ");
188 printxval(seccomp_mode, tcp->u_arg[1],
189 "SECCOMP_MODE_???");
190 if (SECCOMP_MODE_STRICT == tcp->u_arg[1])
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000191 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000192 if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) {
193 tprints(", ");
194 print_seccomp_filter(tcp, tcp->u_arg[2]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000195 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000196 }
197 for (i = 2; i < tcp->s_ent->nargs; i++)
198 tprintf(", %#lx", tcp->u_arg[i]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000199 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000200
201 case PR_SET_SECUREBITS:
202 tprints(", ");
203 printflags(secbits, tcp->u_arg[1], "SECBIT_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000204 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000205
206 case PR_SET_TIMERSLACK:
207 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000208 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000209
210 case PR_SET_TSC:
211 tprints(", ");
212 printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000213 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000214
215 case PR_SET_UNALIGN:
216 tprints(", ");
217 printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000218 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000219
220 case PR_SET_NO_NEW_PRIVS:
221 case PR_SET_THP_DISABLE:
222 tprintf(", %lu", tcp->u_arg[1]);
223 for (i = 2; i < tcp->s_ent->nargs; i++)
224 tprintf(", %#lx", tcp->u_arg[i]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000225 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000226
227 case PR_GET_NO_NEW_PRIVS:
228 case PR_GET_THP_DISABLE:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000229 if (entering(tcp))
230 return printargs(tcp);
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000231 return syserror(tcp) ? 0 : RVAL_UDECIMAL;
232
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000233 case PR_MCE_KILL_GET:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000234 if (entering(tcp))
235 return printargs(tcp);
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000236 if (syserror(tcp))
237 return 0;
238 tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval);
239 return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL;
240
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000241 case PR_MPX_DISABLE_MANAGEMENT:
242 case PR_MPX_ENABLE_MANAGEMENT:
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000243 default:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000244 printargs(tcp);
245 return RVAL_DECODED;
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000246 }
247 return 0;
248}
249
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000250#if defined X86_64 || defined X32
251# include <asm/prctl.h>
252# include "xlat/archvals.h"
253
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000254SYS_FUNC(arch_prctl)
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000255{
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000256 if (entering(tcp))
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000257 printxval(archvals, tcp->u_arg[0], "ARCH_???");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000258
259 switch (tcp->u_arg[0]) {
260 case ARCH_GET_GS:
261 case ARCH_GET_FS:
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000262 if (entering(tcp))
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000263 tprints(", ");
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000264 else
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000265 printnum_long(tcp, tcp->u_arg[1], "%#lx");
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000266 return 0;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000267 }
Dmitry V. Levin1e880732015-02-14 01:51:03 +0000268
269 tprintf(", %#lx", tcp->u_arg[1]);
Dmitry V. Levin210a6b62015-07-17 21:49:17 +0000270 return RVAL_DECODED;
Dmitry V. Levin53c993d2014-12-11 19:25:02 +0000271}
272#endif /* X86_64 || X32 */