blob: 0c4961f9eeaea6c1bde15a6af4bd098809a048bc [file] [log] [blame]
Dmitry V. Levin3acf4032014-02-05 22:41:45 +00001#include "defs.h"
Dmitry V. Levin3acf4032014-02-05 22:41:45 +00002
3typedef int32_t key_serial_t;
4
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00005#include "xlat/key_spec.h"
Dmitry V. Levin3acf4032014-02-05 22:41:45 +00006
7static void
8print_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. Levina0bd3742015-04-07 01:36:50 +000018SYS_FUNC(add_key)
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000019{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000020 /* 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. Levin3acf4032014-02-05 22:41:45 +000034}
35
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000036SYS_FUNC(request_key)
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000037{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000038 /* 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. Levin3acf4032014-02-05 22:41:45 +000051}
52
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000053static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000054keyctl_get_keyring_id(struct tcb *tcp, key_serial_t id, int create)
55{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000056 print_keyring_serial_number(id);
57 tprintf(", %d", create);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000058}
59
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000060static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000061keyctl_update_key(struct tcb *tcp, key_serial_t id, long addr, long len)
62{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000063 print_keyring_serial_number(id);
64 tprints(", ");
65 printstr(tcp, addr, len);
66 tprintf(", %lu", len);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000067}
68
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000069static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000070keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2)
71{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000072 print_keyring_serial_number(id1);
73 tprints(", ");
74 print_keyring_serial_number(id2);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000075}
76
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000077static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000078keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len)
79{
80 if (entering(tcp)) {
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000081 print_keyring_serial_number(id);
82 tprints(", ");
83 } else {
Dmitry V. Levin5f6ca3d2015-07-20 00:26:23 +000084 if (syserror(tcp))
85 printaddr(addr);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000086 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. Levin3acf4032014-02-05 22:41:45 +000093}
94
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000095static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +000096keyctl_keyring_search(struct tcb *tcp, key_serial_t id1, long addr1,
97 long addr2, key_serial_t id2)
98{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +000099 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. Levin3acf4032014-02-05 22:41:45 +0000106}
107
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000108static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000109keyctl_chown_key(struct tcb *tcp, key_serial_t id, int user, int group)
110{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000111 print_keyring_serial_number(id);
112 tprintf(", %d, %d", user, group);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000113}
114
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000115static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000116keyctl_instantiate_key(struct tcb *tcp, key_serial_t id1, long addr,
117 long len, key_serial_t id2)
118{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000119 print_keyring_serial_number(id1);
120 tprints(", ");
121 printstr(tcp, addr, len);
122 tprintf(", %lu, ", len);
123 print_keyring_serial_number(id2);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000124}
125
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000126static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000127keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1,
128 long addr, long len, key_serial_t id2)
129{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000130 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. Levin3acf4032014-02-05 22:41:45 +0000135}
136
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000137static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000138keyctl_negate_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
139 key_serial_t id2)
140{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000141 print_keyring_serial_number(id1);
142 tprintf(", %u, ", timeout);
143 print_keyring_serial_number(id2);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000144}
145
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000146static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000147keyctl_reject_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
148 unsigned error, key_serial_t id2)
149{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000150 print_keyring_serial_number(id1);
151 tprintf(", %u, %u, ", timeout, error);
152 print_keyring_serial_number(id2);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000153}
154
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000155static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000156keyctl_set_timeout(struct tcb *tcp, key_serial_t id, unsigned timeout)
157{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000158 print_keyring_serial_number(id);
159 tprintf(", %u", timeout);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000160}
161
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000162static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000163keyctl_get_persistent(struct tcb *tcp, int uid, key_serial_t id)
164{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000165 tprintf("%d, ", uid);
166 print_keyring_serial_number(id);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000167}
168
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000169#include "xlat/key_perms.h"
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000170
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000171static void
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000172keyctl_setperm_key(struct tcb *tcp, key_serial_t id, uint32_t perm)
173{
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000174 print_keyring_serial_number(id);
175 tprints(", ");
176 printflags(key_perms, perm, "KEY_???");
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000177}
178
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000179#include "xlat/key_reqkeys.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000180#include "xlat/keyctl_commands.h"
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000181
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000182SYS_FUNC(keyctl)
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000183{
184 int cmd = tcp->u_arg[0];
185
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000186 if (entering(tcp)) {
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000187 printxval(keyctl_commands, cmd, "KEYCTL_???");
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000188 tprints(", ");
189 }
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000190
191 switch (cmd) {
192 case KEYCTL_GET_KEYRING_ID:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000193 keyctl_get_keyring_id(tcp, tcp->u_arg[1], tcp->u_arg[2]);
194 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000195
196 case KEYCTL_JOIN_SESSION_KEYRING:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000197 printstr(tcp, tcp->u_arg[1], -1);
198 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000199
200 case KEYCTL_UPDATE:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000201 keyctl_update_key(tcp, tcp->u_arg[1],
202 tcp->u_arg[2], tcp->u_arg[3]);
203 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000204
205 case KEYCTL_REVOKE:
206 case KEYCTL_CLEAR:
207 case KEYCTL_INVALIDATE:
208 case KEYCTL_ASSUME_AUTHORITY:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000209 print_keyring_serial_number(tcp->u_arg[1]);
210 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000211
212 case KEYCTL_LINK:
213 case KEYCTL_UNLINK:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000214 keyctl_handle_key_key(tcp, tcp->u_arg[1], tcp->u_arg[2]);
215 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000216
217 case KEYCTL_DESCRIBE:
218 case KEYCTL_READ:
219 case KEYCTL_GET_SECURITY:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000220 keyctl_read_key(tcp, tcp->u_arg[1],
221 tcp->u_arg[2], tcp->u_arg[3]);
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000222 return 0;
223
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000224 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. Levin3acf4032014-02-05 22:41:45 +0000259 case KEYCTL_REJECT:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000260 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. Levin3acf4032014-02-05 22:41:45 +0000263
264 case KEYCTL_INSTANTIATE_IOV:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000265 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. Levin3acf4032014-02-05 22:41:45 +0000269
270 case KEYCTL_GET_PERSISTENT:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000271 keyctl_get_persistent(tcp, tcp->u_arg[1], tcp->u_arg[2]);
272 break;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000273
274 default:
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000275 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. Levin3acf4032014-02-05 22:41:45 +0000279 }
280
Dmitry V. Levin4eef2912015-07-20 00:48:49 +0000281 return RVAL_DECODED;
Dmitry V. Levin3acf4032014-02-05 22:41:45 +0000282}