Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 1 | #include "defs.h" |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 2 | |
| 3 | typedef int32_t key_serial_t; |
| 4 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 5 | #include "xlat/key_spec.h" |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 6 | |
| 7 | static void |
| 8 | print_keyring_serial_number(key_serial_t id) |
| 9 | { |
| 10 | const char *str = xlookup(key_spec, id); |
| 11 | |
| 12 | if (str) |
| 13 | tprints(str); |
| 14 | else |
| 15 | tprintf("%d", id); |
| 16 | } |
| 17 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 18 | SYS_FUNC(add_key) |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 19 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 20 | /* type */ |
| 21 | printstr(tcp, tcp->u_arg[0], -1); |
| 22 | /* description */ |
| 23 | tprints(", "); |
| 24 | printstr(tcp, tcp->u_arg[1], -1); |
| 25 | /* payload */ |
| 26 | tprints(", "); |
| 27 | printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
| 28 | /* payload length */ |
| 29 | tprintf(", %lu, ", tcp->u_arg[3]); |
| 30 | /* keyring serial number */ |
| 31 | print_keyring_serial_number(tcp->u_arg[4]); |
| 32 | |
| 33 | return RVAL_DECODED; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 36 | SYS_FUNC(request_key) |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 37 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 38 | /* type */ |
| 39 | printstr(tcp, tcp->u_arg[0], -1); |
| 40 | /* description */ |
| 41 | tprints(", "); |
| 42 | printstr(tcp, tcp->u_arg[1], -1); |
| 43 | /* callout_info */ |
| 44 | tprints(", "); |
| 45 | printstr(tcp, tcp->u_arg[2], -1); |
| 46 | /* keyring serial number */ |
| 47 | tprints(", "); |
| 48 | print_keyring_serial_number(tcp->u_arg[3]); |
| 49 | |
| 50 | return RVAL_DECODED; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 53 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 54 | keyctl_get_keyring_id(struct tcb *tcp, key_serial_t id, int create) |
| 55 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 56 | print_keyring_serial_number(id); |
| 57 | tprintf(", %d", create); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 60 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 61 | keyctl_update_key(struct tcb *tcp, key_serial_t id, long addr, long len) |
| 62 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 63 | print_keyring_serial_number(id); |
| 64 | tprints(", "); |
| 65 | printstr(tcp, addr, len); |
| 66 | tprintf(", %lu", len); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 69 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 70 | keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2) |
| 71 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 72 | print_keyring_serial_number(id1); |
| 73 | tprints(", "); |
| 74 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 77 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 78 | keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len) |
| 79 | { |
| 80 | if (entering(tcp)) { |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 81 | print_keyring_serial_number(id); |
| 82 | tprints(", "); |
| 83 | } else { |
Dmitry V. Levin | 5f6ca3d | 2015-07-20 00:26:23 +0000 | [diff] [blame] | 84 | if (syserror(tcp)) |
| 85 | printaddr(addr); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 86 | else { |
| 87 | long rval = tcp->u_rval > len ? |
| 88 | len : (tcp->u_rval ? -1 : 0); |
| 89 | printstr(tcp, addr, rval); |
| 90 | } |
| 91 | tprintf(", %lu", len); |
| 92 | } |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 95 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 96 | keyctl_keyring_search(struct tcb *tcp, key_serial_t id1, long addr1, |
| 97 | long addr2, key_serial_t id2) |
| 98 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 99 | print_keyring_serial_number(id1); |
| 100 | tprints(", "); |
| 101 | printstr(tcp, addr1, -1); |
| 102 | tprints(", "); |
| 103 | printstr(tcp, addr2, -1); |
| 104 | tprints(", "); |
| 105 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 108 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 109 | keyctl_chown_key(struct tcb *tcp, key_serial_t id, int user, int group) |
| 110 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 111 | print_keyring_serial_number(id); |
| 112 | tprintf(", %d, %d", user, group); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 115 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 116 | keyctl_instantiate_key(struct tcb *tcp, key_serial_t id1, long addr, |
| 117 | long len, key_serial_t id2) |
| 118 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 119 | print_keyring_serial_number(id1); |
| 120 | tprints(", "); |
| 121 | printstr(tcp, addr, len); |
| 122 | tprintf(", %lu, ", len); |
| 123 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 126 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 127 | keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1, |
| 128 | long addr, long len, key_serial_t id2) |
| 129 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 130 | print_keyring_serial_number(id1); |
| 131 | tprints(", "); |
| 132 | tprint_iov(tcp, len, addr, 1); |
| 133 | tprintf(", %lu, ", len); |
| 134 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 137 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 138 | keyctl_negate_key(struct tcb *tcp, key_serial_t id1, unsigned timeout, |
| 139 | key_serial_t id2) |
| 140 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 141 | print_keyring_serial_number(id1); |
| 142 | tprintf(", %u, ", timeout); |
| 143 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 146 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 147 | keyctl_reject_key(struct tcb *tcp, key_serial_t id1, unsigned timeout, |
| 148 | unsigned error, key_serial_t id2) |
| 149 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 150 | print_keyring_serial_number(id1); |
| 151 | tprintf(", %u, %u, ", timeout, error); |
| 152 | print_keyring_serial_number(id2); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 155 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 156 | keyctl_set_timeout(struct tcb *tcp, key_serial_t id, unsigned timeout) |
| 157 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 158 | print_keyring_serial_number(id); |
| 159 | tprintf(", %u", timeout); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 162 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 163 | keyctl_get_persistent(struct tcb *tcp, int uid, key_serial_t id) |
| 164 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 165 | tprintf("%d, ", uid); |
| 166 | print_keyring_serial_number(id); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 169 | #include "xlat/key_perms.h" |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 170 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 171 | static void |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 172 | keyctl_setperm_key(struct tcb *tcp, key_serial_t id, uint32_t perm) |
| 173 | { |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 174 | print_keyring_serial_number(id); |
| 175 | tprints(", "); |
| 176 | printflags(key_perms, perm, "KEY_???"); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 179 | #include "xlat/key_reqkeys.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 180 | #include "xlat/keyctl_commands.h" |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 181 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 182 | SYS_FUNC(keyctl) |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 183 | { |
| 184 | int cmd = tcp->u_arg[0]; |
| 185 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 186 | if (entering(tcp)) { |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 187 | printxval(keyctl_commands, cmd, "KEYCTL_???"); |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 188 | tprints(", "); |
| 189 | } |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 190 | |
| 191 | switch (cmd) { |
| 192 | case KEYCTL_GET_KEYRING_ID: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 193 | keyctl_get_keyring_id(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 194 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 195 | |
| 196 | case KEYCTL_JOIN_SESSION_KEYRING: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 197 | printstr(tcp, tcp->u_arg[1], -1); |
| 198 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 199 | |
| 200 | case KEYCTL_UPDATE: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 201 | keyctl_update_key(tcp, tcp->u_arg[1], |
| 202 | tcp->u_arg[2], tcp->u_arg[3]); |
| 203 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 204 | |
| 205 | case KEYCTL_REVOKE: |
| 206 | case KEYCTL_CLEAR: |
| 207 | case KEYCTL_INVALIDATE: |
| 208 | case KEYCTL_ASSUME_AUTHORITY: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 209 | print_keyring_serial_number(tcp->u_arg[1]); |
| 210 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 211 | |
| 212 | case KEYCTL_LINK: |
| 213 | case KEYCTL_UNLINK: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 214 | keyctl_handle_key_key(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 215 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 216 | |
| 217 | case KEYCTL_DESCRIBE: |
| 218 | case KEYCTL_READ: |
| 219 | case KEYCTL_GET_SECURITY: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 220 | keyctl_read_key(tcp, tcp->u_arg[1], |
| 221 | tcp->u_arg[2], tcp->u_arg[3]); |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 222 | return 0; |
| 223 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 224 | case KEYCTL_SEARCH: |
| 225 | keyctl_keyring_search(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 226 | tcp->u_arg[3], tcp->u_arg[4]); |
| 227 | break; |
| 228 | |
| 229 | case KEYCTL_CHOWN: |
| 230 | keyctl_chown_key(tcp, tcp->u_arg[1], |
| 231 | tcp->u_arg[2], tcp->u_arg[3]); |
| 232 | break; |
| 233 | |
| 234 | case KEYCTL_SETPERM: |
| 235 | keyctl_setperm_key(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 236 | break; |
| 237 | |
| 238 | case KEYCTL_INSTANTIATE: |
| 239 | keyctl_instantiate_key(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 240 | tcp->u_arg[3], tcp->u_arg[4]); |
| 241 | break; |
| 242 | |
| 243 | case KEYCTL_NEGATE: |
| 244 | keyctl_negate_key(tcp, tcp->u_arg[1], |
| 245 | tcp->u_arg[2], tcp->u_arg[3]); |
| 246 | break; |
| 247 | |
| 248 | case KEYCTL_SET_REQKEY_KEYRING: |
| 249 | printxval(key_reqkeys, tcp->u_arg[1], "KEY_REQKEY_DEFL_???"); |
| 250 | break; |
| 251 | |
| 252 | case KEYCTL_SET_TIMEOUT: |
| 253 | keyctl_set_timeout(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 254 | break; |
| 255 | |
| 256 | case KEYCTL_SESSION_TO_PARENT: |
| 257 | break; |
| 258 | |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 259 | case KEYCTL_REJECT: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 260 | keyctl_reject_key(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 261 | tcp->u_arg[3], tcp->u_arg[4]); |
| 262 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 263 | |
| 264 | case KEYCTL_INSTANTIATE_IOV: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 265 | keyctl_instantiate_key_iov(tcp, tcp->u_arg[1], |
| 266 | tcp->u_arg[2], tcp->u_arg[3], |
| 267 | tcp->u_arg[4]); |
| 268 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 269 | |
| 270 | case KEYCTL_GET_PERSISTENT: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 271 | keyctl_get_persistent(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 272 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 273 | |
| 274 | default: |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 275 | tprintf("%#lx, %#lx, %#lx, %#lx", |
| 276 | tcp->u_arg[1], tcp->u_arg[2], |
| 277 | tcp->u_arg[3], tcp->u_arg[4]); |
| 278 | break; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Dmitry V. Levin | 4eef291 | 2015-07-20 00:48:49 +0000 | [diff] [blame] | 281 | return RVAL_DECODED; |
Dmitry V. Levin | 3acf403 | 2014-02-05 22:41:45 +0000 | [diff] [blame] | 282 | } |