[PATCH] USB: ftdi_sio: new microHAM and Evolution Robotics devices
[linux-2.6/zen-sources.git] / security / keys / keyctl.c
blobfea262860ea01656dbe7514b4b4a301ca47424b6
1 /* keyctl.c: userspace keyctl operations
3 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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>
19 #include <linux/err.h>
20 #include <asm/uaccess.h>
21 #include "internal.h"
23 /*****************************************************************************/
25 * extract the description of a new key from userspace and either add it as a
26 * new key to the specified keyring or update a matching key in that keyring
27 * - the keyring must be writable
28 * - returns the new key's serial number
29 * - implements add_key()
31 asmlinkage long sys_add_key(const char __user *_type,
32 const char __user *_description,
33 const void __user *_payload,
34 size_t plen,
35 key_serial_t ringid)
37 struct key *keyring, *key;
38 char type[32], *description;
39 void *payload;
40 long dlen, ret;
42 ret = -EINVAL;
43 if (plen > 32767)
44 goto error;
46 /* draw all the data into kernel space */
47 ret = strncpy_from_user(type, _type, sizeof(type) - 1);
48 if (ret < 0)
49 goto error;
50 type[31] = '\0';
52 if (!type[0])
53 goto error;
55 ret = -EPERM;
56 if (type[0] == '.')
57 goto error;
59 ret = -EFAULT;
60 dlen = strnlen_user(_description, PAGE_SIZE - 1);
61 if (dlen <= 0)
62 goto error;
64 ret = -EINVAL;
65 if (dlen > PAGE_SIZE - 1)
66 goto error;
68 ret = -ENOMEM;
69 description = kmalloc(dlen + 1, GFP_KERNEL);
70 if (!description)
71 goto error;
73 ret = -EFAULT;
74 if (copy_from_user(description, _description, dlen + 1) != 0)
75 goto error2;
77 /* pull the payload in if one was supplied */
78 payload = NULL;
80 if (_payload) {
81 ret = -ENOMEM;
82 payload = kmalloc(plen, GFP_KERNEL);
83 if (!payload)
84 goto error2;
86 ret = -EFAULT;
87 if (copy_from_user(payload, _payload, plen) != 0)
88 goto error3;
91 /* find the target keyring (which must be writable) */
92 keyring = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
93 if (IS_ERR(keyring)) {
94 ret = PTR_ERR(keyring);
95 goto error3;
98 /* create or update the requested key and add it to the target
99 * keyring */
100 key = key_create_or_update(keyring, type, description,
101 payload, plen, 0);
102 if (!IS_ERR(key)) {
103 ret = key->serial;
104 key_put(key);
106 else {
107 ret = PTR_ERR(key);
110 key_put(keyring);
111 error3:
112 kfree(payload);
113 error2:
114 kfree(description);
115 error:
116 return ret;
118 } /* end sys_add_key() */
120 /*****************************************************************************/
122 * search the process keyrings for a matching key
123 * - nested keyrings may also be searched if they have Search permission
124 * - if a key is found, it will be attached to the destination keyring if
125 * there's one specified
126 * - /sbin/request-key will be invoked if _callout_info is non-NULL
127 * - the _callout_info string will be passed to /sbin/request-key
128 * - if the _callout_info string is empty, it will be rendered as "-"
129 * - implements request_key()
131 asmlinkage long sys_request_key(const char __user *_type,
132 const char __user *_description,
133 const char __user *_callout_info,
134 key_serial_t destringid)
136 struct key_type *ktype;
137 struct key *key, *dest;
138 char type[32], *description, *callout_info;
139 long dlen, ret;
141 /* pull the type into kernel space */
142 ret = strncpy_from_user(type, _type, sizeof(type) - 1);
143 if (ret < 0)
144 goto error;
145 type[31] = '\0';
147 /* pull the description into kernel space */
148 ret = -EFAULT;
149 dlen = strnlen_user(_description, PAGE_SIZE - 1);
150 if (dlen <= 0)
151 goto error;
153 ret = -EINVAL;
154 if (dlen > PAGE_SIZE - 1)
155 goto error;
157 ret = -ENOMEM;
158 description = kmalloc(dlen + 1, GFP_KERNEL);
159 if (!description)
160 goto error;
162 ret = -EFAULT;
163 if (copy_from_user(description, _description, dlen + 1) != 0)
164 goto error2;
166 /* pull the callout info into kernel space */
167 callout_info = NULL;
168 if (_callout_info) {
169 ret = -EFAULT;
170 dlen = strnlen_user(_callout_info, PAGE_SIZE - 1);
171 if (dlen <= 0)
172 goto error2;
174 ret = -EINVAL;
175 if (dlen > PAGE_SIZE - 1)
176 goto error2;
178 ret = -ENOMEM;
179 callout_info = kmalloc(dlen + 1, GFP_KERNEL);
180 if (!callout_info)
181 goto error2;
183 ret = -EFAULT;
184 if (copy_from_user(callout_info, _callout_info, dlen + 1) != 0)
185 goto error3;
188 /* get the destination keyring if specified */
189 dest = NULL;
190 if (destringid) {
191 dest = lookup_user_key(NULL, destringid, 1, 0, KEY_WRITE);
192 if (IS_ERR(dest)) {
193 ret = PTR_ERR(dest);
194 goto error3;
198 /* find the key type */
199 ktype = key_type_lookup(type);
200 if (IS_ERR(ktype)) {
201 ret = PTR_ERR(ktype);
202 goto error4;
205 /* do the search */
206 key = request_key_and_link(ktype, description, callout_info, dest);
207 if (IS_ERR(key)) {
208 ret = PTR_ERR(key);
209 goto error5;
212 ret = key->serial;
214 key_put(key);
215 error5:
216 key_type_put(ktype);
217 error4:
218 key_put(dest);
219 error3:
220 kfree(callout_info);
221 error2:
222 kfree(description);
223 error:
224 return ret;
226 } /* end sys_request_key() */
228 /*****************************************************************************/
230 * get the ID of the specified process keyring
231 * - the keyring must have search permission to be found
232 * - implements keyctl(KEYCTL_GET_KEYRING_ID)
234 long keyctl_get_keyring_ID(key_serial_t id, int create)
236 struct key *key;
237 long ret;
239 key = lookup_user_key(NULL, id, create, 0, KEY_SEARCH);
240 if (IS_ERR(key)) {
241 ret = PTR_ERR(key);
242 goto error;
245 ret = key->serial;
246 key_put(key);
247 error:
248 return ret;
250 } /* end keyctl_get_keyring_ID() */
252 /*****************************************************************************/
254 * join the session keyring
255 * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING)
257 long keyctl_join_session_keyring(const char __user *_name)
259 char *name;
260 long nlen, ret;
262 /* fetch the name from userspace */
263 name = NULL;
264 if (_name) {
265 ret = -EFAULT;
266 nlen = strnlen_user(_name, PAGE_SIZE - 1);
267 if (nlen <= 0)
268 goto error;
270 ret = -EINVAL;
271 if (nlen > PAGE_SIZE - 1)
272 goto error;
274 ret = -ENOMEM;
275 name = kmalloc(nlen + 1, GFP_KERNEL);
276 if (!name)
277 goto error;
279 ret = -EFAULT;
280 if (copy_from_user(name, _name, nlen + 1) != 0)
281 goto error2;
284 /* join the session */
285 ret = join_session_keyring(name);
287 error2:
288 kfree(name);
289 error:
290 return ret;
292 } /* end keyctl_join_session_keyring() */
294 /*****************************************************************************/
296 * update a key's data payload
297 * - the key must be writable
298 * - implements keyctl(KEYCTL_UPDATE)
300 long keyctl_update_key(key_serial_t id,
301 const void __user *_payload,
302 size_t plen)
304 struct key *key;
305 void *payload;
306 long ret;
308 ret = -EINVAL;
309 if (plen > PAGE_SIZE)
310 goto error;
312 /* pull the payload in if one was supplied */
313 payload = NULL;
314 if (_payload) {
315 ret = -ENOMEM;
316 payload = kmalloc(plen, GFP_KERNEL);
317 if (!payload)
318 goto error;
320 ret = -EFAULT;
321 if (copy_from_user(payload, _payload, plen) != 0)
322 goto error2;
325 /* find the target key (which must be writable) */
326 key = lookup_user_key(NULL, id, 0, 0, KEY_WRITE);
327 if (IS_ERR(key)) {
328 ret = PTR_ERR(key);
329 goto error2;
332 /* update the key */
333 ret = key_update(key, payload, plen);
335 key_put(key);
336 error2:
337 kfree(payload);
338 error:
339 return ret;
341 } /* end keyctl_update_key() */
343 /*****************************************************************************/
345 * revoke a key
346 * - the key must be writable
347 * - implements keyctl(KEYCTL_REVOKE)
349 long keyctl_revoke_key(key_serial_t id)
351 struct key *key;
352 long ret;
354 key = lookup_user_key(NULL, id, 0, 0, KEY_WRITE);
355 if (IS_ERR(key)) {
356 ret = PTR_ERR(key);
357 goto error;
360 key_revoke(key);
361 ret = 0;
363 key_put(key);
364 error:
365 return 0;
367 } /* end keyctl_revoke_key() */
369 /*****************************************************************************/
371 * clear the specified process keyring
372 * - the keyring must be writable
373 * - implements keyctl(KEYCTL_CLEAR)
375 long keyctl_keyring_clear(key_serial_t ringid)
377 struct key *keyring;
378 long ret;
380 keyring = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
381 if (IS_ERR(keyring)) {
382 ret = PTR_ERR(keyring);
383 goto error;
386 ret = keyring_clear(keyring);
388 key_put(keyring);
389 error:
390 return ret;
392 } /* end keyctl_keyring_clear() */
394 /*****************************************************************************/
396 * link a key into a keyring
397 * - the keyring must be writable
398 * - the key must be linkable
399 * - implements keyctl(KEYCTL_LINK)
401 long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
403 struct key *keyring, *key;
404 long ret;
406 keyring = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
407 if (IS_ERR(keyring)) {
408 ret = PTR_ERR(keyring);
409 goto error;
412 key = lookup_user_key(NULL, id, 1, 0, KEY_LINK);
413 if (IS_ERR(key)) {
414 ret = PTR_ERR(key);
415 goto error2;
418 ret = key_link(keyring, key);
420 key_put(key);
421 error2:
422 key_put(keyring);
423 error:
424 return ret;
426 } /* end keyctl_keyring_link() */
428 /*****************************************************************************/
430 * unlink the first attachment of a key from a keyring
431 * - the keyring must be writable
432 * - we don't need any permissions on the key
433 * - implements keyctl(KEYCTL_UNLINK)
435 long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
437 struct key *keyring, *key;
438 long ret;
440 keyring = lookup_user_key(NULL, ringid, 0, 0, KEY_WRITE);
441 if (IS_ERR(keyring)) {
442 ret = PTR_ERR(keyring);
443 goto error;
446 key = lookup_user_key(NULL, id, 0, 0, 0);
447 if (IS_ERR(key)) {
448 ret = PTR_ERR(key);
449 goto error2;
452 ret = key_unlink(keyring, key);
454 key_put(key);
455 error2:
456 key_put(keyring);
457 error:
458 return ret;
460 } /* end keyctl_keyring_unlink() */
462 /*****************************************************************************/
464 * describe a user key
465 * - the key must have view permission
466 * - if there's a buffer, we place up to buflen bytes of data into it
467 * - unless there's an error, we return the amount of description available,
468 * irrespective of how much we may have copied
469 * - the description is formatted thus:
470 * type;uid;gid;perm;description<NUL>
471 * - implements keyctl(KEYCTL_DESCRIBE)
473 long keyctl_describe_key(key_serial_t keyid,
474 char __user *buffer,
475 size_t buflen)
477 struct key *key, *instkey;
478 char *tmpbuf;
479 long ret;
481 key = lookup_user_key(NULL, keyid, 0, 1, KEY_VIEW);
482 if (IS_ERR(key)) {
483 /* viewing a key under construction is permitted if we have the
484 * authorisation token handy */
485 if (PTR_ERR(key) == -EACCES) {
486 instkey = key_get_instantiation_authkey(keyid);
487 if (!IS_ERR(instkey)) {
488 key_put(instkey);
489 key = lookup_user_key(NULL, keyid, 0, 1, 0);
490 if (!IS_ERR(key))
491 goto okay;
495 ret = PTR_ERR(key);
496 goto error;
499 okay:
500 /* calculate how much description we're going to return */
501 ret = -ENOMEM;
502 tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
503 if (!tmpbuf)
504 goto error2;
506 ret = snprintf(tmpbuf, PAGE_SIZE - 1,
507 "%s;%d;%d;%06x;%s",
508 key->type->name,
509 key->uid,
510 key->gid,
511 key->perm,
512 key->description ? key->description :""
515 /* include a NUL char at the end of the data */
516 if (ret > PAGE_SIZE - 1)
517 ret = PAGE_SIZE - 1;
518 tmpbuf[ret] = 0;
519 ret++;
521 /* consider returning the data */
522 if (buffer && buflen > 0) {
523 if (buflen > ret)
524 buflen = ret;
526 if (copy_to_user(buffer, tmpbuf, buflen) != 0)
527 ret = -EFAULT;
530 kfree(tmpbuf);
531 error2:
532 key_put(key);
533 error:
534 return ret;
536 } /* end keyctl_describe_key() */
538 /*****************************************************************************/
540 * search the specified keyring for a matching key
541 * - the start keyring must be searchable
542 * - nested keyrings may also be searched if they are searchable
543 * - only keys with search permission may be found
544 * - if a key is found, it will be attached to the destination keyring if
545 * there's one specified
546 * - implements keyctl(KEYCTL_SEARCH)
548 long keyctl_keyring_search(key_serial_t ringid,
549 const char __user *_type,
550 const char __user *_description,
551 key_serial_t destringid)
553 struct key_type *ktype;
554 struct key *keyring, *key, *dest;
555 char type[32], *description;
556 long dlen, ret;
558 /* pull the type and description into kernel space */
559 ret = strncpy_from_user(type, _type, sizeof(type) - 1);
560 if (ret < 0)
561 goto error;
562 type[31] = '\0';
564 ret = -EFAULT;
565 dlen = strnlen_user(_description, PAGE_SIZE - 1);
566 if (dlen <= 0)
567 goto error;
569 ret = -EINVAL;
570 if (dlen > PAGE_SIZE - 1)
571 goto error;
573 ret = -ENOMEM;
574 description = kmalloc(dlen + 1, GFP_KERNEL);
575 if (!description)
576 goto error;
578 ret = -EFAULT;
579 if (copy_from_user(description, _description, dlen + 1) != 0)
580 goto error2;
582 /* get the keyring at which to begin the search */
583 keyring = lookup_user_key(NULL, ringid, 0, 0, KEY_SEARCH);
584 if (IS_ERR(keyring)) {
585 ret = PTR_ERR(keyring);
586 goto error2;
589 /* get the destination keyring if specified */
590 dest = NULL;
591 if (destringid) {
592 dest = lookup_user_key(NULL, destringid, 1, 0, KEY_WRITE);
593 if (IS_ERR(dest)) {
594 ret = PTR_ERR(dest);
595 goto error3;
599 /* find the key type */
600 ktype = key_type_lookup(type);
601 if (IS_ERR(ktype)) {
602 ret = PTR_ERR(ktype);
603 goto error4;
606 /* do the search */
607 key = keyring_search(keyring, ktype, description);
608 if (IS_ERR(key)) {
609 ret = PTR_ERR(key);
611 /* treat lack or presence of a negative key the same */
612 if (ret == -EAGAIN)
613 ret = -ENOKEY;
614 goto error5;
617 /* link the resulting key to the destination keyring if we can */
618 if (dest) {
619 ret = -EACCES;
620 if (!key_permission(key, KEY_LINK))
621 goto error6;
623 ret = key_link(dest, key);
624 if (ret < 0)
625 goto error6;
628 ret = key->serial;
630 error6:
631 key_put(key);
632 error5:
633 key_type_put(ktype);
634 error4:
635 key_put(dest);
636 error3:
637 key_put(keyring);
638 error2:
639 kfree(description);
640 error:
641 return ret;
643 } /* end keyctl_keyring_search() */
645 /*****************************************************************************/
647 * see if the key we're looking at is the target key
649 static int keyctl_read_key_same(const struct key *key, const void *target)
651 return key == target;
653 } /* end keyctl_read_key_same() */
655 /*****************************************************************************/
657 * read a user key's payload
658 * - the keyring must be readable or the key must be searchable from the
659 * process's keyrings
660 * - if there's a buffer, we place up to buflen bytes of data into it
661 * - unless there's an error, we return the amount of data in the key,
662 * irrespective of how much we may have copied
663 * - implements keyctl(KEYCTL_READ)
665 long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
667 struct key *key, *skey;
668 long ret;
670 /* find the key first */
671 key = lookup_user_key(NULL, keyid, 0, 0, 0);
672 if (!IS_ERR(key)) {
673 /* see if we can read it directly */
674 if (key_permission(key, KEY_READ))
675 goto can_read_key;
677 /* we can't; see if it's searchable from this process's
678 * keyrings
679 * - we automatically take account of the fact that it may be
680 * dangling off an instantiation key
682 skey = search_process_keyrings(key->type, key,
683 keyctl_read_key_same, current);
684 if (!IS_ERR(skey))
685 goto can_read_key2;
687 ret = PTR_ERR(skey);
688 goto error2;
691 ret = -ENOKEY;
692 goto error;
694 /* the key is probably readable - now try to read it */
695 can_read_key2:
696 key_put(skey);
697 can_read_key:
698 ret = key_validate(key);
699 if (ret == 0) {
700 ret = -EOPNOTSUPP;
701 if (key->type->read) {
702 /* read the data with the semaphore held (since we
703 * might sleep) */
704 down_read(&key->sem);
705 ret = key->type->read(key, buffer, buflen);
706 up_read(&key->sem);
710 error2:
711 key_put(key);
712 error:
713 return ret;
715 } /* end keyctl_read_key() */
717 /*****************************************************************************/
719 * change the ownership of a key
720 * - the keyring owned by the changer
721 * - if the uid or gid is -1, then that parameter is not changed
722 * - implements keyctl(KEYCTL_CHOWN)
724 long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
726 struct key *key;
727 long ret;
729 ret = 0;
730 if (uid == (uid_t) -1 && gid == (gid_t) -1)
731 goto error;
733 key = lookup_user_key(NULL, id, 1, 1, 0);
734 if (IS_ERR(key)) {
735 ret = PTR_ERR(key);
736 goto error;
739 /* make the changes with the locks held to prevent chown/chown races */
740 ret = -EACCES;
741 down_write(&key->sem);
743 if (!capable(CAP_SYS_ADMIN)) {
744 /* only the sysadmin can chown a key to some other UID */
745 if (uid != (uid_t) -1 && key->uid != uid)
746 goto no_access;
748 /* only the sysadmin can set the key's GID to a group other
749 * than one of those that the current process subscribes to */
750 if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid))
751 goto no_access;
754 /* change the UID (have to update the quotas) */
755 if (uid != (uid_t) -1 && uid != key->uid) {
756 /* don't support UID changing yet */
757 ret = -EOPNOTSUPP;
758 goto no_access;
761 /* change the GID */
762 if (gid != (gid_t) -1)
763 key->gid = gid;
765 ret = 0;
767 no_access:
768 up_write(&key->sem);
769 key_put(key);
770 error:
771 return ret;
773 } /* end keyctl_chown_key() */
775 /*****************************************************************************/
777 * change the permission mask on a key
778 * - the keyring owned by the changer
779 * - implements keyctl(KEYCTL_SETPERM)
781 long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
783 struct key *key;
784 long ret;
786 ret = -EINVAL;
787 if (perm & ~(KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL))
788 goto error;
790 key = lookup_user_key(NULL, id, 1, 1, 0);
791 if (IS_ERR(key)) {
792 ret = PTR_ERR(key);
793 goto error;
796 /* make the changes with the locks held to prevent chown/chmod races */
797 ret = -EACCES;
798 down_write(&key->sem);
800 /* if we're not the sysadmin, we can only change a key that we own */
801 if (capable(CAP_SYS_ADMIN) || key->uid == current->fsuid) {
802 key->perm = perm;
803 ret = 0;
806 up_write(&key->sem);
807 key_put(key);
808 error:
809 return ret;
811 } /* end keyctl_setperm_key() */
813 /*****************************************************************************/
815 * instantiate the key with the specified payload, and, if one is given, link
816 * the key into the keyring
818 long keyctl_instantiate_key(key_serial_t id,
819 const void __user *_payload,
820 size_t plen,
821 key_serial_t ringid)
823 struct request_key_auth *rka;
824 struct key *instkey, *keyring;
825 void *payload;
826 long ret;
828 ret = -EINVAL;
829 if (plen > 32767)
830 goto error;
832 /* pull the payload in if one was supplied */
833 payload = NULL;
835 if (_payload) {
836 ret = -ENOMEM;
837 payload = kmalloc(plen, GFP_KERNEL);
838 if (!payload)
839 goto error;
841 ret = -EFAULT;
842 if (copy_from_user(payload, _payload, plen) != 0)
843 goto error2;
846 /* find the instantiation authorisation key */
847 instkey = key_get_instantiation_authkey(id);
848 if (IS_ERR(instkey)) {
849 ret = PTR_ERR(instkey);
850 goto error2;
853 rka = instkey->payload.data;
855 /* find the destination keyring amongst those belonging to the
856 * requesting task */
857 keyring = NULL;
858 if (ringid) {
859 keyring = lookup_user_key(rka->context, ringid, 1, 0,
860 KEY_WRITE);
861 if (IS_ERR(keyring)) {
862 ret = PTR_ERR(keyring);
863 goto error3;
867 /* instantiate the key and link it into a keyring */
868 ret = key_instantiate_and_link(rka->target_key, payload, plen,
869 keyring, instkey);
871 key_put(keyring);
872 error3:
873 key_put(instkey);
874 error2:
875 kfree(payload);
876 error:
877 return ret;
879 } /* end keyctl_instantiate_key() */
881 /*****************************************************************************/
883 * negatively instantiate the key with the given timeout (in seconds), and, if
884 * one is given, link the key into the keyring
886 long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
888 struct request_key_auth *rka;
889 struct key *instkey, *keyring;
890 long ret;
892 /* find the instantiation authorisation key */
893 instkey = key_get_instantiation_authkey(id);
894 if (IS_ERR(instkey)) {
895 ret = PTR_ERR(instkey);
896 goto error;
899 rka = instkey->payload.data;
901 /* find the destination keyring if present (which must also be
902 * writable) */
903 keyring = NULL;
904 if (ringid) {
905 keyring = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
906 if (IS_ERR(keyring)) {
907 ret = PTR_ERR(keyring);
908 goto error2;
912 /* instantiate the key and link it into a keyring */
913 ret = key_negate_and_link(rka->target_key, timeout, keyring, instkey);
915 key_put(keyring);
916 error2:
917 key_put(instkey);
918 error:
919 return ret;
921 } /* end keyctl_negate_key() */
923 /*****************************************************************************/
925 * set the default keyring in which request_key() will cache keys
926 * - return the old setting
928 long keyctl_set_reqkey_keyring(int reqkey_defl)
930 int ret;
932 switch (reqkey_defl) {
933 case KEY_REQKEY_DEFL_THREAD_KEYRING:
934 ret = install_thread_keyring(current);
935 if (ret < 0)
936 return ret;
937 goto set;
939 case KEY_REQKEY_DEFL_PROCESS_KEYRING:
940 ret = install_process_keyring(current);
941 if (ret < 0)
942 return ret;
944 case KEY_REQKEY_DEFL_DEFAULT:
945 case KEY_REQKEY_DEFL_SESSION_KEYRING:
946 case KEY_REQKEY_DEFL_USER_KEYRING:
947 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
948 set:
949 current->jit_keyring = reqkey_defl;
951 case KEY_REQKEY_DEFL_NO_CHANGE:
952 return current->jit_keyring;
954 case KEY_REQKEY_DEFL_GROUP_KEYRING:
955 default:
956 return -EINVAL;
959 } /* end keyctl_set_reqkey_keyring() */
961 /*****************************************************************************/
963 * the key control system call
965 asmlinkage long sys_keyctl(int option, unsigned long arg2, unsigned long arg3,
966 unsigned long arg4, unsigned long arg5)
968 switch (option) {
969 case KEYCTL_GET_KEYRING_ID:
970 return keyctl_get_keyring_ID((key_serial_t) arg2,
971 (int) arg3);
973 case KEYCTL_JOIN_SESSION_KEYRING:
974 return keyctl_join_session_keyring((const char __user *) arg2);
976 case KEYCTL_UPDATE:
977 return keyctl_update_key((key_serial_t) arg2,
978 (const void __user *) arg3,
979 (size_t) arg4);
981 case KEYCTL_REVOKE:
982 return keyctl_revoke_key((key_serial_t) arg2);
984 case KEYCTL_DESCRIBE:
985 return keyctl_describe_key((key_serial_t) arg2,
986 (char __user *) arg3,
987 (unsigned) arg4);
989 case KEYCTL_CLEAR:
990 return keyctl_keyring_clear((key_serial_t) arg2);
992 case KEYCTL_LINK:
993 return keyctl_keyring_link((key_serial_t) arg2,
994 (key_serial_t) arg3);
996 case KEYCTL_UNLINK:
997 return keyctl_keyring_unlink((key_serial_t) arg2,
998 (key_serial_t) arg3);
1000 case KEYCTL_SEARCH:
1001 return keyctl_keyring_search((key_serial_t) arg2,
1002 (const char __user *) arg3,
1003 (const char __user *) arg4,
1004 (key_serial_t) arg5);
1006 case KEYCTL_READ:
1007 return keyctl_read_key((key_serial_t) arg2,
1008 (char __user *) arg3,
1009 (size_t) arg4);
1011 case KEYCTL_CHOWN:
1012 return keyctl_chown_key((key_serial_t) arg2,
1013 (uid_t) arg3,
1014 (gid_t) arg4);
1016 case KEYCTL_SETPERM:
1017 return keyctl_setperm_key((key_serial_t) arg2,
1018 (key_perm_t) arg3);
1020 case KEYCTL_INSTANTIATE:
1021 return keyctl_instantiate_key((key_serial_t) arg2,
1022 (const void __user *) arg3,
1023 (size_t) arg4,
1024 (key_serial_t) arg5);
1026 case KEYCTL_NEGATE:
1027 return keyctl_negate_key((key_serial_t) arg2,
1028 (unsigned) arg3,
1029 (key_serial_t) arg4);
1031 case KEYCTL_SET_REQKEY_KEYRING:
1032 return keyctl_set_reqkey_keyring(arg2);
1034 default:
1035 return -EOPNOTSUPP;
1038 } /* end sys_keyctl() */