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" |
| 6 | |
| 7 | static const char * |
| 8 | unalignctl_string(unsigned int ctl) |
| 9 | { |
| 10 | static char buf[sizeof(int)*2 + 2]; |
| 11 | |
| 12 | switch (ctl) { |
| 13 | #ifdef PR_UNALIGN_NOPRINT |
| 14 | case PR_UNALIGN_NOPRINT: |
| 15 | return "NOPRINT"; |
| 16 | #endif |
| 17 | #ifdef PR_UNALIGN_SIGBUS |
| 18 | case PR_UNALIGN_SIGBUS: |
| 19 | return "SIGBUS"; |
| 20 | #endif |
| 21 | default: |
| 22 | break; |
| 23 | } |
| 24 | sprintf(buf, "%x", ctl); |
| 25 | return buf; |
| 26 | } |
| 27 | |
Dmitry V. Levin | 2af6903 | 2015-02-04 23:50:50 +0000 | [diff] [blame] | 28 | #ifdef HAVE_LINUX_SECCOMP_H |
| 29 | # include <linux/seccomp.h> |
| 30 | #endif |
| 31 | |
| 32 | #include "xlat/seccomp_mode.h" |
| 33 | |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 34 | int |
| 35 | sys_prctl(struct tcb *tcp) |
| 36 | { |
| 37 | unsigned int i; |
| 38 | |
| 39 | if (entering(tcp)) { |
| 40 | printxval(prctl_options, tcp->u_arg[0], "PR_???"); |
| 41 | switch (tcp->u_arg[0]) { |
| 42 | #ifdef PR_GETNSHARE |
| 43 | case PR_GETNSHARE: |
| 44 | break; |
| 45 | #endif |
| 46 | #ifdef PR_SET_PDEATHSIG |
| 47 | case PR_SET_PDEATHSIG: |
| 48 | tprintf(", %lu", tcp->u_arg[1]); |
| 49 | break; |
| 50 | #endif |
| 51 | #ifdef PR_GET_PDEATHSIG |
| 52 | case PR_GET_PDEATHSIG: |
| 53 | break; |
| 54 | #endif |
| 55 | #ifdef PR_SET_DUMPABLE |
| 56 | case PR_SET_DUMPABLE: |
| 57 | tprintf(", %lu", tcp->u_arg[1]); |
| 58 | break; |
| 59 | #endif |
| 60 | #ifdef PR_GET_DUMPABLE |
| 61 | case PR_GET_DUMPABLE: |
| 62 | break; |
| 63 | #endif |
| 64 | #ifdef PR_SET_UNALIGN |
| 65 | case PR_SET_UNALIGN: |
| 66 | tprintf(", %s", unalignctl_string(tcp->u_arg[1])); |
| 67 | break; |
| 68 | #endif |
| 69 | #ifdef PR_GET_UNALIGN |
| 70 | case PR_GET_UNALIGN: |
| 71 | tprintf(", %#lx", tcp->u_arg[1]); |
| 72 | break; |
| 73 | #endif |
| 74 | #ifdef PR_SET_KEEPCAPS |
| 75 | case PR_SET_KEEPCAPS: |
| 76 | tprintf(", %lu", tcp->u_arg[1]); |
| 77 | break; |
| 78 | #endif |
| 79 | #ifdef PR_GET_KEEPCAPS |
| 80 | case PR_GET_KEEPCAPS: |
| 81 | break; |
| 82 | #endif |
Dmitry V. Levin | 2af6903 | 2015-02-04 23:50:50 +0000 | [diff] [blame] | 83 | |
| 84 | #ifdef PR_SET_SECCOMP |
| 85 | case PR_SET_SECCOMP: |
| 86 | tprints(", "); |
| 87 | printxval(seccomp_mode, tcp->u_arg[1], |
| 88 | "SECCOMP_MODE_???"); |
| 89 | # ifdef SECCOMP_MODE_STRICT |
| 90 | if (SECCOMP_MODE_STRICT == tcp->u_arg[1]) |
| 91 | break; |
| 92 | # endif |
| 93 | # ifdef SECCOMP_MODE_FILTER |
| 94 | if (SECCOMP_MODE_FILTER == tcp->u_arg[1]) { |
| 95 | tprints(", "); |
| 96 | print_seccomp_filter(tcp, tcp->u_arg[2]); |
| 97 | break; |
| 98 | } |
| 99 | # endif |
| 100 | for (i = 2; i < tcp->s_ent->nargs; i++) |
| 101 | tprintf(", %#lx", tcp->u_arg[i]); |
| 102 | break; |
| 103 | #endif /* PR_SET_SECCOMP */ |
| 104 | |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 105 | default: |
| 106 | for (i = 1; i < tcp->s_ent->nargs; i++) |
| 107 | tprintf(", %#lx", tcp->u_arg[i]); |
| 108 | break; |
| 109 | } |
| 110 | } else { |
| 111 | switch (tcp->u_arg[0]) { |
| 112 | #ifdef PR_GET_PDEATHSIG |
| 113 | case PR_GET_PDEATHSIG: |
| 114 | if (umove(tcp, tcp->u_arg[1], &i) < 0) |
| 115 | tprintf(", %#lx", tcp->u_arg[1]); |
| 116 | else |
| 117 | tprintf(", {%u}", i); |
| 118 | break; |
| 119 | #endif |
| 120 | #ifdef PR_GET_DUMPABLE |
| 121 | case PR_GET_DUMPABLE: |
| 122 | return RVAL_UDECIMAL; |
| 123 | #endif |
| 124 | #ifdef PR_GET_UNALIGN |
| 125 | case PR_GET_UNALIGN: |
| 126 | if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0) |
| 127 | break; |
| 128 | tcp->auxstr = unalignctl_string(i); |
| 129 | return RVAL_STR; |
| 130 | #endif |
| 131 | #ifdef PR_GET_KEEPCAPS |
| 132 | case PR_GET_KEEPCAPS: |
| 133 | return RVAL_UDECIMAL; |
| 134 | #endif |
| 135 | default: |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | return 0; |
| 140 | } |
Dmitry V. Levin | 53c993d | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 141 | |
| 142 | #if defined X86_64 || defined X32 |
| 143 | # include <asm/prctl.h> |
| 144 | # include "xlat/archvals.h" |
| 145 | |
| 146 | int |
| 147 | sys_arch_prctl(struct tcb *tcp) |
| 148 | { |
| 149 | if (entering(tcp)) { |
| 150 | printxval(archvals, tcp->u_arg[0], "ARCH_???"); |
| 151 | if (tcp->u_arg[0] == ARCH_SET_GS |
| 152 | || tcp->u_arg[0] == ARCH_SET_FS |
| 153 | ) { |
| 154 | tprintf(", %#lx", tcp->u_arg[1]); |
| 155 | } |
| 156 | } else { |
| 157 | if (tcp->u_arg[0] == ARCH_GET_GS |
| 158 | || tcp->u_arg[0] == ARCH_GET_FS |
| 159 | ) { |
| 160 | long int v; |
| 161 | if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1) |
| 162 | tprintf(", [%#lx]", v); |
| 163 | else |
| 164 | tprintf(", %#lx", tcp->u_arg[1]); |
| 165 | } |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | #endif /* X86_64 || X32 */ |