-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyctl.c
346 lines (300 loc) · 7.01 KB
/
keyctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#include "defs.h"
typedef int32_t key_serial_t;
#include "xlat/key_spec.h"
static void
print_keyring_serial_number(key_serial_t id)
{
const char *str = xlookup(key_spec, id);
if (str)
tprints(str);
else
tprintf("%d", id);
}
SYS_FUNC(add_key)
{
if (entering(tcp)) {
/* type */
printstr(tcp, tcp->u_arg[0], -1);
/* description */
tprints(", ");
printstr(tcp, tcp->u_arg[1], -1);
/* payload */
tprints(", ");
printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
/* payload length */
tprintf(", %lu, ", tcp->u_arg[3]);
/* keyring serial number */
print_keyring_serial_number(tcp->u_arg[4]);
}
return 0;
}
SYS_FUNC(request_key)
{
if (entering(tcp)) {
/* type */
printstr(tcp, tcp->u_arg[0], -1);
/* description */
tprints(", ");
printstr(tcp, tcp->u_arg[1], -1);
/* callout_info */
tprints(", ");
printstr(tcp, tcp->u_arg[2], -1);
/* keyring serial number */
tprints(", ");
print_keyring_serial_number(tcp->u_arg[3]);
}
return 0;
}
static int
keyctl_get_keyring_id(struct tcb *tcp, key_serial_t id, int create)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprintf(", %d", create);
}
return 0;
}
static int
keyctl_join_session_keyring(struct tcb *tcp, long addr)
{
if (entering(tcp)) {
tprints(", ");
printstr(tcp, addr, -1);
}
return 0;
}
static int
keyctl_update_key(struct tcb *tcp, key_serial_t id, long addr, long len)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprints(", ");
printstr(tcp, addr, len);
tprintf(", %lu", len);
}
return 0;
}
static int
keyctl_handle_key(struct tcb *tcp, key_serial_t id)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
}
return 0;
}
static int
keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprints(", ");
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprints(", ");
} else {
if (addr && syserror(tcp))
tprintf("%#lx", addr);
else {
long rval = tcp->u_rval > len ?
len : (tcp->u_rval ? -1 : 0);
printstr(tcp, addr, rval);
}
tprintf(", %lu", len);
}
return 0;
}
static int
keyctl_keyring_search(struct tcb *tcp, key_serial_t id1, long addr1,
long addr2, key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprints(", ");
printstr(tcp, addr1, -1);
tprints(", ");
printstr(tcp, addr2, -1);
tprints(", ");
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_chown_key(struct tcb *tcp, key_serial_t id, int user, int group)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprintf(", %d, %d", user, group);
}
return 0;
}
static int
keyctl_instantiate_key(struct tcb *tcp, key_serial_t id1, long addr,
long len, key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprints(", ");
printstr(tcp, addr, len);
tprintf(", %lu, ", len);
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1,
long addr, long len, key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprints(", ");
tprint_iov(tcp, len, addr, 1);
tprintf(", %lu, ", len);
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_negate_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprintf(", %u, ", timeout);
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_reject_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
unsigned error, key_serial_t id2)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id1);
tprintf(", %u, %u, ", timeout, error);
print_keyring_serial_number(id2);
}
return 0;
}
static int
keyctl_set_timeout(struct tcb *tcp, key_serial_t id, unsigned timeout)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprintf(", %u", timeout);
}
return 0;
}
static int
keyctl_get_persistent(struct tcb *tcp, int uid, key_serial_t id)
{
if (entering(tcp)) {
tprintf(", %d, ", uid);
print_keyring_serial_number(id);
}
return 0;
}
#include "xlat/key_perms.h"
static int
keyctl_setperm_key(struct tcb *tcp, key_serial_t id, uint32_t perm)
{
if (entering(tcp)) {
tprints(", ");
print_keyring_serial_number(id);
tprints(", ");
printflags(key_perms, perm, "KEY_???");
}
return 0;
}
#include "xlat/key_reqkeys.h"
static int
keyctl_set_reqkey_keyring(struct tcb *tcp, int reqkey)
{
if (entering(tcp)) {
tprints(", ");
printxval(key_reqkeys, reqkey, "KEY_REQKEY_DEFL_???");
}
return 0;
}
#include "xlat/keyctl_commands.h"
SYS_FUNC(keyctl)
{
int cmd = tcp->u_arg[0];
if (entering(tcp))
printxval(keyctl_commands, cmd, "KEYCTL_???");
switch (cmd) {
case KEYCTL_GET_KEYRING_ID:
return keyctl_get_keyring_id(tcp, tcp->u_arg[1], tcp->u_arg[2]);
case KEYCTL_JOIN_SESSION_KEYRING:
return keyctl_join_session_keyring(tcp, tcp->u_arg[1]);
case KEYCTL_UPDATE:
return keyctl_update_key(tcp, tcp->u_arg[1],
tcp->u_arg[2], tcp->u_arg[3]);
case KEYCTL_REVOKE:
case KEYCTL_CLEAR:
case KEYCTL_INVALIDATE:
case KEYCTL_ASSUME_AUTHORITY:
return keyctl_handle_key(tcp, tcp->u_arg[1]);
case KEYCTL_LINK:
case KEYCTL_UNLINK:
return keyctl_handle_key_key(tcp, tcp->u_arg[1], tcp->u_arg[2]);
case KEYCTL_DESCRIBE:
case KEYCTL_READ:
case KEYCTL_GET_SECURITY:
return keyctl_read_key(tcp, tcp->u_arg[1],
tcp->u_arg[2], tcp->u_arg[3]);
case KEYCTL_SEARCH:
return keyctl_keyring_search(tcp, tcp->u_arg[1], tcp->u_arg[2],
tcp->u_arg[3], tcp->u_arg[4]);
case KEYCTL_CHOWN:
return keyctl_chown_key(tcp, tcp->u_arg[1],
tcp->u_arg[2], tcp->u_arg[3]);
case KEYCTL_SETPERM:
return keyctl_setperm_key(tcp, tcp->u_arg[1], tcp->u_arg[2]);
case KEYCTL_INSTANTIATE:
return keyctl_instantiate_key(tcp, tcp->u_arg[1], tcp->u_arg[2],
tcp->u_arg[3], tcp->u_arg[4]);
case KEYCTL_NEGATE:
return keyctl_negate_key(tcp, tcp->u_arg[1],
tcp->u_arg[2], tcp->u_arg[3]);
case KEYCTL_SET_REQKEY_KEYRING:
return keyctl_set_reqkey_keyring(tcp, tcp->u_arg[1]);
case KEYCTL_SET_TIMEOUT:
return keyctl_set_timeout(tcp, tcp->u_arg[1], tcp->u_arg[2]);
case KEYCTL_SESSION_TO_PARENT:
return 0;
case KEYCTL_REJECT:
return keyctl_reject_key(tcp, tcp->u_arg[1], tcp->u_arg[2],
tcp->u_arg[3], tcp->u_arg[4]);
case KEYCTL_INSTANTIATE_IOV:
return keyctl_instantiate_key_iov(tcp, tcp->u_arg[1],
tcp->u_arg[2], tcp->u_arg[3],
tcp->u_arg[4]);
case KEYCTL_GET_PERSISTENT:
return keyctl_get_persistent(tcp, tcp->u_arg[1], tcp->u_arg[2]);
default:
if (entering(tcp))
tprintf(", %#lx, %#lx, %#lx, %#lx",
tcp->u_arg[1], tcp->u_arg[2],
tcp->u_arg[3], tcp->u_arg[4]);
}
return 0;
}