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 | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 34 | SYS_FUNC(prctl) |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 35 | { |
| 36 | unsigned int i; |
| 37 | |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 38 | if (entering(tcp)) |
| 39 | printxval(prctl_options, tcp->u_arg[0], "PR_???"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 40 | |
| 41 | switch (tcp->u_arg[0]) { |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 42 | case PR_GET_DUMPABLE: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 43 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 52 | case PR_GET_ENDIAN: |
| 53 | case PR_GET_FPEMU: |
| 54 | case PR_GET_FPEXC: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 55 | if (entering(tcp)) |
| 56 | tprints(", "); |
| 57 | else |
| 58 | printnum_int(tcp, tcp->u_arg[1], "%u"); |
| 59 | break; |
| 60 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 61 | case PR_GET_NAME: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 62 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 72 | case PR_GET_PDEATHSIG: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 73 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 82 | case PR_GET_SECUREBITS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 83 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 90 | case PR_GET_TID_ADDRESS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 91 | if (entering(tcp)) |
| 92 | tprints(", "); |
| 93 | else |
| 94 | printnum_long(tcp, tcp->u_arg[1], "%#lx"); |
| 95 | break; |
| 96 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 97 | case PR_GET_TSC: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 98 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 107 | case PR_GET_UNALIGN: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 108 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 118 | case PR_TASK_PERF_EVENTS_DISABLE: |
| 119 | case PR_TASK_PERF_EVENTS_ENABLE: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 120 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 121 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 130 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 131 | |
| 132 | case PR_CAPBSET_DROP: |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 133 | tprints(", "); |
| 134 | printxval(cap, tcp->u_arg[1], "CAP_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 135 | 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. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 144 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 156 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 157 | |
| 158 | case PR_SET_NAME: |
| 159 | tprints(", "); |
| 160 | printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 161 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 162 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 168 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 169 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 176 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 177 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 184 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 185 | |
| 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. 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 | if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) { |
| 193 | tprints(", "); |
| 194 | print_seccomp_filter(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 195 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 196 | } |
| 197 | for (i = 2; i < tcp->s_ent->nargs; i++) |
| 198 | tprintf(", %#lx", tcp->u_arg[i]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 199 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 200 | |
| 201 | case PR_SET_SECUREBITS: |
| 202 | tprints(", "); |
| 203 | printflags(secbits, tcp->u_arg[1], "SECBIT_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 204 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 205 | |
| 206 | case PR_SET_TIMERSLACK: |
| 207 | tprintf(", %ld", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 208 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 209 | |
| 210 | case PR_SET_TSC: |
| 211 | tprints(", "); |
| 212 | printxval(pr_tsc, tcp->u_arg[1], "PR_TSC_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 213 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 214 | |
| 215 | case PR_SET_UNALIGN: |
| 216 | tprints(", "); |
| 217 | printflags(pr_unalign_flags, tcp->u_arg[1], "PR_UNALIGN_???"); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 218 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 219 | |
| 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 225 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 226 | |
| 227 | case PR_GET_NO_NEW_PRIVS: |
| 228 | case PR_GET_THP_DISABLE: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 229 | if (entering(tcp)) |
| 230 | return printargs(tcp); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 231 | return syserror(tcp) ? 0 : RVAL_UDECIMAL; |
| 232 | |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 233 | case PR_MCE_KILL_GET: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 234 | if (entering(tcp)) |
| 235 | return printargs(tcp); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 236 | 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. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 241 | case PR_MPX_DISABLE_MANAGEMENT: |
| 242 | case PR_MPX_ENABLE_MANAGEMENT: |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 243 | default: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 244 | printargs(tcp); |
| 245 | return RVAL_DECODED; |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 250 | #if defined X86_64 || defined X32 |
| 251 | # include <asm/prctl.h> |
| 252 | # include "xlat/archvals.h" |
| 253 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 254 | SYS_FUNC(arch_prctl) |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 255 | { |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 256 | if (entering(tcp)) |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 257 | printxval(archvals, tcp->u_arg[0], "ARCH_???"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 258 | |
| 259 | switch (tcp->u_arg[0]) { |
| 260 | case ARCH_GET_GS: |
| 261 | case ARCH_GET_FS: |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 262 | if (entering(tcp)) |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 263 | tprints(", "); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 264 | else |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 265 | printnum_long(tcp, tcp->u_arg[1], "%#lx"); |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 266 | return 0; |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 267 | } |
Dmitry V. Levin | 1e88073 | 2015-02-14 01:51:03 +0000 | [diff] [blame] | 268 | |
| 269 | tprintf(", %#lx", tcp->u_arg[1]); |
Dmitry V. Levin | 210a6b6 | 2015-07-17 21:49:17 +0000 | [diff] [blame] | 270 | return RVAL_DECODED; |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 271 | } |
| 272 | #endif /* X86_64 || X32 */ |