aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/keyctl.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /security/keys/keyctl.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'security/keys/keyctl.c')
-rw-r--r--security/keys/keyctl.c502
1 files changed, 344 insertions, 158 deletions
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 60924f6a52db..eca51918c951 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1,4 +1,4 @@
1/* keyctl.c: userspace keyctl operations 1/* Userspace key control operations
2 * 2 *
3 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved. 3 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com) 4 * Written by David Howells (dhowells@redhat.com)
@@ -31,28 +31,24 @@ static int key_get_type_from_user(char *type,
31 int ret; 31 int ret;
32 32
33 ret = strncpy_from_user(type, _type, len); 33 ret = strncpy_from_user(type, _type, len);
34
35 if (ret < 0) 34 if (ret < 0)
36 return ret; 35 return ret;
37
38 if (ret == 0 || ret >= len) 36 if (ret == 0 || ret >= len)
39 return -EINVAL; 37 return -EINVAL;
40
41 if (type[0] == '.') 38 if (type[0] == '.')
42 return -EPERM; 39 return -EPERM;
43
44 type[len - 1] = '\0'; 40 type[len - 1] = '\0';
45
46 return 0; 41 return 0;
47} 42}
48 43
49/*****************************************************************************/
50/* 44/*
51 * extract the description of a new key from userspace and either add it as a 45 * Extract the description of a new key from userspace and either add it as a
52 * new key to the specified keyring or update a matching key in that keyring 46 * new key to the specified keyring or update a matching key in that keyring.
53 * - the keyring must be writable 47 *
54 * - returns the new key's serial number 48 * The keyring must be writable so that we can attach the key to it.
55 * - implements add_key() 49 *
50 * If successful, the new key's serial number is returned, otherwise an error
51 * code is returned.
56 */ 52 */
57SYSCALL_DEFINE5(add_key, const char __user *, _type, 53SYSCALL_DEFINE5(add_key, const char __user *, _type,
58 const char __user *, _description, 54 const char __user *, _description,
@@ -132,19 +128,20 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
132 kfree(description); 128 kfree(description);
133 error: 129 error:
134 return ret; 130 return ret;
131}
135 132
136} /* end sys_add_key() */
137
138/*****************************************************************************/
139/* 133/*
140 * search the process keyrings for a matching key 134 * Search the process keyrings and keyring trees linked from those for a
141 * - nested keyrings may also be searched if they have Search permission 135 * matching key. Keyrings must have appropriate Search permission to be
142 * - if a key is found, it will be attached to the destination keyring if 136 * searched.
143 * there's one specified 137 *
144 * - /sbin/request-key will be invoked if _callout_info is non-NULL 138 * If a key is found, it will be attached to the destination keyring if there's
145 * - the _callout_info string will be passed to /sbin/request-key 139 * one specified and the serial number of the key will be returned.
146 * - if the _callout_info string is empty, it will be rendered as "-" 140 *
147 * - implements request_key() 141 * If no key is found, /sbin/request-key will be invoked if _callout_info is
142 * non-NULL in an attempt to create a key. The _callout_info string will be
143 * passed to /sbin/request-key to aid with completing the request. If the
144 * _callout_info string is "" then it will be changed to "-".
148 */ 145 */
149SYSCALL_DEFINE4(request_key, const char __user *, _type, 146SYSCALL_DEFINE4(request_key, const char __user *, _type,
150 const char __user *, _description, 147 const char __user *, _description,
@@ -209,8 +206,14 @@ SYSCALL_DEFINE4(request_key, const char __user *, _type,
209 goto error5; 206 goto error5;
210 } 207 }
211 208
209 /* wait for the key to finish being constructed */
210 ret = wait_for_key_construction(key, 1);
211 if (ret < 0)
212 goto error6;
213
212 ret = key->serial; 214 ret = key->serial;
213 215
216error6:
214 key_put(key); 217 key_put(key);
215error5: 218error5:
216 key_type_put(ktype); 219 key_type_put(ktype);
@@ -222,14 +225,14 @@ error2:
222 kfree(description); 225 kfree(description);
223error: 226error:
224 return ret; 227 return ret;
228}
225 229
226} /* end sys_request_key() */
227
228/*****************************************************************************/
229/* 230/*
230 * get the ID of the specified process keyring 231 * Get the ID of the specified process keyring.
231 * - the keyring must have search permission to be found 232 *
232 * - implements keyctl(KEYCTL_GET_KEYRING_ID) 233 * The requested keyring must have search permission to be found.
234 *
235 * If successful, the ID of the requested keyring will be returned.
233 */ 236 */
234long keyctl_get_keyring_ID(key_serial_t id, int create) 237long keyctl_get_keyring_ID(key_serial_t id, int create)
235{ 238{
@@ -248,13 +251,17 @@ long keyctl_get_keyring_ID(key_serial_t id, int create)
248 key_ref_put(key_ref); 251 key_ref_put(key_ref);
249error: 252error:
250 return ret; 253 return ret;
254}
251 255
252} /* end keyctl_get_keyring_ID() */
253
254/*****************************************************************************/
255/* 256/*
256 * join the session keyring 257 * Join a (named) session keyring.
257 * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING) 258 *
259 * Create and join an anonymous session keyring or join a named session
260 * keyring, creating it if necessary. A named session keyring must have Search
261 * permission for it to be joined. Session keyrings without this permit will
262 * be skipped over.
263 *
264 * If successful, the ID of the joined session keyring will be returned.
258 */ 265 */
259long keyctl_join_session_keyring(const char __user *_name) 266long keyctl_join_session_keyring(const char __user *_name)
260{ 267{
@@ -277,14 +284,17 @@ long keyctl_join_session_keyring(const char __user *_name)
277 284
278error: 285error:
279 return ret; 286 return ret;
287}
280 288
281} /* end keyctl_join_session_keyring() */
282
283/*****************************************************************************/
284/* 289/*
285 * update a key's data payload 290 * Update a key's data payload from the given data.
286 * - the key must be writable 291 *
287 * - implements keyctl(KEYCTL_UPDATE) 292 * The key must grant the caller Write permission and the key type must support
293 * updating for this to work. A negative key can be positively instantiated
294 * with this call.
295 *
296 * If successful, 0 will be returned. If the key type does not support
297 * updating, then -EOPNOTSUPP will be returned.
288 */ 298 */
289long keyctl_update_key(key_serial_t id, 299long keyctl_update_key(key_serial_t id,
290 const void __user *_payload, 300 const void __user *_payload,
@@ -326,14 +336,17 @@ error2:
326 kfree(payload); 336 kfree(payload);
327error: 337error:
328 return ret; 338 return ret;
339}
329 340
330} /* end keyctl_update_key() */
331
332/*****************************************************************************/
333/* 341/*
334 * revoke a key 342 * Revoke a key.
335 * - the key must be writable 343 *
336 * - implements keyctl(KEYCTL_REVOKE) 344 * The key must be grant the caller Write or Setattr permission for this to
345 * work. The key type should give up its quota claim when revoked. The key
346 * and any links to the key will be automatically garbage collected after a
347 * certain amount of time (/proc/sys/kernel/keys/gc_delay).
348 *
349 * If successful, 0 is returned.
337 */ 350 */
338long keyctl_revoke_key(key_serial_t id) 351long keyctl_revoke_key(key_serial_t id)
339{ 352{
@@ -358,14 +371,14 @@ long keyctl_revoke_key(key_serial_t id)
358 key_ref_put(key_ref); 371 key_ref_put(key_ref);
359error: 372error:
360 return ret; 373 return ret;
374}
361 375
362} /* end keyctl_revoke_key() */
363
364/*****************************************************************************/
365/* 376/*
366 * clear the specified process keyring 377 * Clear the specified keyring, creating an empty process keyring if one of the
367 * - the keyring must be writable 378 * special keyring IDs is used.
368 * - implements keyctl(KEYCTL_CLEAR) 379 *
380 * The keyring must grant the caller Write permission for this to work. If
381 * successful, 0 will be returned.
369 */ 382 */
370long keyctl_keyring_clear(key_serial_t ringid) 383long keyctl_keyring_clear(key_serial_t ringid)
371{ 384{
@@ -383,15 +396,18 @@ long keyctl_keyring_clear(key_serial_t ringid)
383 key_ref_put(keyring_ref); 396 key_ref_put(keyring_ref);
384error: 397error:
385 return ret; 398 return ret;
399}
386 400
387} /* end keyctl_keyring_clear() */
388
389/*****************************************************************************/
390/* 401/*
391 * link a key into a keyring 402 * Create a link from a keyring to a key if there's no matching key in the
392 * - the keyring must be writable 403 * keyring, otherwise replace the link to the matching key with a link to the
393 * - the key must be linkable 404 * new key.
394 * - implements keyctl(KEYCTL_LINK) 405 *
406 * The key must grant the caller Link permission and the the keyring must grant
407 * the caller Write permission. Furthermore, if an additional link is created,
408 * the keyring's quota will be extended.
409 *
410 * If successful, 0 will be returned.
395 */ 411 */
396long keyctl_keyring_link(key_serial_t id, key_serial_t ringid) 412long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
397{ 413{
@@ -417,15 +433,16 @@ error2:
417 key_ref_put(keyring_ref); 433 key_ref_put(keyring_ref);
418error: 434error:
419 return ret; 435 return ret;
436}
420 437
421} /* end keyctl_keyring_link() */
422
423/*****************************************************************************/
424/* 438/*
425 * unlink the first attachment of a key from a keyring 439 * Unlink a key from a keyring.
426 * - the keyring must be writable 440 *
427 * - we don't need any permissions on the key 441 * The keyring must grant the caller Write permission for this to work; the key
428 * - implements keyctl(KEYCTL_UNLINK) 442 * itself need not grant the caller anything. If the last link to a key is
443 * removed then that key will be scheduled for destruction.
444 *
445 * If successful, 0 will be returned.
429 */ 446 */
430long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid) 447long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
431{ 448{
@@ -451,19 +468,20 @@ error2:
451 key_ref_put(keyring_ref); 468 key_ref_put(keyring_ref);
452error: 469error:
453 return ret; 470 return ret;
471}
454 472
455} /* end keyctl_keyring_unlink() */
456
457/*****************************************************************************/
458/* 473/*
459 * describe a user key 474 * Return a description of a key to userspace.
460 * - the key must have view permission 475 *
461 * - if there's a buffer, we place up to buflen bytes of data into it 476 * The key must grant the caller View permission for this to work.
462 * - unless there's an error, we return the amount of description available, 477 *
463 * irrespective of how much we may have copied 478 * If there's a buffer, we place up to buflen bytes of data into it formatted
464 * - the description is formatted thus: 479 * in the following way:
480 *
465 * type;uid;gid;perm;description<NUL> 481 * type;uid;gid;perm;description<NUL>
466 * - implements keyctl(KEYCTL_DESCRIBE) 482 *
483 * If successful, we return the amount of description available, irrespective
484 * of how much we may have copied into the buffer.
467 */ 485 */
468long keyctl_describe_key(key_serial_t keyid, 486long keyctl_describe_key(key_serial_t keyid,
469 char __user *buffer, 487 char __user *buffer,
@@ -531,18 +549,17 @@ error2:
531 key_ref_put(key_ref); 549 key_ref_put(key_ref);
532error: 550error:
533 return ret; 551 return ret;
552}
534 553
535} /* end keyctl_describe_key() */
536
537/*****************************************************************************/
538/* 554/*
539 * search the specified keyring for a matching key 555 * Search the specified keyring and any keyrings it links to for a matching
540 * - the start keyring must be searchable 556 * key. Only keyrings that grant the caller Search permission will be searched
541 * - nested keyrings may also be searched if they are searchable 557 * (this includes the starting keyring). Only keys with Search permission can
542 * - only keys with search permission may be found 558 * be found.
543 * - if a key is found, it will be attached to the destination keyring if 559 *
544 * there's one specified 560 * If successful, the found key will be linked to the destination keyring if
545 * - implements keyctl(KEYCTL_SEARCH) 561 * supplied and the key has Link permission, and the found key ID will be
562 * returned.
546 */ 563 */
547long keyctl_keyring_search(key_serial_t ringid, 564long keyctl_keyring_search(key_serial_t ringid,
548 const char __user *_type, 565 const char __user *_type,
@@ -626,18 +643,17 @@ error2:
626 kfree(description); 643 kfree(description);
627error: 644error:
628 return ret; 645 return ret;
646}
629 647
630} /* end keyctl_keyring_search() */
631
632/*****************************************************************************/
633/* 648/*
634 * read a user key's payload 649 * Read a key's payload.
635 * - the keyring must be readable or the key must be searchable from the 650 *
636 * process's keyrings 651 * The key must either grant the caller Read permission, or it must grant the
637 * - if there's a buffer, we place up to buflen bytes of data into it 652 * caller Search permission when searched for from the process keyrings.
638 * - unless there's an error, we return the amount of data in the key, 653 *
639 * irrespective of how much we may have copied 654 * If successful, we place up to buflen bytes of data into the buffer, if one
640 * - implements keyctl(KEYCTL_READ) 655 * is provided, and return the amount of data that is available in the key,
656 * irrespective of how much we copied into the buffer.
641 */ 657 */
642long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen) 658long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
643{ 659{
@@ -688,15 +704,22 @@ error2:
688 key_put(key); 704 key_put(key);
689error: 705error:
690 return ret; 706 return ret;
707}
691 708
692} /* end keyctl_read_key() */
693
694/*****************************************************************************/
695/* 709/*
696 * change the ownership of a key 710 * Change the ownership of a key
697 * - the keyring owned by the changer 711 *
698 * - if the uid or gid is -1, then that parameter is not changed 712 * The key must grant the caller Setattr permission for this to work, though
699 * - implements keyctl(KEYCTL_CHOWN) 713 * the key need not be fully instantiated yet. For the UID to be changed, or
714 * for the GID to be changed to a group the caller is not a member of, the
715 * caller must have sysadmin capability. If either uid or gid is -1 then that
716 * attribute is not changed.
717 *
718 * If the UID is to be changed, the new user must have sufficient quota to
719 * accept the key. The quota deduction will be removed from the old user to
720 * the new user should the attribute be changed.
721 *
722 * If successful, 0 will be returned.
700 */ 723 */
701long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) 724long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
702{ 725{
@@ -796,14 +819,14 @@ quota_overrun:
796 zapowner = newowner; 819 zapowner = newowner;
797 ret = -EDQUOT; 820 ret = -EDQUOT;
798 goto error_put; 821 goto error_put;
822}
799 823
800} /* end keyctl_chown_key() */
801
802/*****************************************************************************/
803/* 824/*
804 * change the permission mask on a key 825 * Change the permission mask on a key.
805 * - the keyring owned by the changer 826 *
806 * - implements keyctl(KEYCTL_SETPERM) 827 * The key must grant the caller Setattr permission for this to work, though
828 * the key need not be fully instantiated yet. If the caller does not have
829 * sysadmin capability, it may only change the permission on keys that it owns.
807 */ 830 */
808long keyctl_setperm_key(key_serial_t id, key_perm_t perm) 831long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
809{ 832{
@@ -838,11 +861,11 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
838 key_put(key); 861 key_put(key);
839error: 862error:
840 return ret; 863 return ret;
841 864}
842} /* end keyctl_setperm_key() */
843 865
844/* 866/*
845 * get the destination keyring for instantiation 867 * Get the destination keyring for instantiation and check that the caller has
868 * Write permission on it.
846 */ 869 */
847static long get_instantiation_keyring(key_serial_t ringid, 870static long get_instantiation_keyring(key_serial_t ringid,
848 struct request_key_auth *rka, 871 struct request_key_auth *rka,
@@ -879,7 +902,7 @@ static long get_instantiation_keyring(key_serial_t ringid,
879} 902}
880 903
881/* 904/*
882 * change the request_key authorisation key on the current process 905 * Change the request_key authorisation key on the current process.
883 */ 906 */
884static int keyctl_change_reqkey_auth(struct key *key) 907static int keyctl_change_reqkey_auth(struct key *key)
885{ 908{
@@ -895,15 +918,35 @@ static int keyctl_change_reqkey_auth(struct key *key)
895 return commit_creds(new); 918 return commit_creds(new);
896} 919}
897 920
898/*****************************************************************************/
899/* 921/*
900 * instantiate the key with the specified payload, and, if one is given, link 922 * Copy the iovec data from userspace
901 * the key into the keyring
902 */ 923 */
903long keyctl_instantiate_key(key_serial_t id, 924static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
904 const void __user *_payload, 925 unsigned ioc)
905 size_t plen, 926{
906 key_serial_t ringid) 927 for (; ioc > 0; ioc--) {
928 if (copy_from_user(buffer, iov->iov_base, iov->iov_len) != 0)
929 return -EFAULT;
930 buffer += iov->iov_len;
931 iov++;
932 }
933 return 0;
934}
935
936/*
937 * Instantiate a key with the specified payload and link the key into the
938 * destination keyring if one is given.
939 *
940 * The caller must have the appropriate instantiation permit set for this to
941 * work (see keyctl_assume_authority). No other permissions are required.
942 *
943 * If successful, 0 will be returned.
944 */
945long keyctl_instantiate_key_common(key_serial_t id,
946 const struct iovec *payload_iov,
947 unsigned ioc,
948 size_t plen,
949 key_serial_t ringid)
907{ 950{
908 const struct cred *cred = current_cred(); 951 const struct cred *cred = current_cred();
909 struct request_key_auth *rka; 952 struct request_key_auth *rka;
@@ -932,7 +975,7 @@ long keyctl_instantiate_key(key_serial_t id,
932 /* pull the payload in if one was supplied */ 975 /* pull the payload in if one was supplied */
933 payload = NULL; 976 payload = NULL;
934 977
935 if (_payload) { 978 if (payload_iov) {
936 ret = -ENOMEM; 979 ret = -ENOMEM;
937 payload = kmalloc(plen, GFP_KERNEL); 980 payload = kmalloc(plen, GFP_KERNEL);
938 if (!payload) { 981 if (!payload) {
@@ -944,8 +987,8 @@ long keyctl_instantiate_key(key_serial_t id,
944 goto error; 987 goto error;
945 } 988 }
946 989
947 ret = -EFAULT; 990 ret = copy_from_user_iovec(payload, payload_iov, ioc);
948 if (copy_from_user(payload, _payload, plen) != 0) 991 if (ret < 0)
949 goto error2; 992 goto error2;
950 } 993 }
951 994
@@ -973,22 +1016,127 @@ error2:
973 vfree(payload); 1016 vfree(payload);
974error: 1017error:
975 return ret; 1018 return ret;
1019}
1020
1021/*
1022 * Instantiate a key with the specified payload and link the key into the
1023 * destination keyring if one is given.
1024 *
1025 * The caller must have the appropriate instantiation permit set for this to
1026 * work (see keyctl_assume_authority). No other permissions are required.
1027 *
1028 * If successful, 0 will be returned.
1029 */
1030long keyctl_instantiate_key(key_serial_t id,
1031 const void __user *_payload,
1032 size_t plen,
1033 key_serial_t ringid)
1034{
1035 if (_payload && plen) {
1036 struct iovec iov[1] = {
1037 [0].iov_base = (void __user *)_payload,
1038 [0].iov_len = plen
1039 };
976 1040
977} /* end keyctl_instantiate_key() */ 1041 return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
1042 }
1043
1044 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
1045}
978 1046
979/*****************************************************************************/
980/* 1047/*
981 * negatively instantiate the key with the given timeout (in seconds), and, if 1048 * Instantiate a key with the specified multipart payload and link the key into
982 * one is given, link the key into the keyring 1049 * the destination keyring if one is given.
1050 *
1051 * The caller must have the appropriate instantiation permit set for this to
1052 * work (see keyctl_assume_authority). No other permissions are required.
1053 *
1054 * If successful, 0 will be returned.
1055 */
1056long keyctl_instantiate_key_iov(key_serial_t id,
1057 const struct iovec __user *_payload_iov,
1058 unsigned ioc,
1059 key_serial_t ringid)
1060{
1061 struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
1062 long ret;
1063
1064 if (_payload_iov == 0 || ioc == 0)
1065 goto no_payload;
1066
1067 ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc,
1068 ARRAY_SIZE(iovstack), iovstack, &iov);
1069 if (ret < 0)
1070 return ret;
1071 if (ret == 0)
1072 goto no_payload_free;
1073
1074 ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
1075
1076 if (iov != iovstack)
1077 kfree(iov);
1078 return ret;
1079
1080no_payload_free:
1081 if (iov != iovstack)
1082 kfree(iov);
1083no_payload:
1084 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
1085}
1086
1087/*
1088 * Negatively instantiate the key with the given timeout (in seconds) and link
1089 * the key into the destination keyring if one is given.
1090 *
1091 * The caller must have the appropriate instantiation permit set for this to
1092 * work (see keyctl_assume_authority). No other permissions are required.
1093 *
1094 * The key and any links to the key will be automatically garbage collected
1095 * after the timeout expires.
1096 *
1097 * Negative keys are used to rate limit repeated request_key() calls by causing
1098 * them to return -ENOKEY until the negative key expires.
1099 *
1100 * If successful, 0 will be returned.
983 */ 1101 */
984long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) 1102long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
985{ 1103{
1104 return keyctl_reject_key(id, timeout, ENOKEY, ringid);
1105}
1106
1107/*
1108 * Negatively instantiate the key with the given timeout (in seconds) and error
1109 * code and link the key into the destination keyring if one is given.
1110 *
1111 * The caller must have the appropriate instantiation permit set for this to
1112 * work (see keyctl_assume_authority). No other permissions are required.
1113 *
1114 * The key and any links to the key will be automatically garbage collected
1115 * after the timeout expires.
1116 *
1117 * Negative keys are used to rate limit repeated request_key() calls by causing
1118 * them to return the specified error code until the negative key expires.
1119 *
1120 * If successful, 0 will be returned.
1121 */
1122long keyctl_reject_key(key_serial_t id, unsigned timeout, unsigned error,
1123 key_serial_t ringid)
1124{
986 const struct cred *cred = current_cred(); 1125 const struct cred *cred = current_cred();
987 struct request_key_auth *rka; 1126 struct request_key_auth *rka;
988 struct key *instkey, *dest_keyring; 1127 struct key *instkey, *dest_keyring;
989 long ret; 1128 long ret;
990 1129
991 kenter("%d,%u,%d", id, timeout, ringid); 1130 kenter("%d,%u,%u,%d", id, timeout, error, ringid);
1131
1132 /* must be a valid error code and mustn't be a kernel special */
1133 if (error <= 0 ||
1134 error >= MAX_ERRNO ||
1135 error == ERESTARTSYS ||
1136 error == ERESTARTNOINTR ||
1137 error == ERESTARTNOHAND ||
1138 error == ERESTART_RESTARTBLOCK)
1139 return -EINVAL;
992 1140
993 /* the appropriate instantiation authorisation key must have been 1141 /* the appropriate instantiation authorisation key must have been
994 * assumed before calling this */ 1142 * assumed before calling this */
@@ -1008,7 +1156,7 @@ long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
1008 goto error; 1156 goto error;
1009 1157
1010 /* instantiate the key and link it into a keyring */ 1158 /* instantiate the key and link it into a keyring */
1011 ret = key_negate_and_link(rka->target_key, timeout, 1159 ret = key_reject_and_link(rka->target_key, timeout, error,
1012 dest_keyring, instkey); 1160 dest_keyring, instkey);
1013 1161
1014 key_put(dest_keyring); 1162 key_put(dest_keyring);
@@ -1020,13 +1168,14 @@ long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
1020 1168
1021error: 1169error:
1022 return ret; 1170 return ret;
1171}
1023 1172
1024} /* end keyctl_negate_key() */
1025
1026/*****************************************************************************/
1027/* 1173/*
1028 * set the default keyring in which request_key() will cache keys 1174 * Read or set the default keyring in which request_key() will cache keys and
1029 * - return the old setting 1175 * return the old setting.
1176 *
1177 * If a process keyring is specified then this will be created if it doesn't
1178 * yet exist. The old setting will be returned if successful.
1030 */ 1179 */
1031long keyctl_set_reqkey_keyring(int reqkey_defl) 1180long keyctl_set_reqkey_keyring(int reqkey_defl)
1032{ 1181{
@@ -1079,12 +1228,19 @@ set:
1079error: 1228error:
1080 abort_creds(new); 1229 abort_creds(new);
1081 return ret; 1230 return ret;
1231}
1082 1232
1083} /* end keyctl_set_reqkey_keyring() */
1084
1085/*****************************************************************************/
1086/* 1233/*
1087 * set or clear the timeout for a key 1234 * Set or clear the timeout on a key.
1235 *
1236 * Either the key must grant the caller Setattr permission or else the caller
1237 * must hold an instantiation authorisation token for the key.
1238 *
1239 * The timeout is either 0 to clear the timeout, or a number of seconds from
1240 * the current time. The key and any links to the key will be automatically
1241 * garbage collected after the timeout expires.
1242 *
1243 * If successful, 0 is returned.
1088 */ 1244 */
1089long keyctl_set_timeout(key_serial_t id, unsigned timeout) 1245long keyctl_set_timeout(key_serial_t id, unsigned timeout)
1090{ 1246{
@@ -1136,12 +1292,24 @@ okay:
1136 ret = 0; 1292 ret = 0;
1137error: 1293error:
1138 return ret; 1294 return ret;
1295}
1139 1296
1140} /* end keyctl_set_timeout() */
1141
1142/*****************************************************************************/
1143/* 1297/*
1144 * assume the authority to instantiate the specified key 1298 * Assume (or clear) the authority to instantiate the specified key.
1299 *
1300 * This sets the authoritative token currently in force for key instantiation.
1301 * This must be done for a key to be instantiated. It has the effect of making
1302 * available all the keys from the caller of the request_key() that created a
1303 * key to request_key() calls made by the caller of this function.
1304 *
1305 * The caller must have the instantiation key in their process keyrings with a
1306 * Search permission grant available to the caller.
1307 *
1308 * If the ID given is 0, then the setting will be cleared and 0 returned.
1309 *
1310 * If the ID given has a matching an authorisation key, then that key will be
1311 * set and its ID will be returned. The authorisation key can be read to get
1312 * the callout information passed to request_key().
1145 */ 1313 */
1146long keyctl_assume_authority(key_serial_t id) 1314long keyctl_assume_authority(key_serial_t id)
1147{ 1315{
@@ -1178,16 +1346,17 @@ long keyctl_assume_authority(key_serial_t id)
1178 ret = authkey->serial; 1346 ret = authkey->serial;
1179error: 1347error:
1180 return ret; 1348 return ret;
1181 1349}
1182} /* end keyctl_assume_authority() */
1183 1350
1184/* 1351/*
1185 * get the security label of a key 1352 * Get a key's the LSM security label.
1186 * - the key must grant us view permission 1353 *
1187 * - if there's a buffer, we place up to buflen bytes of data into it 1354 * The key must grant the caller View permission for this to work.
1188 * - unless there's an error, we return the amount of information available, 1355 *
1189 * irrespective of how much we may have copied (including the terminal NUL) 1356 * If there's a buffer, then up to buflen bytes of data will be placed into it.
1190 * - implements keyctl(KEYCTL_GET_SECURITY) 1357 *
1358 * If successful, the amount of information available will be returned,
1359 * irrespective of how much was copied (including the terminal NUL).
1191 */ 1360 */
1192long keyctl_get_security(key_serial_t keyid, 1361long keyctl_get_security(key_serial_t keyid,
1193 char __user *buffer, 1362 char __user *buffer,
@@ -1242,10 +1411,16 @@ long keyctl_get_security(key_serial_t keyid,
1242} 1411}
1243 1412
1244/* 1413/*
1245 * attempt to install the calling process's session keyring on the process's 1414 * Attempt to install the calling process's session keyring on the process's
1246 * parent process 1415 * parent process.
1247 * - the keyring must exist and must grant us LINK permission 1416 *
1248 * - implements keyctl(KEYCTL_SESSION_TO_PARENT) 1417 * The keyring must exist and must grant the caller LINK permission, and the
1418 * parent process must be single-threaded and must have the same effective
1419 * ownership as this process and mustn't be SUID/SGID.
1420 *
1421 * The keyring will be emplaced on the parent when it next resumes userspace.
1422 *
1423 * If successful, 0 will be returned.
1249 */ 1424 */
1250long keyctl_session_to_parent(void) 1425long keyctl_session_to_parent(void)
1251{ 1426{
@@ -1348,9 +1523,8 @@ error_keyring:
1348#endif /* !TIF_NOTIFY_RESUME */ 1523#endif /* !TIF_NOTIFY_RESUME */
1349} 1524}
1350 1525
1351/*****************************************************************************/
1352/* 1526/*
1353 * the key control system call 1527 * The key control system call
1354 */ 1528 */
1355SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, 1529SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
1356 unsigned long, arg4, unsigned long, arg5) 1530 unsigned long, arg4, unsigned long, arg5)
@@ -1436,8 +1610,20 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
1436 case KEYCTL_SESSION_TO_PARENT: 1610 case KEYCTL_SESSION_TO_PARENT:
1437 return keyctl_session_to_parent(); 1611 return keyctl_session_to_parent();
1438 1612
1613 case KEYCTL_REJECT:
1614 return keyctl_reject_key((key_serial_t) arg2,
1615 (unsigned) arg3,
1616 (unsigned) arg4,
1617 (key_serial_t) arg5);
1618
1619 case KEYCTL_INSTANTIATE_IOV:
1620 return keyctl_instantiate_key_iov(
1621 (key_serial_t) arg2,
1622 (const struct iovec __user *) arg3,
1623 (unsigned) arg4,
1624 (key_serial_t) arg5);
1625
1439 default: 1626 default:
1440 return -EOPNOTSUPP; 1627 return -EOPNOTSUPP;
1441 } 1628 }
1442 1629}
1443} /* end sys_keyctl() */