2 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 typedef int32_t key_serial_t;
32 #include "xlat/key_spec.h"
34 struct keyctl_dh_params {
41 print_keyring_serial_number(key_serial_t id)
43 const char *str = xlookup(key_spec, (unsigned int) id);
54 printstr(tcp, tcp->u_arg[0]);
57 printstr(tcp, tcp->u_arg[1]);
60 printstrn(tcp, tcp->u_arg[2], tcp->u_arg[3]);
62 tprintf(", %" PRI_klu ", ", tcp->u_arg[3]);
63 /* keyring serial number */
64 print_keyring_serial_number(tcp->u_arg[4]);
72 printstr(tcp, tcp->u_arg[0]);
75 printstr(tcp, tcp->u_arg[1]);
78 printstr(tcp, tcp->u_arg[2]);
79 /* keyring serial number */
81 print_keyring_serial_number(tcp->u_arg[3]);
87 keyctl_get_keyring_id(struct tcb *tcp, key_serial_t id, int create)
89 print_keyring_serial_number(id);
90 tprintf(", %d", create);
94 keyctl_update_key(struct tcb *tcp, key_serial_t id, kernel_ulong_t addr,
97 print_keyring_serial_number(id);
99 printstrn(tcp, addr, len);
100 tprintf(", %llu", zero_extend_signed_to_ull(len));
104 keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2)
106 print_keyring_serial_number(id1);
108 print_keyring_serial_number(id2);
112 keyctl_read_key(struct tcb *tcp, key_serial_t id, kernel_ulong_t addr,
113 kernel_ulong_t len, bool has_nul)
116 print_keyring_serial_number(id);
122 kernel_ulong_t rval = (tcp->u_rval >= 0) &&
123 ((kernel_ulong_t) tcp->u_rval > len) ? len :
124 (kernel_ulong_t) tcp->u_rval;
125 printstr_ex(tcp, addr, rval, has_nul ?
126 QUOTE_OMIT_TRAILING_0 : 0);
128 tprintf(", %llu", zero_extend_signed_to_ull(len));
133 keyctl_keyring_search(struct tcb *tcp, key_serial_t id1, kernel_ulong_t addr1,
134 kernel_ulong_t addr2, key_serial_t id2)
136 print_keyring_serial_number(id1);
138 printstr(tcp, addr1);
140 printstr(tcp, addr2);
142 print_keyring_serial_number(id2);
146 keyctl_chown_key(struct tcb *tcp, key_serial_t id, unsigned user,
149 print_keyring_serial_number(id);
150 printuid(", ", user);
151 printuid(", ", group);
155 keyctl_instantiate_key(struct tcb *tcp, key_serial_t id1, kernel_ulong_t addr,
156 kernel_ulong_t len, key_serial_t id2)
158 print_keyring_serial_number(id1);
160 printstrn(tcp, addr, len);
161 tprintf(", %llu, ", zero_extend_signed_to_ull(len));
162 print_keyring_serial_number(id2);
166 keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1,
167 kernel_ulong_t addr, kernel_ulong_t len,
170 print_keyring_serial_number(id1);
172 tprint_iov(tcp, len, addr, IOV_DECODE_STR);
173 tprintf(", %llu, ", zero_extend_signed_to_ull(len));
174 print_keyring_serial_number(id2);
178 keyctl_negate_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
181 print_keyring_serial_number(id1);
182 tprintf(", %u, ", timeout);
183 print_keyring_serial_number(id2);
187 keyctl_reject_key(struct tcb *tcp, key_serial_t id1, unsigned timeout,
188 unsigned error, key_serial_t id2)
190 const char *err_str = err_name(error);
192 print_keyring_serial_number(id1);
193 tprintf(", %u, ", timeout);
196 tprintf("%s, ", err_str);
198 tprintf("%u, ", error);
200 print_keyring_serial_number(id2);
204 keyctl_set_timeout(struct tcb *tcp, key_serial_t id, unsigned timeout)
206 print_keyring_serial_number(id);
207 tprintf(", %u", timeout);
211 keyctl_get_persistent(struct tcb *tcp, unsigned uid, key_serial_t id)
215 print_keyring_serial_number(id);
218 #include "xlat/key_perms.h"
221 keyctl_setperm_key(struct tcb *tcp, key_serial_t id, uint32_t perm)
223 print_keyring_serial_number(id);
225 printflags(key_perms, perm, "KEY_???");
229 print_dh_params(struct tcb *tcp, kernel_ulong_t addr)
231 struct keyctl_dh_params params;
233 if (umove_or_printaddr(tcp, addr, ¶ms))
236 tprints("{private=");
237 print_keyring_serial_number(params.private);
239 print_keyring_serial_number(params.prime);
241 print_keyring_serial_number(params.base);
246 keyctl_dh_compute(struct tcb *tcp, kernel_ulong_t params, kernel_ulong_t buf,
250 print_dh_params(tcp, params);
256 kernel_ulong_t rval = (tcp->u_rval >= 0) &&
257 ((kernel_ulong_t) tcp->u_rval > len) ? len :
258 (kernel_ulong_t) tcp->u_rval;
259 printstrn(tcp, buf, rval);
261 tprintf(", %llu", zero_extend_signed_to_ull(len));
265 #include "xlat/key_reqkeys.h"
266 #include "xlat/keyctl_commands.h"
270 int cmd = tcp->u_arg[0];
271 kernel_ulong_t arg2 = getarg_klu(tcp, 1);
272 kernel_ulong_t arg3 = getarg_klu(tcp, 2);
273 kernel_ulong_t arg4 = getarg_klu(tcp, 3);
274 kernel_ulong_t arg5 = getarg_klu(tcp, 4);
277 printxval(keyctl_commands, cmd, "KEYCTL_???");
280 * For now, KEYCTL_SESSION_TO_PARENT is the only cmd without
283 if (cmd != KEYCTL_SESSION_TO_PARENT)
288 case KEYCTL_GET_KEYRING_ID:
289 keyctl_get_keyring_id(tcp, arg2, arg3);
292 case KEYCTL_JOIN_SESSION_KEYRING:
297 keyctl_update_key(tcp, arg2, arg3, arg4);
302 case KEYCTL_INVALIDATE:
303 case KEYCTL_ASSUME_AUTHORITY:
304 print_keyring_serial_number(arg2);
309 keyctl_handle_key_key(tcp, arg2, arg3);
312 case KEYCTL_DESCRIBE:
314 case KEYCTL_GET_SECURITY:
315 keyctl_read_key(tcp, arg2, arg3, arg4, cmd != KEYCTL_READ);
319 keyctl_keyring_search(tcp, arg2, arg3, arg4, arg5);
323 keyctl_chown_key(tcp, arg2, arg3, arg4);
327 keyctl_setperm_key(tcp, arg2, arg3);
330 case KEYCTL_INSTANTIATE:
331 keyctl_instantiate_key(tcp, arg2, arg3, arg4, arg5);
335 keyctl_negate_key(tcp, arg2, arg3, arg4);
338 case KEYCTL_SET_REQKEY_KEYRING:
339 printxval(key_reqkeys, arg2, "KEY_REQKEY_DEFL_???");
342 case KEYCTL_SET_TIMEOUT:
343 keyctl_set_timeout(tcp, arg2, arg3);
346 case KEYCTL_SESSION_TO_PARENT:
350 keyctl_reject_key(tcp, arg2, arg3, arg4, arg5);
353 case KEYCTL_INSTANTIATE_IOV:
354 keyctl_instantiate_key_iov(tcp, arg2, arg3, arg4, arg5);
357 case KEYCTL_GET_PERSISTENT:
358 keyctl_get_persistent(tcp, arg2, arg3);
361 case KEYCTL_DH_COMPUTE:
362 keyctl_dh_compute(tcp, arg2, arg3, arg4);
366 tprintf("%#" PRI_klx ", %#" PRI_klx
367 ", %#" PRI_klx ", %#" PRI_klx,
368 arg2, arg3, arg4, arg5);