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>
19 #include <linux/capability.h>
20 #include <linux/string.h>
21 #include <linux/err.h>
22 #include <linux/vmalloc.h>
23 #include <asm/uaccess.h>
26 static int key_get_type_from_user(char *type,
27 const char __user *_type,
32 ret = strncpy_from_user(type, _type, len);
37 if (ret == 0 || ret >= len)
48 /*****************************************************************************/
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()
56 asmlinkage long sys_add_key(const char __user *_type,
57 const char __user *_description,
58 const void __user *_payload,
62 key_ref_t keyring_ref, key_ref;
63 char type[32], *description;
69 if (plen > 1024 * 1024 - 1)
72 /* draw all the data into kernel space */
73 ret = key_get_type_from_user(type, _type, sizeof(type));
77 description = strndup_user(_description, PAGE_SIZE);
78 if (IS_ERR(description)) {
79 ret = PTR_ERR(description);
83 /* pull the payload in if one was supplied */
89 payload = kmalloc(plen, GFP_KERNEL);
91 if (plen <= PAGE_SIZE)
94 payload = vmalloc(plen);
100 if (copy_from_user(payload, _payload, plen) != 0)
104 /* find the target keyring (which must be writable) */
105 keyring_ref = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
106 if (IS_ERR(keyring_ref)) {
107 ret = PTR_ERR(keyring_ref);
111 /* create or update the requested key and add it to the target
113 key_ref = key_create_or_update(keyring_ref, type, description,
114 payload, plen, KEY_ALLOC_IN_QUOTA);
115 if (!IS_ERR(key_ref)) {
116 ret = key_ref_to_ptr(key_ref)->serial;
117 key_ref_put(key_ref);
120 ret = PTR_ERR(key_ref);
123 key_ref_put(keyring_ref);
134 } /* end sys_add_key() */
136 /*****************************************************************************/
138 * search the process keyrings for a matching key
139 * - nested keyrings may also be searched if they have Search permission
140 * - if a key is found, it will be attached to the destination keyring if
141 * there's one specified
142 * - /sbin/request-key will be invoked if _callout_info is non-NULL
143 * - the _callout_info string will be passed to /sbin/request-key
144 * - if the _callout_info string is empty, it will be rendered as "-"
145 * - implements request_key()
147 asmlinkage long sys_request_key(const char __user *_type,
148 const char __user *_description,
149 const char __user *_callout_info,
150 key_serial_t destringid)
152 struct key_type *ktype;
156 char type[32], *description, *callout_info;
159 /* pull the type into kernel space */
160 ret = key_get_type_from_user(type, _type, sizeof(type));
164 /* pull the description into kernel space */
165 description = strndup_user(_description, PAGE_SIZE);
166 if (IS_ERR(description)) {
167 ret = PTR_ERR(description);
171 /* pull the callout info into kernel space */
175 callout_info = strndup_user(_callout_info, PAGE_SIZE);
176 if (IS_ERR(callout_info)) {
177 ret = PTR_ERR(callout_info);
180 callout_len = strlen(callout_info);
183 /* get the destination keyring if specified */
186 dest_ref = lookup_user_key(NULL, destringid, 1, 0, KEY_WRITE);
187 if (IS_ERR(dest_ref)) {
188 ret = PTR_ERR(dest_ref);
193 /* find the key type */
194 ktype = key_type_lookup(type);
196 ret = PTR_ERR(ktype);
201 key = request_key_and_link(ktype, description, callout_info,
202 callout_len, NULL, key_ref_to_ptr(dest_ref),
215 key_ref_put(dest_ref);
223 } /* end sys_request_key() */
225 /*****************************************************************************/
227 * get the ID of the specified process keyring
228 * - the keyring must have search permission to be found
229 * - implements keyctl(KEYCTL_GET_KEYRING_ID)
231 long keyctl_get_keyring_ID(key_serial_t id, int create)
236 key_ref = lookup_user_key(NULL, id, create, 0, KEY_SEARCH);
237 if (IS_ERR(key_ref)) {
238 ret = PTR_ERR(key_ref);
242 ret = key_ref_to_ptr(key_ref)->serial;
243 key_ref_put(key_ref);
247 } /* end keyctl_get_keyring_ID() */
249 /*****************************************************************************/
251 * join the session keyring
252 * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING)
254 long keyctl_join_session_keyring(const char __user *_name)
259 /* fetch the name from userspace */
262 name = strndup_user(_name, PAGE_SIZE);
269 /* join the session */
270 ret = join_session_keyring(name);
275 } /* end keyctl_join_session_keyring() */
277 /*****************************************************************************/
279 * update a key's data payload
280 * - the key must be writable
281 * - implements keyctl(KEYCTL_UPDATE)
283 long keyctl_update_key(key_serial_t id,
284 const void __user *_payload,
292 if (plen > PAGE_SIZE)
295 /* pull the payload in if one was supplied */
299 payload = kmalloc(plen, GFP_KERNEL);
304 if (copy_from_user(payload, _payload, plen) != 0)
308 /* find the target key (which must be writable) */
309 key_ref = lookup_user_key(NULL, id, 0, 0, KEY_WRITE);
310 if (IS_ERR(key_ref)) {
311 ret = PTR_ERR(key_ref);
316 ret = key_update(key_ref, payload, plen);
318 key_ref_put(key_ref);
324 } /* end keyctl_update_key() */
326 /*****************************************************************************/
329 * - the key must be writable
330 * - implements keyctl(KEYCTL_REVOKE)
332 long keyctl_revoke_key(key_serial_t id)
337 key_ref = lookup_user_key(NULL, id, 0, 0, KEY_WRITE);
338 if (IS_ERR(key_ref)) {
339 ret = PTR_ERR(key_ref);
343 key_revoke(key_ref_to_ptr(key_ref));
346 key_ref_put(key_ref);
350 } /* end keyctl_revoke_key() */
352 /*****************************************************************************/
354 * clear the specified process keyring
355 * - the keyring must be writable
356 * - implements keyctl(KEYCTL_CLEAR)
358 long keyctl_keyring_clear(key_serial_t ringid)
360 key_ref_t keyring_ref;
363 keyring_ref = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
364 if (IS_ERR(keyring_ref)) {
365 ret = PTR_ERR(keyring_ref);
369 ret = keyring_clear(key_ref_to_ptr(keyring_ref));
371 key_ref_put(keyring_ref);
375 } /* end keyctl_keyring_clear() */
377 /*****************************************************************************/
379 * link a key into a keyring
380 * - the keyring must be writable
381 * - the key must be linkable
382 * - implements keyctl(KEYCTL_LINK)
384 long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
386 key_ref_t keyring_ref, key_ref;
389 keyring_ref = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
390 if (IS_ERR(keyring_ref)) {
391 ret = PTR_ERR(keyring_ref);
395 key_ref = lookup_user_key(NULL, id, 1, 0, KEY_LINK);
396 if (IS_ERR(key_ref)) {
397 ret = PTR_ERR(key_ref);
401 ret = key_link(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
403 key_ref_put(key_ref);
405 key_ref_put(keyring_ref);
409 } /* end keyctl_keyring_link() */
411 /*****************************************************************************/
413 * unlink the first attachment of a key from a keyring
414 * - the keyring must be writable
415 * - we don't need any permissions on the key
416 * - implements keyctl(KEYCTL_UNLINK)
418 long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
420 key_ref_t keyring_ref, key_ref;
423 keyring_ref = lookup_user_key(NULL, ringid, 0, 0, KEY_WRITE);
424 if (IS_ERR(keyring_ref)) {
425 ret = PTR_ERR(keyring_ref);
429 key_ref = lookup_user_key(NULL, id, 0, 0, 0);
430 if (IS_ERR(key_ref)) {
431 ret = PTR_ERR(key_ref);
435 ret = key_unlink(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
437 key_ref_put(key_ref);
439 key_ref_put(keyring_ref);
443 } /* end keyctl_keyring_unlink() */
445 /*****************************************************************************/
447 * describe a user key
448 * - the key must have view permission
449 * - if there's a buffer, we place up to buflen bytes of data into it
450 * - unless there's an error, we return the amount of description available,
451 * irrespective of how much we may have copied
452 * - the description is formatted thus:
453 * type;uid;gid;perm;description<NUL>
454 * - implements keyctl(KEYCTL_DESCRIBE)
456 long keyctl_describe_key(key_serial_t keyid,
460 struct key *key, *instkey;
465 key_ref = lookup_user_key(NULL, keyid, 0, 1, KEY_VIEW);
466 if (IS_ERR(key_ref)) {
467 /* viewing a key under construction is permitted if we have the
468 * authorisation token handy */
469 if (PTR_ERR(key_ref) == -EACCES) {
470 instkey = key_get_instantiation_authkey(keyid);
471 if (!IS_ERR(instkey)) {
473 key_ref = lookup_user_key(NULL, keyid,
475 if (!IS_ERR(key_ref))
480 ret = PTR_ERR(key_ref);
485 /* calculate how much description we're going to return */
487 tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
491 key = key_ref_to_ptr(key_ref);
493 ret = snprintf(tmpbuf, PAGE_SIZE - 1,
495 key_ref_to_ptr(key_ref)->type->name,
496 key_ref_to_ptr(key_ref)->uid,
497 key_ref_to_ptr(key_ref)->gid,
498 key_ref_to_ptr(key_ref)->perm,
499 key_ref_to_ptr(key_ref)->description ?
500 key_ref_to_ptr(key_ref)->description : ""
503 /* include a NUL char at the end of the data */
504 if (ret > PAGE_SIZE - 1)
509 /* consider returning the data */
510 if (buffer && buflen > 0) {
514 if (copy_to_user(buffer, tmpbuf, buflen) != 0)
520 key_ref_put(key_ref);
524 } /* end keyctl_describe_key() */
526 /*****************************************************************************/
528 * search the specified keyring for a matching key
529 * - the start keyring must be searchable
530 * - nested keyrings may also be searched if they are searchable
531 * - only keys with search permission may be found
532 * - if a key is found, it will be attached to the destination keyring if
533 * there's one specified
534 * - implements keyctl(KEYCTL_SEARCH)
536 long keyctl_keyring_search(key_serial_t ringid,
537 const char __user *_type,
538 const char __user *_description,
539 key_serial_t destringid)
541 struct key_type *ktype;
542 key_ref_t keyring_ref, key_ref, dest_ref;
543 char type[32], *description;
546 /* pull the type and description into kernel space */
547 ret = key_get_type_from_user(type, _type, sizeof(type));
551 description = strndup_user(_description, PAGE_SIZE);
552 if (IS_ERR(description)) {
553 ret = PTR_ERR(description);
557 /* get the keyring at which to begin the search */
558 keyring_ref = lookup_user_key(NULL, ringid, 0, 0, KEY_SEARCH);
559 if (IS_ERR(keyring_ref)) {
560 ret = PTR_ERR(keyring_ref);
564 /* get the destination keyring if specified */
567 dest_ref = lookup_user_key(NULL, destringid, 1, 0, KEY_WRITE);
568 if (IS_ERR(dest_ref)) {
569 ret = PTR_ERR(dest_ref);
574 /* find the key type */
575 ktype = key_type_lookup(type);
577 ret = PTR_ERR(ktype);
582 key_ref = keyring_search(keyring_ref, ktype, description);
583 if (IS_ERR(key_ref)) {
584 ret = PTR_ERR(key_ref);
586 /* treat lack or presence of a negative key the same */
592 /* link the resulting key to the destination keyring if we can */
594 ret = key_permission(key_ref, KEY_LINK);
598 ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref));
603 ret = key_ref_to_ptr(key_ref)->serial;
606 key_ref_put(key_ref);
610 key_ref_put(dest_ref);
612 key_ref_put(keyring_ref);
618 } /* end keyctl_keyring_search() */
620 /*****************************************************************************/
622 * read a user key's payload
623 * - the keyring must be readable or the key must be searchable from the
625 * - if there's a buffer, we place up to buflen bytes of data into it
626 * - unless there's an error, we return the amount of data in the key,
627 * irrespective of how much we may have copied
628 * - implements keyctl(KEYCTL_READ)
630 long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
636 /* find the key first */
637 key_ref = lookup_user_key(NULL, keyid, 0, 0, 0);
638 if (IS_ERR(key_ref)) {
643 key = key_ref_to_ptr(key_ref);
645 /* see if we can read it directly */
646 ret = key_permission(key_ref, KEY_READ);
652 /* we can't; see if it's searchable from this process's keyrings
653 * - we automatically take account of the fact that it may be
654 * dangling off an instantiation key
656 if (!is_key_possessed(key_ref)) {
661 /* the key is probably readable - now try to read it */
663 ret = key_validate(key);
666 if (key->type->read) {
667 /* read the data with the semaphore held (since we
669 down_read(&key->sem);
670 ret = key->type->read(key, buffer, buflen);
680 } /* end keyctl_read_key() */
682 /*****************************************************************************/
684 * change the ownership of a key
685 * - the keyring owned by the changer
686 * - if the uid or gid is -1, then that parameter is not changed
687 * - implements keyctl(KEYCTL_CHOWN)
689 long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
691 struct key_user *newowner, *zapowner = NULL;
697 if (uid == (uid_t) -1 && gid == (gid_t) -1)
700 key_ref = lookup_user_key(NULL, id, 1, 1, KEY_SETATTR);
701 if (IS_ERR(key_ref)) {
702 ret = PTR_ERR(key_ref);
706 key = key_ref_to_ptr(key_ref);
708 /* make the changes with the locks held to prevent chown/chown races */
710 down_write(&key->sem);
712 if (!capable(CAP_SYS_ADMIN)) {
713 /* only the sysadmin can chown a key to some other UID */
714 if (uid != (uid_t) -1 && key->uid != uid)
717 /* only the sysadmin can set the key's GID to a group other
718 * than one of those that the current process subscribes to */
719 if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid))
724 if (uid != (uid_t) -1 && uid != key->uid) {
726 newowner = key_user_lookup(uid);
730 /* transfer the quota burden to the new user */
731 if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) {
732 spin_lock(&newowner->lock);
733 if (newowner->qnkeys + 1 >= KEYQUOTA_MAX_KEYS ||
734 newowner->qnbytes + key->quotalen >=
739 newowner->qnbytes += key->quotalen;
740 spin_unlock(&newowner->lock);
742 spin_lock(&key->user->lock);
744 key->user->qnbytes -= key->quotalen;
745 spin_unlock(&key->user->lock);
748 atomic_dec(&key->user->nkeys);
749 atomic_inc(&newowner->nkeys);
751 if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
752 atomic_dec(&key->user->nikeys);
753 atomic_inc(&newowner->nikeys);
756 zapowner = key->user;
757 key->user = newowner;
762 if (gid != (gid_t) -1)
771 key_user_put(zapowner);
776 spin_unlock(&newowner->lock);
781 } /* end keyctl_chown_key() */
783 /*****************************************************************************/
785 * change the permission mask on a key
786 * - the keyring owned by the changer
787 * - implements keyctl(KEYCTL_SETPERM)
789 long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
796 if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL))
799 key_ref = lookup_user_key(NULL, id, 1, 1, KEY_SETATTR);
800 if (IS_ERR(key_ref)) {
801 ret = PTR_ERR(key_ref);
805 key = key_ref_to_ptr(key_ref);
807 /* make the changes with the locks held to prevent chown/chmod races */
809 down_write(&key->sem);
811 /* if we're not the sysadmin, we can only change a key that we own */
812 if (capable(CAP_SYS_ADMIN) || key->uid == current->fsuid) {
822 } /* end keyctl_setperm_key() */
824 /*****************************************************************************/
826 * instantiate the key with the specified payload, and, if one is given, link
827 * the key into the keyring
829 long keyctl_instantiate_key(key_serial_t id,
830 const void __user *_payload,
834 struct request_key_auth *rka;
836 key_ref_t keyring_ref;
842 if (plen > 1024 * 1024 - 1)
845 /* the appropriate instantiation authorisation key must have been
846 * assumed before calling this */
848 instkey = current->request_key_auth;
852 rka = instkey->payload.data;
853 if (rka->target_key->serial != id)
856 /* pull the payload in if one was supplied */
861 payload = kmalloc(plen, GFP_KERNEL);
863 if (plen <= PAGE_SIZE)
866 payload = vmalloc(plen);
872 if (copy_from_user(payload, _payload, plen) != 0)
876 /* find the destination keyring amongst those belonging to the
880 keyring_ref = lookup_user_key(rka->context, ringid, 1, 0,
882 if (IS_ERR(keyring_ref)) {
883 ret = PTR_ERR(keyring_ref);
888 /* instantiate the key and link it into a keyring */
889 ret = key_instantiate_and_link(rka->target_key, payload, plen,
890 key_ref_to_ptr(keyring_ref), instkey);
892 key_ref_put(keyring_ref);
894 /* discard the assumed authority if it's just been disabled by
895 * instantiation of the key */
897 key_put(current->request_key_auth);
898 current->request_key_auth = NULL;
909 } /* end keyctl_instantiate_key() */
911 /*****************************************************************************/
913 * negatively instantiate the key with the given timeout (in seconds), and, if
914 * one is given, link the key into the keyring
916 long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
918 struct request_key_auth *rka;
920 key_ref_t keyring_ref;
923 /* the appropriate instantiation authorisation key must have been
924 * assumed before calling this */
926 instkey = current->request_key_auth;
930 rka = instkey->payload.data;
931 if (rka->target_key->serial != id)
934 /* find the destination keyring if present (which must also be
938 keyring_ref = lookup_user_key(NULL, ringid, 1, 0, KEY_WRITE);
939 if (IS_ERR(keyring_ref)) {
940 ret = PTR_ERR(keyring_ref);
945 /* instantiate the key and link it into a keyring */
946 ret = key_negate_and_link(rka->target_key, timeout,
947 key_ref_to_ptr(keyring_ref), instkey);
949 key_ref_put(keyring_ref);
951 /* discard the assumed authority if it's just been disabled by
952 * instantiation of the key */
954 key_put(current->request_key_auth);
955 current->request_key_auth = NULL;
961 } /* end keyctl_negate_key() */
963 /*****************************************************************************/
965 * set the default keyring in which request_key() will cache keys
966 * - return the old setting
968 long keyctl_set_reqkey_keyring(int reqkey_defl)
972 switch (reqkey_defl) {
973 case KEY_REQKEY_DEFL_THREAD_KEYRING:
974 ret = install_thread_keyring(current);
979 case KEY_REQKEY_DEFL_PROCESS_KEYRING:
980 ret = install_process_keyring(current);
984 case KEY_REQKEY_DEFL_DEFAULT:
985 case KEY_REQKEY_DEFL_SESSION_KEYRING:
986 case KEY_REQKEY_DEFL_USER_KEYRING:
987 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
989 current->jit_keyring = reqkey_defl;
991 case KEY_REQKEY_DEFL_NO_CHANGE:
992 return current->jit_keyring;
994 case KEY_REQKEY_DEFL_GROUP_KEYRING:
999 } /* end keyctl_set_reqkey_keyring() */
1001 /*****************************************************************************/
1003 * set or clear the timeout for a key
1005 long keyctl_set_timeout(key_serial_t id, unsigned timeout)
1007 struct timespec now;
1013 key_ref = lookup_user_key(NULL, id, 1, 1, KEY_SETATTR);
1014 if (IS_ERR(key_ref)) {
1015 ret = PTR_ERR(key_ref);
1019 key = key_ref_to_ptr(key_ref);
1021 /* make the changes with the locks held to prevent races */
1022 down_write(&key->sem);
1026 now = current_kernel_time();
1027 expiry = now.tv_sec + timeout;
1030 key->expiry = expiry;
1032 up_write(&key->sem);
1039 } /* end keyctl_set_timeout() */
1041 /*****************************************************************************/
1043 * assume the authority to instantiate the specified key
1045 long keyctl_assume_authority(key_serial_t id)
1047 struct key *authkey;
1050 /* special key IDs aren't permitted */
1055 /* we divest ourselves of authority if given an ID of 0 */
1057 key_put(current->request_key_auth);
1058 current->request_key_auth = NULL;
1063 /* attempt to assume the authority temporarily granted to us whilst we
1064 * instantiate the specified key
1065 * - the authorisation key must be in the current task's keyrings
1068 authkey = key_get_instantiation_authkey(id);
1069 if (IS_ERR(authkey)) {
1070 ret = PTR_ERR(authkey);
1074 key_put(current->request_key_auth);
1075 current->request_key_auth = authkey;
1076 ret = authkey->serial;
1081 } /* end keyctl_assume_authority() */
1083 /*****************************************************************************/
1085 * the key control system call
1087 asmlinkage long sys_keyctl(int option, unsigned long arg2, unsigned long arg3,
1088 unsigned long arg4, unsigned long arg5)
1091 case KEYCTL_GET_KEYRING_ID:
1092 return keyctl_get_keyring_ID((key_serial_t) arg2,
1095 case KEYCTL_JOIN_SESSION_KEYRING:
1096 return keyctl_join_session_keyring((const char __user *) arg2);
1099 return keyctl_update_key((key_serial_t) arg2,
1100 (const void __user *) arg3,
1104 return keyctl_revoke_key((key_serial_t) arg2);
1106 case KEYCTL_DESCRIBE:
1107 return keyctl_describe_key((key_serial_t) arg2,
1108 (char __user *) arg3,
1112 return keyctl_keyring_clear((key_serial_t) arg2);
1115 return keyctl_keyring_link((key_serial_t) arg2,
1116 (key_serial_t) arg3);
1119 return keyctl_keyring_unlink((key_serial_t) arg2,
1120 (key_serial_t) arg3);
1123 return keyctl_keyring_search((key_serial_t) arg2,
1124 (const char __user *) arg3,
1125 (const char __user *) arg4,
1126 (key_serial_t) arg5);
1129 return keyctl_read_key((key_serial_t) arg2,
1130 (char __user *) arg3,
1134 return keyctl_chown_key((key_serial_t) arg2,
1138 case KEYCTL_SETPERM:
1139 return keyctl_setperm_key((key_serial_t) arg2,
1142 case KEYCTL_INSTANTIATE:
1143 return keyctl_instantiate_key((key_serial_t) arg2,
1144 (const void __user *) arg3,
1146 (key_serial_t) arg5);
1149 return keyctl_negate_key((key_serial_t) arg2,
1151 (key_serial_t) arg4);
1153 case KEYCTL_SET_REQKEY_KEYRING:
1154 return keyctl_set_reqkey_keyring(arg2);
1156 case KEYCTL_SET_TIMEOUT:
1157 return keyctl_set_timeout((key_serial_t) arg2,
1160 case KEYCTL_ASSUME_AUTHORITY:
1161 return keyctl_assume_authority((key_serial_t) arg2);
1167 } /* end sys_keyctl() */