blob: 83ec98b7e98db80ca99b8ce0a86b94e9bf2b2625 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* keyctl.c: userspace keyctl operations
2 *
David Howells3e301482005-06-23 22:00:56 -07003 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/sched.h>
15#include <linux/slab.h>
16#include <linux/syscalls.h>
17#include <linux/keyctl.h>
18#include <linux/fs.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080019#include <linux/capability.h>
Davi Arnaut0cb409d2006-03-24 03:18:43 -080020#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/err.h>
David Howells38bbca62008-04-29 01:01:19 -070022#include <linux/vmalloc.h>
David Howells70a5bb72008-04-29 01:01:26 -070023#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/uaccess.h>
25#include "internal.h"
26
Davi Arnaut0cb409d2006-03-24 03:18:43 -080027static int key_get_type_from_user(char *type,
28 const char __user *_type,
29 unsigned len)
30{
31 int ret;
32
33 ret = strncpy_from_user(type, _type, len);
34
35 if (ret < 0)
Dan Carpenter4303ef12010-06-11 17:30:05 +010036 return ret;
Davi Arnaut0cb409d2006-03-24 03:18:43 -080037
38 if (ret == 0 || ret >= len)
39 return -EINVAL;
40
41 if (type[0] == '.')
42 return -EPERM;
43
44 type[len - 1] = '\0';
45
46 return 0;
47}
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/*
50 * extract the description of a new key from userspace and either add it as a
51 * new key to the specified keyring or update a matching key in that keyring
52 * - the keyring must be writable
53 * - returns the new key's serial number
54 * - implements add_key()
55 */
Heiko Carstens1e7bfb22009-01-14 14:14:29 +010056SYSCALL_DEFINE5(add_key, const char __user *, _type,
57 const char __user *, _description,
58 const void __user *, _payload,
59 size_t, plen,
60 key_serial_t, ringid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
David Howells664cceb2005-09-28 17:03:15 +010062 key_ref_t keyring_ref, key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 char type[32], *description;
64 void *payload;
Davi Arnaut0cb409d2006-03-24 03:18:43 -080065 long ret;
David Howells38bbca62008-04-29 01:01:19 -070066 bool vm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 ret = -EINVAL;
David Howells38bbca62008-04-29 01:01:19 -070069 if (plen > 1024 * 1024 - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 goto error;
71
72 /* draw all the data into kernel space */
Davi Arnaut0cb409d2006-03-24 03:18:43 -080073 ret = key_get_type_from_user(type, _type, sizeof(type));
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if (ret < 0)
75 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Davi Arnaut0cb409d2006-03-24 03:18:43 -080077 description = strndup_user(_description, PAGE_SIZE);
78 if (IS_ERR(description)) {
79 ret = PTR_ERR(description);
David Howells3e301482005-06-23 22:00:56 -070080 goto error;
Davi Arnaut0cb409d2006-03-24 03:18:43 -080081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 /* pull the payload in if one was supplied */
84 payload = NULL;
85
David Howells38bbca62008-04-29 01:01:19 -070086 vm = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (_payload) {
88 ret = -ENOMEM;
89 payload = kmalloc(plen, GFP_KERNEL);
David Howells38bbca62008-04-29 01:01:19 -070090 if (!payload) {
91 if (plen <= PAGE_SIZE)
92 goto error2;
93 vm = true;
94 payload = vmalloc(plen);
95 if (!payload)
96 goto error2;
97 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 ret = -EFAULT;
100 if (copy_from_user(payload, _payload, plen) != 0)
101 goto error3;
102 }
103
104 /* find the target keyring (which must be writable) */
David Howells55931222009-09-02 09:13:45 +0100105 keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100106 if (IS_ERR(keyring_ref)) {
107 ret = PTR_ERR(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 goto error3;
109 }
110
111 /* create or update the requested key and add it to the target
112 * keyring */
David Howells664cceb2005-09-28 17:03:15 +0100113 key_ref = key_create_or_update(keyring_ref, type, description,
Arun Raghavan6b79ccb2008-04-29 01:01:28 -0700114 payload, plen, KEY_PERM_UNDEF,
115 KEY_ALLOC_IN_QUOTA);
David Howells664cceb2005-09-28 17:03:15 +0100116 if (!IS_ERR(key_ref)) {
117 ret = key_ref_to_ptr(key_ref)->serial;
118 key_ref_put(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120 else {
David Howells664cceb2005-09-28 17:03:15 +0100121 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
David Howells664cceb2005-09-28 17:03:15 +0100124 key_ref_put(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 error3:
David Howells38bbca62008-04-29 01:01:19 -0700126 if (!vm)
127 kfree(payload);
128 else
129 vfree(payload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 error2:
131 kfree(description);
132 error:
133 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000134}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/*
137 * search the process keyrings for a matching key
138 * - nested keyrings may also be searched if they have Search permission
139 * - if a key is found, it will be attached to the destination keyring if
140 * there's one specified
141 * - /sbin/request-key will be invoked if _callout_info is non-NULL
142 * - the _callout_info string will be passed to /sbin/request-key
143 * - if the _callout_info string is empty, it will be rendered as "-"
144 * - implements request_key()
145 */
Heiko Carstens1e7bfb22009-01-14 14:14:29 +0100146SYSCALL_DEFINE4(request_key, const char __user *, _type,
147 const char __user *, _description,
148 const char __user *, _callout_info,
149 key_serial_t, destringid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151 struct key_type *ktype;
David Howells664cceb2005-09-28 17:03:15 +0100152 struct key *key;
153 key_ref_t dest_ref;
David Howells4a38e122008-04-29 01:01:24 -0700154 size_t callout_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 char type[32], *description, *callout_info;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800156 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /* pull the type into kernel space */
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800159 ret = key_get_type_from_user(type, _type, sizeof(type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (ret < 0)
161 goto error;
David Howells1260f802005-08-04 11:50:01 +0100162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* pull the description into kernel space */
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800164 description = strndup_user(_description, PAGE_SIZE);
165 if (IS_ERR(description)) {
166 ret = PTR_ERR(description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 goto error;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* pull the callout info into kernel space */
171 callout_info = NULL;
David Howells4a38e122008-04-29 01:01:24 -0700172 callout_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 if (_callout_info) {
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800174 callout_info = strndup_user(_callout_info, PAGE_SIZE);
175 if (IS_ERR(callout_info)) {
176 ret = PTR_ERR(callout_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 goto error2;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800178 }
David Howells4a38e122008-04-29 01:01:24 -0700179 callout_len = strlen(callout_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181
182 /* get the destination keyring if specified */
David Howells664cceb2005-09-28 17:03:15 +0100183 dest_ref = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if (destringid) {
David Howells55931222009-09-02 09:13:45 +0100185 dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,
186 KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100187 if (IS_ERR(dest_ref)) {
188 ret = PTR_ERR(dest_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 goto error3;
190 }
191 }
192
193 /* find the key type */
194 ktype = key_type_lookup(type);
195 if (IS_ERR(ktype)) {
196 ret = PTR_ERR(ktype);
197 goto error4;
198 }
199
200 /* do the search */
David Howells4a38e122008-04-29 01:01:24 -0700201 key = request_key_and_link(ktype, description, callout_info,
202 callout_len, NULL, key_ref_to_ptr(dest_ref),
David Howells7e047ef2006-06-26 00:24:50 -0700203 KEY_ALLOC_IN_QUOTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (IS_ERR(key)) {
205 ret = PTR_ERR(key);
206 goto error5;
207 }
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 ret = key->serial;
210
David Howells3e301482005-06-23 22:00:56 -0700211 key_put(key);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700212error5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 key_type_put(ktype);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700214error4:
David Howells664cceb2005-09-28 17:03:15 +0100215 key_ref_put(dest_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700216error3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 kfree(callout_info);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700218error2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 kfree(description);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700220error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000222}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*
225 * get the ID of the specified process keyring
226 * - the keyring must have search permission to be found
227 * - implements keyctl(KEYCTL_GET_KEYRING_ID)
228 */
229long keyctl_get_keyring_ID(key_serial_t id, int create)
230{
David Howells664cceb2005-09-28 17:03:15 +0100231 key_ref_t key_ref;
David Howells55931222009-09-02 09:13:45 +0100232 unsigned long lflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 long ret;
234
David Howells55931222009-09-02 09:13:45 +0100235 lflags = create ? KEY_LOOKUP_CREATE : 0;
236 key_ref = lookup_user_key(id, lflags, KEY_SEARCH);
David Howells664cceb2005-09-28 17:03:15 +0100237 if (IS_ERR(key_ref)) {
238 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 goto error;
240 }
241
David Howells664cceb2005-09-28 17:03:15 +0100242 ret = key_ref_to_ptr(key_ref)->serial;
243 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700244error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return ret;
246
247} /* end keyctl_get_keyring_ID() */
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249/*
250 * join the session keyring
251 * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING)
252 */
253long keyctl_join_session_keyring(const char __user *_name)
254{
255 char *name;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800256 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 /* fetch the name from userspace */
259 name = NULL;
260 if (_name) {
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800261 name = strndup_user(_name, PAGE_SIZE);
262 if (IS_ERR(name)) {
263 ret = PTR_ERR(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 goto error;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267
268 /* join the session */
269 ret = join_session_keyring(name);
Vegard Nossum0d54ee12009-01-17 17:45:45 +0100270 kfree(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700272error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000274}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
277 * update a key's data payload
278 * - the key must be writable
279 * - implements keyctl(KEYCTL_UPDATE)
280 */
281long keyctl_update_key(key_serial_t id,
282 const void __user *_payload,
283 size_t plen)
284{
David Howells664cceb2005-09-28 17:03:15 +0100285 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 void *payload;
287 long ret;
288
289 ret = -EINVAL;
290 if (plen > PAGE_SIZE)
291 goto error;
292
293 /* pull the payload in if one was supplied */
294 payload = NULL;
295 if (_payload) {
296 ret = -ENOMEM;
297 payload = kmalloc(plen, GFP_KERNEL);
298 if (!payload)
299 goto error;
300
301 ret = -EFAULT;
302 if (copy_from_user(payload, _payload, plen) != 0)
303 goto error2;
304 }
305
306 /* find the target key (which must be writable) */
David Howells55931222009-09-02 09:13:45 +0100307 key_ref = lookup_user_key(id, 0, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100308 if (IS_ERR(key_ref)) {
309 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 goto error2;
311 }
312
313 /* update the key */
David Howells664cceb2005-09-28 17:03:15 +0100314 ret = key_update(key_ref, payload, plen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
David Howells664cceb2005-09-28 17:03:15 +0100316 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700317error2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 kfree(payload);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700319error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000321}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/*
324 * revoke a key
325 * - the key must be writable
326 * - implements keyctl(KEYCTL_REVOKE)
327 */
328long keyctl_revoke_key(key_serial_t id)
329{
David Howells664cceb2005-09-28 17:03:15 +0100330 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 long ret;
332
David Howells55931222009-09-02 09:13:45 +0100333 key_ref = lookup_user_key(id, 0, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100334 if (IS_ERR(key_ref)) {
335 ret = PTR_ERR(key_ref);
David Howells0c2c9a32009-09-02 09:13:50 +0100336 if (ret != -EACCES)
337 goto error;
338 key_ref = lookup_user_key(id, 0, KEY_SETATTR);
339 if (IS_ERR(key_ref)) {
340 ret = PTR_ERR(key_ref);
341 goto error;
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344
David Howells664cceb2005-09-28 17:03:15 +0100345 key_revoke(key_ref_to_ptr(key_ref));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ret = 0;
347
David Howells664cceb2005-09-28 17:03:15 +0100348 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700349error:
David Howells1260f802005-08-04 11:50:01 +0100350 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000351}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/*
354 * clear the specified process keyring
355 * - the keyring must be writable
356 * - implements keyctl(KEYCTL_CLEAR)
357 */
358long keyctl_keyring_clear(key_serial_t ringid)
359{
David Howells664cceb2005-09-28 17:03:15 +0100360 key_ref_t keyring_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 long ret;
362
David Howells55931222009-09-02 09:13:45 +0100363 keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100364 if (IS_ERR(keyring_ref)) {
365 ret = PTR_ERR(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 goto error;
367 }
368
David Howells664cceb2005-09-28 17:03:15 +0100369 ret = keyring_clear(key_ref_to_ptr(keyring_ref));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
David Howells664cceb2005-09-28 17:03:15 +0100371 key_ref_put(keyring_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700372error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000374}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/*
377 * link a key into a keyring
378 * - the keyring must be writable
379 * - the key must be linkable
380 * - implements keyctl(KEYCTL_LINK)
381 */
382long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
383{
David Howells664cceb2005-09-28 17:03:15 +0100384 key_ref_t keyring_ref, key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 long ret;
386
David Howells55931222009-09-02 09:13:45 +0100387 keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100388 if (IS_ERR(keyring_ref)) {
389 ret = PTR_ERR(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 goto error;
391 }
392
David Howells55931222009-09-02 09:13:45 +0100393 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE, KEY_LINK);
David Howells664cceb2005-09-28 17:03:15 +0100394 if (IS_ERR(key_ref)) {
395 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 goto error2;
397 }
398
David Howells664cceb2005-09-28 17:03:15 +0100399 ret = key_link(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
David Howells664cceb2005-09-28 17:03:15 +0100401 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700402error2:
David Howells664cceb2005-09-28 17:03:15 +0100403 key_ref_put(keyring_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700404error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000406}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408/*
409 * unlink the first attachment of a key from a keyring
410 * - the keyring must be writable
411 * - we don't need any permissions on the key
412 * - implements keyctl(KEYCTL_UNLINK)
413 */
414long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
415{
David Howells664cceb2005-09-28 17:03:15 +0100416 key_ref_t keyring_ref, key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 long ret;
418
David Howells55931222009-09-02 09:13:45 +0100419 keyring_ref = lookup_user_key(ringid, 0, KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100420 if (IS_ERR(keyring_ref)) {
421 ret = PTR_ERR(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 goto error;
423 }
424
David Howells55931222009-09-02 09:13:45 +0100425 key_ref = lookup_user_key(id, KEY_LOOKUP_FOR_UNLINK, 0);
David Howells664cceb2005-09-28 17:03:15 +0100426 if (IS_ERR(key_ref)) {
427 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 goto error2;
429 }
430
David Howells664cceb2005-09-28 17:03:15 +0100431 ret = key_unlink(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
David Howells664cceb2005-09-28 17:03:15 +0100433 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700434error2:
David Howells664cceb2005-09-28 17:03:15 +0100435 key_ref_put(keyring_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700436error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000438}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*
441 * describe a user key
442 * - the key must have view permission
443 * - if there's a buffer, we place up to buflen bytes of data into it
444 * - unless there's an error, we return the amount of description available,
445 * irrespective of how much we may have copied
446 * - the description is formatted thus:
447 * type;uid;gid;perm;description<NUL>
448 * - implements keyctl(KEYCTL_DESCRIBE)
449 */
450long keyctl_describe_key(key_serial_t keyid,
451 char __user *buffer,
452 size_t buflen)
453{
David Howells3e301482005-06-23 22:00:56 -0700454 struct key *key, *instkey;
David Howells664cceb2005-09-28 17:03:15 +0100455 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 char *tmpbuf;
457 long ret;
458
David Howells55931222009-09-02 09:13:45 +0100459 key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);
David Howells664cceb2005-09-28 17:03:15 +0100460 if (IS_ERR(key_ref)) {
David Howells3e301482005-06-23 22:00:56 -0700461 /* viewing a key under construction is permitted if we have the
462 * authorisation token handy */
David Howells664cceb2005-09-28 17:03:15 +0100463 if (PTR_ERR(key_ref) == -EACCES) {
David Howells3e301482005-06-23 22:00:56 -0700464 instkey = key_get_instantiation_authkey(keyid);
465 if (!IS_ERR(instkey)) {
466 key_put(instkey);
David Howells8bbf49762008-11-14 10:39:14 +1100467 key_ref = lookup_user_key(keyid,
David Howells55931222009-09-02 09:13:45 +0100468 KEY_LOOKUP_PARTIAL,
469 0);
David Howells664cceb2005-09-28 17:03:15 +0100470 if (!IS_ERR(key_ref))
David Howells3e301482005-06-23 22:00:56 -0700471 goto okay;
472 }
473 }
474
David Howells664cceb2005-09-28 17:03:15 +0100475 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 goto error;
477 }
478
David Howells3e301482005-06-23 22:00:56 -0700479okay:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* calculate how much description we're going to return */
481 ret = -ENOMEM;
482 tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
483 if (!tmpbuf)
484 goto error2;
485
David Howells664cceb2005-09-28 17:03:15 +0100486 key = key_ref_to_ptr(key_ref);
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 ret = snprintf(tmpbuf, PAGE_SIZE - 1,
David Howells664cceb2005-09-28 17:03:15 +0100489 "%s;%d;%d;%08x;%s",
David Howells94fd8402010-06-28 14:05:04 +0100490 key->type->name,
491 key->uid,
492 key->gid,
493 key->perm,
494 key->description ?: "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 /* include a NUL char at the end of the data */
497 if (ret > PAGE_SIZE - 1)
498 ret = PAGE_SIZE - 1;
499 tmpbuf[ret] = 0;
500 ret++;
501
502 /* consider returning the data */
503 if (buffer && buflen > 0) {
504 if (buflen > ret)
505 buflen = ret;
506
507 if (copy_to_user(buffer, tmpbuf, buflen) != 0)
508 ret = -EFAULT;
509 }
510
511 kfree(tmpbuf);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700512error2:
David Howells664cceb2005-09-28 17:03:15 +0100513 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700514error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000516}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518/*
519 * search the specified keyring for a matching key
520 * - the start keyring must be searchable
521 * - nested keyrings may also be searched if they are searchable
522 * - only keys with search permission may be found
523 * - if a key is found, it will be attached to the destination keyring if
524 * there's one specified
525 * - implements keyctl(KEYCTL_SEARCH)
526 */
527long keyctl_keyring_search(key_serial_t ringid,
528 const char __user *_type,
529 const char __user *_description,
530 key_serial_t destringid)
531{
532 struct key_type *ktype;
David Howells664cceb2005-09-28 17:03:15 +0100533 key_ref_t keyring_ref, key_ref, dest_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 char type[32], *description;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800535 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 /* pull the type and description into kernel space */
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800538 ret = key_get_type_from_user(type, _type, sizeof(type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (ret < 0)
540 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800542 description = strndup_user(_description, PAGE_SIZE);
543 if (IS_ERR(description)) {
544 ret = PTR_ERR(description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 goto error;
Davi Arnaut0cb409d2006-03-24 03:18:43 -0800546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* get the keyring at which to begin the search */
David Howells55931222009-09-02 09:13:45 +0100549 keyring_ref = lookup_user_key(ringid, 0, KEY_SEARCH);
David Howells664cceb2005-09-28 17:03:15 +0100550 if (IS_ERR(keyring_ref)) {
551 ret = PTR_ERR(keyring_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 goto error2;
553 }
554
555 /* get the destination keyring if specified */
David Howells664cceb2005-09-28 17:03:15 +0100556 dest_ref = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 if (destringid) {
David Howells55931222009-09-02 09:13:45 +0100558 dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,
559 KEY_WRITE);
David Howells664cceb2005-09-28 17:03:15 +0100560 if (IS_ERR(dest_ref)) {
561 ret = PTR_ERR(dest_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 goto error3;
563 }
564 }
565
566 /* find the key type */
567 ktype = key_type_lookup(type);
568 if (IS_ERR(ktype)) {
569 ret = PTR_ERR(ktype);
570 goto error4;
571 }
572
573 /* do the search */
David Howells664cceb2005-09-28 17:03:15 +0100574 key_ref = keyring_search(keyring_ref, ktype, description);
575 if (IS_ERR(key_ref)) {
576 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /* treat lack or presence of a negative key the same */
579 if (ret == -EAGAIN)
580 ret = -ENOKEY;
581 goto error5;
582 }
583
584 /* link the resulting key to the destination keyring if we can */
David Howells664cceb2005-09-28 17:03:15 +0100585 if (dest_ref) {
David Howells29db9192005-10-30 15:02:44 -0800586 ret = key_permission(key_ref, KEY_LINK);
587 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 goto error6;
589
David Howells664cceb2005-09-28 17:03:15 +0100590 ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (ret < 0)
592 goto error6;
593 }
594
David Howells664cceb2005-09-28 17:03:15 +0100595 ret = key_ref_to_ptr(key_ref)->serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700597error6:
David Howells664cceb2005-09-28 17:03:15 +0100598 key_ref_put(key_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700599error5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 key_type_put(ktype);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700601error4:
David Howells664cceb2005-09-28 17:03:15 +0100602 key_ref_put(dest_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700603error3:
David Howells664cceb2005-09-28 17:03:15 +0100604 key_ref_put(keyring_ref);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700605error2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 kfree(description);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700607error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000609}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 * read a user key's payload
613 * - the keyring must be readable or the key must be searchable from the
614 * process's keyrings
615 * - if there's a buffer, we place up to buflen bytes of data into it
616 * - unless there's an error, we return the amount of data in the key,
617 * irrespective of how much we may have copied
618 * - implements keyctl(KEYCTL_READ)
619 */
620long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
621{
David Howells664cceb2005-09-28 17:03:15 +0100622 struct key *key;
623 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 long ret;
625
626 /* find the key first */
David Howells55931222009-09-02 09:13:45 +0100627 key_ref = lookup_user_key(keyid, 0, 0);
David Howells664cceb2005-09-28 17:03:15 +0100628 if (IS_ERR(key_ref)) {
629 ret = -ENOKEY;
630 goto error;
631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
David Howells664cceb2005-09-28 17:03:15 +0100633 key = key_ref_to_ptr(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
David Howells664cceb2005-09-28 17:03:15 +0100635 /* see if we can read it directly */
David Howells29db9192005-10-30 15:02:44 -0800636 ret = key_permission(key_ref, KEY_READ);
637 if (ret == 0)
David Howells664cceb2005-09-28 17:03:15 +0100638 goto can_read_key;
David Howells29db9192005-10-30 15:02:44 -0800639 if (ret != -EACCES)
640 goto error;
David Howells664cceb2005-09-28 17:03:15 +0100641
642 /* we can't; see if it's searchable from this process's keyrings
643 * - we automatically take account of the fact that it may be
644 * dangling off an instantiation key
645 */
646 if (!is_key_possessed(key_ref)) {
647 ret = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 goto error2;
649 }
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* the key is probably readable - now try to read it */
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700652can_read_key:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 ret = key_validate(key);
654 if (ret == 0) {
655 ret = -EOPNOTSUPP;
656 if (key->type->read) {
657 /* read the data with the semaphore held (since we
658 * might sleep) */
659 down_read(&key->sem);
660 ret = key->type->read(key, buffer, buflen);
661 up_read(&key->sem);
662 }
663 }
664
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700665error2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 key_put(key);
Justin P. Mattockc5b60b52010-04-21 00:02:11 -0700667error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000669}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671/*
672 * change the ownership of a key
673 * - the keyring owned by the changer
674 * - if the uid or gid is -1, then that parameter is not changed
675 * - implements keyctl(KEYCTL_CHOWN)
676 */
677long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
678{
Fredrik Tolf58016492006-06-26 00:24:51 -0700679 struct key_user *newowner, *zapowner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 struct key *key;
David Howells664cceb2005-09-28 17:03:15 +0100681 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 long ret;
683
684 ret = 0;
685 if (uid == (uid_t) -1 && gid == (gid_t) -1)
686 goto error;
687
David Howells55931222009-09-02 09:13:45 +0100688 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
689 KEY_SETATTR);
David Howells664cceb2005-09-28 17:03:15 +0100690 if (IS_ERR(key_ref)) {
691 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 goto error;
693 }
694
David Howells664cceb2005-09-28 17:03:15 +0100695 key = key_ref_to_ptr(key_ref);
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* make the changes with the locks held to prevent chown/chown races */
698 ret = -EACCES;
699 down_write(&key->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 if (!capable(CAP_SYS_ADMIN)) {
702 /* only the sysadmin can chown a key to some other UID */
703 if (uid != (uid_t) -1 && key->uid != uid)
Fredrik Tolf58016492006-06-26 00:24:51 -0700704 goto error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 /* only the sysadmin can set the key's GID to a group other
707 * than one of those that the current process subscribes to */
708 if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid))
Fredrik Tolf58016492006-06-26 00:24:51 -0700709 goto error_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
711
Fredrik Tolf58016492006-06-26 00:24:51 -0700712 /* change the UID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (uid != (uid_t) -1 && uid != key->uid) {
Fredrik Tolf58016492006-06-26 00:24:51 -0700714 ret = -ENOMEM;
Serge E. Hallyn1d1e9752009-02-26 18:27:38 -0600715 newowner = key_user_lookup(uid, current_user_ns());
Fredrik Tolf58016492006-06-26 00:24:51 -0700716 if (!newowner)
717 goto error_put;
718
719 /* transfer the quota burden to the new user */
720 if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) {
David Howells0b77f5b2008-04-29 01:01:32 -0700721 unsigned maxkeys = (uid == 0) ?
722 key_quota_root_maxkeys : key_quota_maxkeys;
723 unsigned maxbytes = (uid == 0) ?
724 key_quota_root_maxbytes : key_quota_maxbytes;
725
Fredrik Tolf58016492006-06-26 00:24:51 -0700726 spin_lock(&newowner->lock);
David Howells0b77f5b2008-04-29 01:01:32 -0700727 if (newowner->qnkeys + 1 >= maxkeys ||
728 newowner->qnbytes + key->quotalen >= maxbytes ||
729 newowner->qnbytes + key->quotalen <
730 newowner->qnbytes)
Fredrik Tolf58016492006-06-26 00:24:51 -0700731 goto quota_overrun;
732
733 newowner->qnkeys++;
734 newowner->qnbytes += key->quotalen;
735 spin_unlock(&newowner->lock);
736
737 spin_lock(&key->user->lock);
738 key->user->qnkeys--;
739 key->user->qnbytes -= key->quotalen;
740 spin_unlock(&key->user->lock);
741 }
742
743 atomic_dec(&key->user->nkeys);
744 atomic_inc(&newowner->nkeys);
745
746 if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
747 atomic_dec(&key->user->nikeys);
748 atomic_inc(&newowner->nikeys);
749 }
750
751 zapowner = key->user;
752 key->user = newowner;
753 key->uid = uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755
756 /* change the GID */
757 if (gid != (gid_t) -1)
758 key->gid = gid;
759
760 ret = 0;
761
Fredrik Tolf58016492006-06-26 00:24:51 -0700762error_put:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 up_write(&key->sem);
764 key_put(key);
Fredrik Tolf58016492006-06-26 00:24:51 -0700765 if (zapowner)
766 key_user_put(zapowner);
767error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 return ret;
769
Fredrik Tolf58016492006-06-26 00:24:51 -0700770quota_overrun:
771 spin_unlock(&newowner->lock);
772 zapowner = newowner;
773 ret = -EDQUOT;
774 goto error_put;
David Howellsa8b17ed2011-01-20 16:38:27 +0000775}
Fredrik Tolf58016492006-06-26 00:24:51 -0700776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777/*
778 * change the permission mask on a key
779 * - the keyring owned by the changer
780 * - implements keyctl(KEYCTL_SETPERM)
781 */
782long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
783{
784 struct key *key;
David Howells664cceb2005-09-28 17:03:15 +0100785 key_ref_t key_ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 long ret;
787
788 ret = -EINVAL;
David Howells664cceb2005-09-28 17:03:15 +0100789 if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 goto error;
791
David Howells55931222009-09-02 09:13:45 +0100792 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
793 KEY_SETATTR);
David Howells664cceb2005-09-28 17:03:15 +0100794 if (IS_ERR(key_ref)) {
795 ret = PTR_ERR(key_ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 goto error;
797 }
798
David Howells664cceb2005-09-28 17:03:15 +0100799 key = key_ref_to_ptr(key_ref);
800
David Howells76d8aea2005-06-23 22:00:49 -0700801 /* make the changes with the locks held to prevent chown/chmod races */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 ret = -EACCES;
803 down_write(&key->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
David Howells76d8aea2005-06-23 22:00:49 -0700805 /* if we're not the sysadmin, we can only change a key that we own */
David Howells47d804b2008-11-14 10:39:11 +1100806 if (capable(CAP_SYS_ADMIN) || key->uid == current_fsuid()) {
David Howells76d8aea2005-06-23 22:00:49 -0700807 key->perm = perm;
808 ret = 0;
809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 up_write(&key->sem);
812 key_put(key);
David Howells76d8aea2005-06-23 22:00:49 -0700813error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000815}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
David Howells8bbf49762008-11-14 10:39:14 +1100817/*
818 * get the destination keyring for instantiation
819 */
820static long get_instantiation_keyring(key_serial_t ringid,
821 struct request_key_auth *rka,
822 struct key **_dest_keyring)
823{
824 key_ref_t dkref;
825
David Howellseca1bf52008-12-29 00:41:51 +0000826 *_dest_keyring = NULL;
827
David Howells8bbf49762008-11-14 10:39:14 +1100828 /* just return a NULL pointer if we weren't asked to make a link */
David Howellseca1bf52008-12-29 00:41:51 +0000829 if (ringid == 0)
David Howells8bbf49762008-11-14 10:39:14 +1100830 return 0;
David Howells8bbf49762008-11-14 10:39:14 +1100831
832 /* if a specific keyring is nominated by ID, then use that */
833 if (ringid > 0) {
David Howells55931222009-09-02 09:13:45 +0100834 dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
David Howells8bbf49762008-11-14 10:39:14 +1100835 if (IS_ERR(dkref))
836 return PTR_ERR(dkref);
837 *_dest_keyring = key_ref_to_ptr(dkref);
838 return 0;
839 }
840
841 if (ringid == KEY_SPEC_REQKEY_AUTH_KEY)
842 return -EINVAL;
843
844 /* otherwise specify the destination keyring recorded in the
845 * authorisation key (any KEY_SPEC_*_KEYRING) */
846 if (ringid >= KEY_SPEC_REQUESTOR_KEYRING) {
David Howells21279cf2009-10-15 10:14:35 +0100847 *_dest_keyring = key_get(rka->dest_keyring);
David Howells8bbf49762008-11-14 10:39:14 +1100848 return 0;
849 }
850
851 return -ENOKEY;
852}
853
David Howellsd84f4f92008-11-14 10:39:23 +1100854/*
855 * change the request_key authorisation key on the current process
856 */
857static int keyctl_change_reqkey_auth(struct key *key)
858{
859 struct cred *new;
860
861 new = prepare_creds();
862 if (!new)
863 return -ENOMEM;
864
865 key_put(new->request_key_auth);
866 new->request_key_auth = key_get(key);
867
868 return commit_creds(new);
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*
872 * instantiate the key with the specified payload, and, if one is given, link
873 * the key into the keyring
874 */
875long keyctl_instantiate_key(key_serial_t id,
876 const void __user *_payload,
877 size_t plen,
878 key_serial_t ringid)
879{
David Howellsd84f4f92008-11-14 10:39:23 +1100880 const struct cred *cred = current_cred();
David Howells3e301482005-06-23 22:00:56 -0700881 struct request_key_auth *rka;
David Howells8bbf49762008-11-14 10:39:14 +1100882 struct key *instkey, *dest_keyring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 void *payload;
884 long ret;
David Howells38bbca62008-04-29 01:01:19 -0700885 bool vm = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
David Howellsd84f4f92008-11-14 10:39:23 +1100887 kenter("%d,,%zu,%d", id, plen, ringid);
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 ret = -EINVAL;
David Howells38bbca62008-04-29 01:01:19 -0700890 if (plen > 1024 * 1024 - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 goto error;
892
David Howellsb5f545c2006-01-08 01:02:47 -0800893 /* the appropriate instantiation authorisation key must have been
894 * assumed before calling this */
895 ret = -EPERM;
David Howellsd84f4f92008-11-14 10:39:23 +1100896 instkey = cred->request_key_auth;
David Howellsb5f545c2006-01-08 01:02:47 -0800897 if (!instkey)
898 goto error;
899
900 rka = instkey->payload.data;
901 if (rka->target_key->serial != id)
902 goto error;
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 /* pull the payload in if one was supplied */
905 payload = NULL;
906
907 if (_payload) {
908 ret = -ENOMEM;
909 payload = kmalloc(plen, GFP_KERNEL);
David Howells38bbca62008-04-29 01:01:19 -0700910 if (!payload) {
911 if (plen <= PAGE_SIZE)
912 goto error;
913 vm = true;
914 payload = vmalloc(plen);
915 if (!payload)
916 goto error;
917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 ret = -EFAULT;
920 if (copy_from_user(payload, _payload, plen) != 0)
921 goto error2;
922 }
923
David Howells3e301482005-06-23 22:00:56 -0700924 /* find the destination keyring amongst those belonging to the
925 * requesting task */
David Howells8bbf49762008-11-14 10:39:14 +1100926 ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
927 if (ret < 0)
928 goto error2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 /* instantiate the key and link it into a keyring */
David Howells3e301482005-06-23 22:00:56 -0700931 ret = key_instantiate_and_link(rka->target_key, payload, plen,
David Howells8bbf49762008-11-14 10:39:14 +1100932 dest_keyring, instkey);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
David Howells8bbf49762008-11-14 10:39:14 +1100934 key_put(dest_keyring);
David Howellsb5f545c2006-01-08 01:02:47 -0800935
936 /* discard the assumed authority if it's just been disabled by
937 * instantiation of the key */
David Howellsd84f4f92008-11-14 10:39:23 +1100938 if (ret == 0)
939 keyctl_change_reqkey_auth(NULL);
David Howellsb5f545c2006-01-08 01:02:47 -0800940
941error2:
David Howells38bbca62008-04-29 01:01:19 -0700942 if (!vm)
943 kfree(payload);
944 else
945 vfree(payload);
David Howellsb5f545c2006-01-08 01:02:47 -0800946error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000948}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950/*
951 * negatively instantiate the key with the given timeout (in seconds), and, if
952 * one is given, link the key into the keyring
953 */
954long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
955{
David Howellsd84f4f92008-11-14 10:39:23 +1100956 const struct cred *cred = current_cred();
David Howells3e301482005-06-23 22:00:56 -0700957 struct request_key_auth *rka;
David Howells8bbf49762008-11-14 10:39:14 +1100958 struct key *instkey, *dest_keyring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 long ret;
960
David Howellsd84f4f92008-11-14 10:39:23 +1100961 kenter("%d,%u,%d", id, timeout, ringid);
962
David Howellsb5f545c2006-01-08 01:02:47 -0800963 /* the appropriate instantiation authorisation key must have been
964 * assumed before calling this */
965 ret = -EPERM;
David Howellsd84f4f92008-11-14 10:39:23 +1100966 instkey = cred->request_key_auth;
David Howellsb5f545c2006-01-08 01:02:47 -0800967 if (!instkey)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
David Howells3e301482005-06-23 22:00:56 -0700970 rka = instkey->payload.data;
David Howellsb5f545c2006-01-08 01:02:47 -0800971 if (rka->target_key->serial != id)
972 goto error;
David Howells3e301482005-06-23 22:00:56 -0700973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* find the destination keyring if present (which must also be
975 * writable) */
David Howells8bbf49762008-11-14 10:39:14 +1100976 ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
977 if (ret < 0)
978 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 /* instantiate the key and link it into a keyring */
David Howells664cceb2005-09-28 17:03:15 +0100981 ret = key_negate_and_link(rka->target_key, timeout,
David Howells8bbf49762008-11-14 10:39:14 +1100982 dest_keyring, instkey);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
David Howells8bbf49762008-11-14 10:39:14 +1100984 key_put(dest_keyring);
David Howellsb5f545c2006-01-08 01:02:47 -0800985
986 /* discard the assumed authority if it's just been disabled by
987 * instantiation of the key */
David Howellsd84f4f92008-11-14 10:39:23 +1100988 if (ret == 0)
989 keyctl_change_reqkey_auth(NULL);
David Howellsb5f545c2006-01-08 01:02:47 -0800990
991error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +0000993}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995/*
David Howells3e301482005-06-23 22:00:56 -0700996 * set the default keyring in which request_key() will cache keys
997 * - return the old setting
998 */
999long keyctl_set_reqkey_keyring(int reqkey_defl)
1000{
David Howellsd84f4f92008-11-14 10:39:23 +11001001 struct cred *new;
1002 int ret, old_setting;
1003
1004 old_setting = current_cred_xxx(jit_keyring);
1005
1006 if (reqkey_defl == KEY_REQKEY_DEFL_NO_CHANGE)
1007 return old_setting;
1008
1009 new = prepare_creds();
1010 if (!new)
1011 return -ENOMEM;
David Howells3e301482005-06-23 22:00:56 -07001012
1013 switch (reqkey_defl) {
1014 case KEY_REQKEY_DEFL_THREAD_KEYRING:
David Howellsd84f4f92008-11-14 10:39:23 +11001015 ret = install_thread_keyring_to_cred(new);
David Howells3e301482005-06-23 22:00:56 -07001016 if (ret < 0)
David Howellsd84f4f92008-11-14 10:39:23 +11001017 goto error;
David Howells3e301482005-06-23 22:00:56 -07001018 goto set;
1019
1020 case KEY_REQKEY_DEFL_PROCESS_KEYRING:
David Howellsd84f4f92008-11-14 10:39:23 +11001021 ret = install_process_keyring_to_cred(new);
1022 if (ret < 0) {
1023 if (ret != -EEXIST)
1024 goto error;
1025 ret = 0;
1026 }
1027 goto set;
David Howells3e301482005-06-23 22:00:56 -07001028
1029 case KEY_REQKEY_DEFL_DEFAULT:
1030 case KEY_REQKEY_DEFL_SESSION_KEYRING:
1031 case KEY_REQKEY_DEFL_USER_KEYRING:
1032 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
David Howellsd84f4f92008-11-14 10:39:23 +11001033 case KEY_REQKEY_DEFL_REQUESTOR_KEYRING:
1034 goto set;
David Howells3e301482005-06-23 22:00:56 -07001035
1036 case KEY_REQKEY_DEFL_NO_CHANGE:
David Howells3e301482005-06-23 22:00:56 -07001037 case KEY_REQKEY_DEFL_GROUP_KEYRING:
1038 default:
David Howellsd84f4f92008-11-14 10:39:23 +11001039 ret = -EINVAL;
1040 goto error;
David Howells3e301482005-06-23 22:00:56 -07001041 }
1042
David Howellsd84f4f92008-11-14 10:39:23 +11001043set:
1044 new->jit_keyring = reqkey_defl;
1045 commit_creds(new);
1046 return old_setting;
1047error:
1048 abort_creds(new);
Dan Carpenter4303ef12010-06-11 17:30:05 +01001049 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +00001050}
David Howellsd84f4f92008-11-14 10:39:23 +11001051
David Howells3e301482005-06-23 22:00:56 -07001052/*
David Howells017679c2006-01-08 01:02:43 -08001053 * set or clear the timeout for a key
1054 */
1055long keyctl_set_timeout(key_serial_t id, unsigned timeout)
1056{
1057 struct timespec now;
David Howells91562352010-06-11 17:31:05 +01001058 struct key *key, *instkey;
David Howells017679c2006-01-08 01:02:43 -08001059 key_ref_t key_ref;
1060 time_t expiry;
1061 long ret;
1062
David Howells55931222009-09-02 09:13:45 +01001063 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
1064 KEY_SETATTR);
David Howells017679c2006-01-08 01:02:43 -08001065 if (IS_ERR(key_ref)) {
David Howells91562352010-06-11 17:31:05 +01001066 /* setting the timeout on a key under construction is permitted
1067 * if we have the authorisation token handy */
1068 if (PTR_ERR(key_ref) == -EACCES) {
1069 instkey = key_get_instantiation_authkey(id);
1070 if (!IS_ERR(instkey)) {
1071 key_put(instkey);
1072 key_ref = lookup_user_key(id,
1073 KEY_LOOKUP_PARTIAL,
1074 0);
1075 if (!IS_ERR(key_ref))
1076 goto okay;
1077 }
1078 }
1079
David Howells017679c2006-01-08 01:02:43 -08001080 ret = PTR_ERR(key_ref);
1081 goto error;
1082 }
1083
David Howells91562352010-06-11 17:31:05 +01001084okay:
David Howells017679c2006-01-08 01:02:43 -08001085 key = key_ref_to_ptr(key_ref);
1086
1087 /* make the changes with the locks held to prevent races */
1088 down_write(&key->sem);
1089
1090 expiry = 0;
1091 if (timeout > 0) {
1092 now = current_kernel_time();
1093 expiry = now.tv_sec + timeout;
1094 }
1095
1096 key->expiry = expiry;
David Howellsc08ef802009-09-14 17:26:13 +01001097 key_schedule_gc(key->expiry + key_gc_delay);
David Howells017679c2006-01-08 01:02:43 -08001098
1099 up_write(&key->sem);
1100 key_put(key);
1101
1102 ret = 0;
1103error:
1104 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +00001105}
David Howells017679c2006-01-08 01:02:43 -08001106
David Howells017679c2006-01-08 01:02:43 -08001107/*
David Howellsb5f545c2006-01-08 01:02:47 -08001108 * assume the authority to instantiate the specified key
1109 */
1110long keyctl_assume_authority(key_serial_t id)
1111{
1112 struct key *authkey;
1113 long ret;
1114
1115 /* special key IDs aren't permitted */
1116 ret = -EINVAL;
1117 if (id < 0)
1118 goto error;
1119
1120 /* we divest ourselves of authority if given an ID of 0 */
1121 if (id == 0) {
David Howellsd84f4f92008-11-14 10:39:23 +11001122 ret = keyctl_change_reqkey_auth(NULL);
David Howellsb5f545c2006-01-08 01:02:47 -08001123 goto error;
1124 }
1125
1126 /* attempt to assume the authority temporarily granted to us whilst we
1127 * instantiate the specified key
1128 * - the authorisation key must be in the current task's keyrings
1129 * somewhere
1130 */
1131 authkey = key_get_instantiation_authkey(id);
1132 if (IS_ERR(authkey)) {
1133 ret = PTR_ERR(authkey);
1134 goto error;
1135 }
1136
David Howellsd84f4f92008-11-14 10:39:23 +11001137 ret = keyctl_change_reqkey_auth(authkey);
1138 if (ret < 0)
1139 goto error;
1140 key_put(authkey);
David Howellsb5f545c2006-01-08 01:02:47 -08001141
David Howellsd84f4f92008-11-14 10:39:23 +11001142 ret = authkey->serial;
David Howellsb5f545c2006-01-08 01:02:47 -08001143error:
1144 return ret;
David Howellsa8b17ed2011-01-20 16:38:27 +00001145}
David Howellsb5f545c2006-01-08 01:02:47 -08001146
David Howells70a5bb72008-04-29 01:01:26 -07001147/*
1148 * get the security label of a key
1149 * - the key must grant us view permission
1150 * - if there's a buffer, we place up to buflen bytes of data into it
1151 * - unless there's an error, we return the amount of information available,
1152 * irrespective of how much we may have copied (including the terminal NUL)
1153 * - implements keyctl(KEYCTL_GET_SECURITY)
1154 */
1155long keyctl_get_security(key_serial_t keyid,
1156 char __user *buffer,
1157 size_t buflen)
1158{
1159 struct key *key, *instkey;
1160 key_ref_t key_ref;
1161 char *context;
1162 long ret;
1163
David Howells55931222009-09-02 09:13:45 +01001164 key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);
David Howells70a5bb72008-04-29 01:01:26 -07001165 if (IS_ERR(key_ref)) {
1166 if (PTR_ERR(key_ref) != -EACCES)
1167 return PTR_ERR(key_ref);
1168
1169 /* viewing a key under construction is also permitted if we
1170 * have the authorisation token handy */
1171 instkey = key_get_instantiation_authkey(keyid);
1172 if (IS_ERR(instkey))
Roel Kluinfa1cc7b2009-12-15 15:05:12 -08001173 return PTR_ERR(instkey);
David Howells70a5bb72008-04-29 01:01:26 -07001174 key_put(instkey);
1175
David Howells55931222009-09-02 09:13:45 +01001176 key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, 0);
David Howells70a5bb72008-04-29 01:01:26 -07001177 if (IS_ERR(key_ref))
1178 return PTR_ERR(key_ref);
1179 }
1180
1181 key = key_ref_to_ptr(key_ref);
1182 ret = security_key_getsecurity(key, &context);
1183 if (ret == 0) {
1184 /* if no information was returned, give userspace an empty
1185 * string */
1186 ret = 1;
1187 if (buffer && buflen > 0 &&
1188 copy_to_user(buffer, "", 1) != 0)
1189 ret = -EFAULT;
1190 } else if (ret > 0) {
1191 /* return as much data as there's room for */
1192 if (buffer && buflen > 0) {
1193 if (buflen > ret)
1194 buflen = ret;
1195
1196 if (copy_to_user(buffer, context, buflen) != 0)
1197 ret = -EFAULT;
1198 }
1199
1200 kfree(context);
1201 }
1202
1203 key_ref_put(key_ref);
1204 return ret;
1205}
1206
David Howellsee18d642009-09-02 09:14:21 +01001207/*
1208 * attempt to install the calling process's session keyring on the process's
1209 * parent process
1210 * - the keyring must exist and must grant us LINK permission
1211 * - implements keyctl(KEYCTL_SESSION_TO_PARENT)
1212 */
1213long keyctl_session_to_parent(void)
1214{
Geert Uytterhoevena00ae4d2009-12-13 20:21:34 +01001215#ifdef TIF_NOTIFY_RESUME
David Howellsee18d642009-09-02 09:14:21 +01001216 struct task_struct *me, *parent;
1217 const struct cred *mycred, *pcred;
1218 struct cred *cred, *oldcred;
1219 key_ref_t keyring_r;
1220 int ret;
1221
1222 keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);
1223 if (IS_ERR(keyring_r))
1224 return PTR_ERR(keyring_r);
1225
1226 /* our parent is going to need a new cred struct, a new tgcred struct
1227 * and new security data, so we allocate them here to prevent ENOMEM in
1228 * our parent */
1229 ret = -ENOMEM;
1230 cred = cred_alloc_blank();
1231 if (!cred)
1232 goto error_keyring;
1233
1234 cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
1235 keyring_r = NULL;
1236
1237 me = current;
David Howells9d1ac652010-09-10 09:59:46 +01001238 rcu_read_lock();
David Howellsee18d642009-09-02 09:14:21 +01001239 write_lock_irq(&tasklist_lock);
1240
1241 parent = me->real_parent;
1242 ret = -EPERM;
1243
1244 /* the parent mustn't be init and mustn't be a kernel thread */
1245 if (parent->pid <= 1 || !parent->mm)
1246 goto not_permitted;
1247
1248 /* the parent must be single threaded */
Oleg Nesterovdd98acf2010-05-26 14:43:23 -07001249 if (!thread_group_empty(parent))
David Howellsee18d642009-09-02 09:14:21 +01001250 goto not_permitted;
1251
1252 /* the parent and the child must have different session keyrings or
1253 * there's no point */
1254 mycred = current_cred();
1255 pcred = __task_cred(parent);
1256 if (mycred == pcred ||
1257 mycred->tgcred->session_keyring == pcred->tgcred->session_keyring)
1258 goto already_same;
1259
1260 /* the parent must have the same effective ownership and mustn't be
1261 * SUID/SGID */
Justin P. Mattockc5b60b52010-04-21 00:02:11 -07001262 if (pcred->uid != mycred->euid ||
David Howellsee18d642009-09-02 09:14:21 +01001263 pcred->euid != mycred->euid ||
1264 pcred->suid != mycred->euid ||
Justin P. Mattockc5b60b52010-04-21 00:02:11 -07001265 pcred->gid != mycred->egid ||
David Howellsee18d642009-09-02 09:14:21 +01001266 pcred->egid != mycred->egid ||
1267 pcred->sgid != mycred->egid)
1268 goto not_permitted;
1269
1270 /* the keyrings must have the same UID */
David Howells3d964062010-09-10 09:59:51 +01001271 if ((pcred->tgcred->session_keyring &&
1272 pcred->tgcred->session_keyring->uid != mycred->euid) ||
David Howellsee18d642009-09-02 09:14:21 +01001273 mycred->tgcred->session_keyring->uid != mycred->euid)
1274 goto not_permitted;
1275
David Howellsee18d642009-09-02 09:14:21 +01001276 /* if there's an already pending keyring replacement, then we replace
1277 * that */
1278 oldcred = parent->replacement_session_keyring;
1279
1280 /* the replacement session keyring is applied just prior to userspace
1281 * restarting */
1282 parent->replacement_session_keyring = cred;
1283 cred = NULL;
1284 set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME);
1285
1286 write_unlock_irq(&tasklist_lock);
David Howells9d1ac652010-09-10 09:59:46 +01001287 rcu_read_unlock();
David Howellsee18d642009-09-02 09:14:21 +01001288 if (oldcred)
1289 put_cred(oldcred);
1290 return 0;
1291
1292already_same:
1293 ret = 0;
1294not_permitted:
Marc Dionne5c843422009-09-14 12:46:23 +01001295 write_unlock_irq(&tasklist_lock);
David Howells9d1ac652010-09-10 09:59:46 +01001296 rcu_read_unlock();
David Howellsee18d642009-09-02 09:14:21 +01001297 put_cred(cred);
1298 return ret;
1299
1300error_keyring:
1301 key_ref_put(keyring_r);
1302 return ret;
Geert Uytterhoevena00ae4d2009-12-13 20:21:34 +01001303
1304#else /* !TIF_NOTIFY_RESUME */
1305 /*
1306 * To be removed when TIF_NOTIFY_RESUME has been implemented on
1307 * m68k/xtensa
1308 */
1309#warning TIF_NOTIFY_RESUME not implemented
1310 return -EOPNOTSUPP;
1311#endif /* !TIF_NOTIFY_RESUME */
David Howellsee18d642009-09-02 09:14:21 +01001312}
1313
David Howellsb5f545c2006-01-08 01:02:47 -08001314/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 * the key control system call
1316 */
Heiko Carstens938bb9f2009-01-14 14:14:30 +01001317SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
1318 unsigned long, arg4, unsigned long, arg5)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 switch (option) {
1321 case KEYCTL_GET_KEYRING_ID:
1322 return keyctl_get_keyring_ID((key_serial_t) arg2,
1323 (int) arg3);
1324
1325 case KEYCTL_JOIN_SESSION_KEYRING:
1326 return keyctl_join_session_keyring((const char __user *) arg2);
1327
1328 case KEYCTL_UPDATE:
1329 return keyctl_update_key((key_serial_t) arg2,
1330 (const void __user *) arg3,
1331 (size_t) arg4);
1332
1333 case KEYCTL_REVOKE:
1334 return keyctl_revoke_key((key_serial_t) arg2);
1335
1336 case KEYCTL_DESCRIBE:
1337 return keyctl_describe_key((key_serial_t) arg2,
1338 (char __user *) arg3,
1339 (unsigned) arg4);
1340
1341 case KEYCTL_CLEAR:
1342 return keyctl_keyring_clear((key_serial_t) arg2);
1343
1344 case KEYCTL_LINK:
1345 return keyctl_keyring_link((key_serial_t) arg2,
1346 (key_serial_t) arg3);
1347
1348 case KEYCTL_UNLINK:
1349 return keyctl_keyring_unlink((key_serial_t) arg2,
1350 (key_serial_t) arg3);
1351
1352 case KEYCTL_SEARCH:
1353 return keyctl_keyring_search((key_serial_t) arg2,
1354 (const char __user *) arg3,
1355 (const char __user *) arg4,
1356 (key_serial_t) arg5);
1357
1358 case KEYCTL_READ:
1359 return keyctl_read_key((key_serial_t) arg2,
1360 (char __user *) arg3,
1361 (size_t) arg4);
1362
1363 case KEYCTL_CHOWN:
1364 return keyctl_chown_key((key_serial_t) arg2,
1365 (uid_t) arg3,
1366 (gid_t) arg4);
1367
1368 case KEYCTL_SETPERM:
1369 return keyctl_setperm_key((key_serial_t) arg2,
1370 (key_perm_t) arg3);
1371
1372 case KEYCTL_INSTANTIATE:
1373 return keyctl_instantiate_key((key_serial_t) arg2,
1374 (const void __user *) arg3,
1375 (size_t) arg4,
1376 (key_serial_t) arg5);
1377
1378 case KEYCTL_NEGATE:
1379 return keyctl_negate_key((key_serial_t) arg2,
1380 (unsigned) arg3,
1381 (key_serial_t) arg4);
1382
David Howells3e301482005-06-23 22:00:56 -07001383 case KEYCTL_SET_REQKEY_KEYRING:
1384 return keyctl_set_reqkey_keyring(arg2);
1385
David Howells017679c2006-01-08 01:02:43 -08001386 case KEYCTL_SET_TIMEOUT:
1387 return keyctl_set_timeout((key_serial_t) arg2,
1388 (unsigned) arg3);
1389
David Howellsb5f545c2006-01-08 01:02:47 -08001390 case KEYCTL_ASSUME_AUTHORITY:
1391 return keyctl_assume_authority((key_serial_t) arg2);
1392
David Howells70a5bb72008-04-29 01:01:26 -07001393 case KEYCTL_GET_SECURITY:
1394 return keyctl_get_security((key_serial_t) arg2,
James Morris90bd49a2008-12-29 14:35:35 +11001395 (char __user *) arg3,
David Howells70a5bb72008-04-29 01:01:26 -07001396 (size_t) arg4);
1397
David Howellsee18d642009-09-02 09:14:21 +01001398 case KEYCTL_SESSION_TO_PARENT:
1399 return keyctl_session_to_parent();
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 default:
1402 return -EOPNOTSUPP;
1403 }
David Howellsa8b17ed2011-01-20 16:38:27 +00001404}