Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 3 | #include <sys/prctl.h> |
| 4 | |
| 5 | #include "xlat/prctl_options.h" |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 6 | #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. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 11 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 12 | #ifndef TASK_COMM_LEN |
| 13 | # define TASK_COMM_LEN 16 |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 14 | #endif |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 15 | |
Dmitry V. Levin | 2af6903 | 2015-02-04 23:50:50 +0000 | [diff] [blame] | 16 | #ifdef HAVE_LINUX_SECCOMP_H |
| 17 | # include <linux/seccomp.h> |
| 18 | #endif |
Dmitry V. Levin | 2af6903 | 2015-02-04 23:50:50 +0000 | [diff] [blame] | 19 | #include "xlat/seccomp_mode.h" |
| 20 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 21 | #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> */ |
| 27 | enum { |
| 28 | #include "caps0.h" |
| 29 | #include "caps1.h" |
| 30 | }; |
| 31 | |
| 32 | #include "xlat/cap.h" |
| 33 | |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 34 | static void |
| 35 | print_prctl_args(struct tcb *tcp, const unsigned int first) |
| 36 | { |
| 37 | unsigned int i; |
| 38 | |
| 39 | for (i = first; i < tcp->s_ent->nargs; ++i) |
| 40 | tprintf(", %#lx", tcp->u_arg[i]); |
| 41 | } |
| 42 | |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 43 | SYS_FUNC(prctl) |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 44 | { |
| 45 | unsigned int i; |
| 46 | |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 47 | if (entering(tcp)) |
| 48 | printxval(prctl_options, tcp->u_arg[0], "PR_???"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 49 | |
| 50 | switch (tcp->u_arg[0]) { |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 51 | case PR_GET_DUMPABLE: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 52 | case PR_GET_KEEPCAPS: |
| 53 | case PR_GET_SECCOMP: |
| 54 | case PR_GET_TIMERSLACK: |
| 55 | case PR_GET_TIMING: |
| 56 | if (entering(tcp)) |
| 57 | break; |
| 58 | return syserror(tcp) ? 0 : RVAL_UDECIMAL; |
| 59 | |
| 60 | case PR_GET_CHILD_SUBREAPER: |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 61 | case PR_GET_ENDIAN: |
| 62 | case PR_GET_FPEMU: |
| 63 | case PR_GET_FPEXC: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 64 | if (entering(tcp)) |
| 65 | tprints(", "); |
| 66 | else |
| 67 | printnum_int(tcp, tcp->u_arg[1], "%u"); |
| 68 | break; |
| 69 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 70 | case PR_GET_NAME: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 71 | if (entering(tcp)) |
| 72 | tprints(", "); |
| 73 | else { |
| 74 | if (syserror(tcp)) |
| 75 | printaddr(tcp->u_arg[1]); |
| 76 | else |
| 77 | printstr(tcp, tcp->u_arg[1], -1); |
| 78 | } |
| 79 | break; |
| 80 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 81 | case PR_GET_PDEATHSIG: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 82 | if (entering(tcp)) |
| 83 | tprints(", "); |
| 84 | else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) { |
| 85 | tprints("["); |
| 86 | tprints(signame(i)); |
| 87 | tprints("]"); |
| 88 | } |
| 89 | break; |
| 90 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 91 | case PR_GET_SECUREBITS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 92 | if (entering(tcp)) |
| 93 | break; |
| 94 | if (syserror(tcp) || tcp->u_rval == 0) |
| 95 | return 0; |
| 96 | tcp->auxstr = sprintflags("", secbits, tcp->u_rval); |
| 97 | return RVAL_STR; |
| 98 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 99 | case PR_GET_TID_ADDRESS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 100 | if (entering(tcp)) |
| 101 | tprints(", "); |
| 102 | else |
| 103 | printnum_long(tcp, tcp->u_arg[1], "%#lx"); |
| 104 | break; |
| 105 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 106 | case PR_GET_TSC: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 107 | if (entering(tcp)) |
| 108 | tprints(", "); |
| 109 | else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) { |
| 110 | tprints("["); |
| 111 | printxval(pr_tsc, i, "PR_TSC_???"); |
| 112 | tprints("]"); |
| 113 | } |
| 114 | break; |
| 115 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 116 | case PR_GET_UNALIGN: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 117 | if (entering(tcp)) |
| 118 | tprints(", "); |
| 119 | else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &i)) { |
| 120 | tprints("["); |
| 121 | printflags(pr_unalign_flags, i, "PR_UNALIGN_???"); |
| 122 | tprints("]"); |
| 123 | } |
| 124 | break; |
| 125 | |
| 126 | /* PR_TASK_PERF_EVENTS_* take no arguments. */ |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 127 | case PR_TASK_PERF_EVENTS_DISABLE: |
| 128 | case PR_TASK_PERF_EVENTS_ENABLE: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 129 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 130 | |
| 131 | case PR_SET_CHILD_SUBREAPER: |
| 132 | case PR_SET_DUMPABLE: |
| 133 | case PR_SET_ENDIAN: |
| 134 | case PR_SET_FPEMU: |
| 135 | case PR_SET_FPEXC: |
| 136 | case PR_SET_KEEPCAPS: |
| 137 | case PR_SET_TIMING: |
| 138 | tprintf(", %lu", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 139 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 140 | |
| 141 | case PR_CAPBSET_DROP: |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 142 | tprints(", "); |
| 143 | printxval(cap, tcp->u_arg[1], "CAP_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 144 | return RVAL_DECODED; |
| 145 | |
| 146 | case PR_CAPBSET_READ: |
| 147 | if (entering(tcp)) { |
| 148 | tprints(", "); |
| 149 | printxval(cap, tcp->u_arg[1], "CAP_???"); |
| 150 | break; |
| 151 | } |
| 152 | return syserror(tcp) ? 0 : RVAL_UDECIMAL; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 153 | |
| 154 | case PR_MCE_KILL: |
| 155 | tprints(", "); |
| 156 | printxval(pr_mce_kill, tcp->u_arg[1], "PR_MCE_KILL_???"); |
| 157 | tprints(", "); |
| 158 | if (PR_MCE_KILL_SET == tcp->u_arg[1]) |
| 159 | printxval(pr_mce_kill_policy, tcp->u_arg[2], |
| 160 | "PR_MCE_KILL_???"); |
| 161 | else |
| 162 | tprintf("%#lx", tcp->u_arg[2]); |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 163 | print_prctl_args(tcp, 3); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 164 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 165 | |
| 166 | case PR_SET_NAME: |
| 167 | tprints(", "); |
| 168 | printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 169 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 170 | |
| 171 | case PR_SET_MM: |
| 172 | tprints(", "); |
| 173 | printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???"); |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 174 | print_prctl_args(tcp, 2); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 175 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 176 | |
| 177 | case PR_SET_PDEATHSIG: |
| 178 | tprints(", "); |
| 179 | if ((unsigned long) tcp->u_arg[1] > 128) |
| 180 | tprintf("%lu", tcp->u_arg[1]); |
| 181 | else |
| 182 | tprints(signame(tcp->u_arg[1])); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 183 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 184 | |
| 185 | case PR_SET_PTRACER: |
| 186 | tprints(", "); |
| 187 | if (tcp->u_arg[1] == -1) |
| 188 | tprints("PR_SET_PTRACER_ANY"); |
| 189 | else |
| 190 | tprintf("%lu", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 191 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 192 | |
| 193 | case PR_SET_SECCOMP: |
| 194 | tprints(", "); |
| 195 | printxval(seccomp_mode, tcp->u_arg[1], |
| 196 | "SECCOMP_MODE_???"); |
| 197 | if (SECCOMP_MODE_STRICT == tcp->u_arg[1]) |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 198 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 199 | if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) { |
| 200 | tprints(", "); |
| 201 | print_seccomp_filter(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 202 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 203 | } |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 204 | print_prctl_args(tcp, 2); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 205 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 206 | |
| 207 | case PR_SET_SECUREBITS: |
| 208 | tprints(", "); |
| 209 | printflags(secbits, tcp->u_arg[1], "SECBIT_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 210 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 211 | |
| 212 | case PR_SET_TIMERSLACK: |
| 213 | tprintf(", %ld", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 214 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 215 | |
| 216 | case PR_SET_TSC: |
| 217 | tprints(", "); |
| 218 | printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 219 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 220 | |
| 221 | case PR_SET_UNALIGN: |
| 222 | tprints(", "); |
| 223 | printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 224 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 225 | |
| 226 | case PR_SET_NO_NEW_PRIVS: |
| 227 | case PR_SET_THP_DISABLE: |
| 228 | tprintf(", %lu", tcp->u_arg[1]); |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 229 | print_prctl_args(tcp, 2); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 230 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 231 | |
| 232 | case PR_GET_NO_NEW_PRIVS: |
| 233 | case PR_GET_THP_DISABLE: |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 234 | if (entering(tcp)) { |
| 235 | print_prctl_args(tcp, 1); |
| 236 | return 0; |
| 237 | } |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 238 | return syserror(tcp) ? 0 : RVAL_UDECIMAL; |
| 239 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 240 | case PR_MCE_KILL_GET: |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 241 | if (entering(tcp)) { |
| 242 | print_prctl_args(tcp, 1); |
| 243 | return 0; |
| 244 | } |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 245 | if (syserror(tcp)) |
| 246 | return 0; |
| 247 | tcp->auxstr = xlookup(pr_mce_kill_policy, tcp->u_rval); |
| 248 | return tcp->auxstr ? RVAL_STR : RVAL_UDECIMAL; |
| 249 | |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 250 | case PR_MPX_DISABLE_MANAGEMENT: |
| 251 | case PR_MPX_ENABLE_MANAGEMENT: |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 252 | default: |
Dmitry V. Levin | 3691562 | 2015-07-25 09:43:01 +0000 | [diff] [blame^] | 253 | print_prctl_args(tcp, 1); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 254 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 259 | #if defined X86_64 || defined X32 |
| 260 | # include <asm/prctl.h> |
| 261 | # include "xlat/archvals.h" |
| 262 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 263 | SYS_FUNC(arch_prctl) |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 264 | { |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 265 | if (entering(tcp)) |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 266 | printxval(archvals, tcp->u_arg[0], "ARCH_???"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 267 | |
| 268 | switch (tcp->u_arg[0]) { |
| 269 | case ARCH_GET_GS: |
| 270 | case ARCH_GET_FS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 271 | if (entering(tcp)) |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 272 | tprints(", "); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 273 | else |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 274 | printnum_long(tcp, tcp->u_arg[1], "%#lx"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 275 | return 0; |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 276 | } |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 277 | |
| 278 | tprintf(", %#lx", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 279 | return RVAL_DECODED; |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 280 | } |
| 281 | #endif /* X86_64 || X32 */ |