diff options
Diffstat (limited to 'security/keys/keyctl.c')
-rw-r--r-- | security/keys/keyctl.c | 355 |
1 files changed, 205 insertions, 150 deletions
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c index 60924f6a52db..31a0fd8189f1 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 | */ |
57 | SYSCALL_DEFINE5(add_key, const char __user *, _type, | 53 | SYSCALL_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 | */ |
149 | SYSCALL_DEFINE4(request_key, const char __user *, _type, | 146 | SYSCALL_DEFINE4(request_key, const char __user *, _type, |
150 | const char __user *, _description, | 147 | const char __user *, _description, |
@@ -222,14 +219,14 @@ error2: | |||
222 | kfree(description); | 219 | kfree(description); |
223 | error: | 220 | error: |
224 | return ret; | 221 | return ret; |
222 | } | ||
225 | 223 | ||
226 | } /* end sys_request_key() */ | ||
227 | |||
228 | /*****************************************************************************/ | ||
229 | /* | 224 | /* |
230 | * get the ID of the specified process keyring | 225 | * Get the ID of the specified process keyring. |
231 | * - the keyring must have search permission to be found | 226 | * |
232 | * - implements keyctl(KEYCTL_GET_KEYRING_ID) | 227 | * The requested keyring must have search permission to be found. |
228 | * | ||
229 | * If successful, the ID of the requested keyring will be returned. | ||
233 | */ | 230 | */ |
234 | long keyctl_get_keyring_ID(key_serial_t id, int create) | 231 | long keyctl_get_keyring_ID(key_serial_t id, int create) |
235 | { | 232 | { |
@@ -248,13 +245,17 @@ long keyctl_get_keyring_ID(key_serial_t id, int create) | |||
248 | key_ref_put(key_ref); | 245 | key_ref_put(key_ref); |
249 | error: | 246 | error: |
250 | return ret; | 247 | return ret; |
248 | } | ||
251 | 249 | ||
252 | } /* end keyctl_get_keyring_ID() */ | ||
253 | |||
254 | /*****************************************************************************/ | ||
255 | /* | 250 | /* |
256 | * join the session keyring | 251 | * Join a (named) session keyring. |
257 | * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING) | 252 | * |
253 | * Create and join an anonymous session keyring or join a named session | ||
254 | * keyring, creating it if necessary. A named session keyring must have Search | ||
255 | * permission for it to be joined. Session keyrings without this permit will | ||
256 | * be skipped over. | ||
257 | * | ||
258 | * If successful, the ID of the joined session keyring will be returned. | ||
258 | */ | 259 | */ |
259 | long keyctl_join_session_keyring(const char __user *_name) | 260 | long keyctl_join_session_keyring(const char __user *_name) |
260 | { | 261 | { |
@@ -277,14 +278,17 @@ long keyctl_join_session_keyring(const char __user *_name) | |||
277 | 278 | ||
278 | error: | 279 | error: |
279 | return ret; | 280 | return ret; |
281 | } | ||
280 | 282 | ||
281 | } /* end keyctl_join_session_keyring() */ | ||
282 | |||
283 | /*****************************************************************************/ | ||
284 | /* | 283 | /* |
285 | * update a key's data payload | 284 | * Update a key's data payload from the given data. |
286 | * - the key must be writable | 285 | * |
287 | * - implements keyctl(KEYCTL_UPDATE) | 286 | * The key must grant the caller Write permission and the key type must support |
287 | * updating for this to work. A negative key can be positively instantiated | ||
288 | * with this call. | ||
289 | * | ||
290 | * If successful, 0 will be returned. If the key type does not support | ||
291 | * updating, then -EOPNOTSUPP will be returned. | ||
288 | */ | 292 | */ |
289 | long keyctl_update_key(key_serial_t id, | 293 | long keyctl_update_key(key_serial_t id, |
290 | const void __user *_payload, | 294 | const void __user *_payload, |
@@ -326,14 +330,17 @@ error2: | |||
326 | kfree(payload); | 330 | kfree(payload); |
327 | error: | 331 | error: |
328 | return ret; | 332 | return ret; |
333 | } | ||
329 | 334 | ||
330 | } /* end keyctl_update_key() */ | ||
331 | |||
332 | /*****************************************************************************/ | ||
333 | /* | 335 | /* |
334 | * revoke a key | 336 | * Revoke a key. |
335 | * - the key must be writable | 337 | * |
336 | * - implements keyctl(KEYCTL_REVOKE) | 338 | * The key must be grant the caller Write or Setattr permission for this to |
339 | * work. The key type should give up its quota claim when revoked. The key | ||
340 | * and any links to the key will be automatically garbage collected after a | ||
341 | * certain amount of time (/proc/sys/kernel/keys/gc_delay). | ||
342 | * | ||
343 | * If successful, 0 is returned. | ||
337 | */ | 344 | */ |
338 | long keyctl_revoke_key(key_serial_t id) | 345 | long keyctl_revoke_key(key_serial_t id) |
339 | { | 346 | { |
@@ -358,14 +365,14 @@ long keyctl_revoke_key(key_serial_t id) | |||
358 | key_ref_put(key_ref); | 365 | key_ref_put(key_ref); |
359 | error: | 366 | error: |
360 | return ret; | 367 | return ret; |
368 | } | ||
361 | 369 | ||
362 | } /* end keyctl_revoke_key() */ | ||
363 | |||
364 | /*****************************************************************************/ | ||
365 | /* | 370 | /* |
366 | * clear the specified process keyring | 371 | * Clear the specified keyring, creating an empty process keyring if one of the |
367 | * - the keyring must be writable | 372 | * special keyring IDs is used. |
368 | * - implements keyctl(KEYCTL_CLEAR) | 373 | * |
374 | * The keyring must grant the caller Write permission for this to work. If | ||
375 | * successful, 0 will be returned. | ||
369 | */ | 376 | */ |
370 | long keyctl_keyring_clear(key_serial_t ringid) | 377 | long keyctl_keyring_clear(key_serial_t ringid) |
371 | { | 378 | { |
@@ -383,15 +390,18 @@ long keyctl_keyring_clear(key_serial_t ringid) | |||
383 | key_ref_put(keyring_ref); | 390 | key_ref_put(keyring_ref); |
384 | error: | 391 | error: |
385 | return ret; | 392 | return ret; |
393 | } | ||
386 | 394 | ||
387 | } /* end keyctl_keyring_clear() */ | ||
388 | |||
389 | /*****************************************************************************/ | ||
390 | /* | 395 | /* |
391 | * link a key into a keyring | 396 | * Create a link from a keyring to a key if there's no matching key in the |
392 | * - the keyring must be writable | 397 | * keyring, otherwise replace the link to the matching key with a link to the |
393 | * - the key must be linkable | 398 | * new key. |
394 | * - implements keyctl(KEYCTL_LINK) | 399 | * |
400 | * The key must grant the caller Link permission and the the keyring must grant | ||
401 | * the caller Write permission. Furthermore, if an additional link is created, | ||
402 | * the keyring's quota will be extended. | ||
403 | * | ||
404 | * If successful, 0 will be returned. | ||
395 | */ | 405 | */ |
396 | long keyctl_keyring_link(key_serial_t id, key_serial_t ringid) | 406 | long keyctl_keyring_link(key_serial_t id, key_serial_t ringid) |
397 | { | 407 | { |
@@ -417,15 +427,16 @@ error2: | |||
417 | key_ref_put(keyring_ref); | 427 | key_ref_put(keyring_ref); |
418 | error: | 428 | error: |
419 | return ret; | 429 | return ret; |
430 | } | ||
420 | 431 | ||
421 | } /* end keyctl_keyring_link() */ | ||
422 | |||
423 | /*****************************************************************************/ | ||
424 | /* | 432 | /* |
425 | * unlink the first attachment of a key from a keyring | 433 | * Unlink a key from a keyring. |
426 | * - the keyring must be writable | 434 | * |
427 | * - we don't need any permissions on the key | 435 | * The keyring must grant the caller Write permission for this to work; the key |
428 | * - implements keyctl(KEYCTL_UNLINK) | 436 | * itself need not grant the caller anything. If the last link to a key is |
437 | * removed then that key will be scheduled for destruction. | ||
438 | * | ||
439 | * If successful, 0 will be returned. | ||
429 | */ | 440 | */ |
430 | long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid) | 441 | long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid) |
431 | { | 442 | { |
@@ -451,19 +462,20 @@ error2: | |||
451 | key_ref_put(keyring_ref); | 462 | key_ref_put(keyring_ref); |
452 | error: | 463 | error: |
453 | return ret; | 464 | return ret; |
465 | } | ||
454 | 466 | ||
455 | } /* end keyctl_keyring_unlink() */ | ||
456 | |||
457 | /*****************************************************************************/ | ||
458 | /* | 467 | /* |
459 | * describe a user key | 468 | * Return a description of a key to userspace. |
460 | * - the key must have view permission | 469 | * |
461 | * - if there's a buffer, we place up to buflen bytes of data into it | 470 | * 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, | 471 | * |
463 | * irrespective of how much we may have copied | 472 | * If there's a buffer, we place up to buflen bytes of data into it formatted |
464 | * - the description is formatted thus: | 473 | * in the following way: |
474 | * | ||
465 | * type;uid;gid;perm;description<NUL> | 475 | * type;uid;gid;perm;description<NUL> |
466 | * - implements keyctl(KEYCTL_DESCRIBE) | 476 | * |
477 | * If successful, we return the amount of description available, irrespective | ||
478 | * of how much we may have copied into the buffer. | ||
467 | */ | 479 | */ |
468 | long keyctl_describe_key(key_serial_t keyid, | 480 | long keyctl_describe_key(key_serial_t keyid, |
469 | char __user *buffer, | 481 | char __user *buffer, |
@@ -531,18 +543,17 @@ error2: | |||
531 | key_ref_put(key_ref); | 543 | key_ref_put(key_ref); |
532 | error: | 544 | error: |
533 | return ret; | 545 | return ret; |
546 | } | ||
534 | 547 | ||
535 | } /* end keyctl_describe_key() */ | ||
536 | |||
537 | /*****************************************************************************/ | ||
538 | /* | 548 | /* |
539 | * search the specified keyring for a matching key | 549 | * Search the specified keyring and any keyrings it links to for a matching |
540 | * - the start keyring must be searchable | 550 | * key. Only keyrings that grant the caller Search permission will be searched |
541 | * - nested keyrings may also be searched if they are searchable | 551 | * (this includes the starting keyring). Only keys with Search permission can |
542 | * - only keys with search permission may be found | 552 | * be found. |
543 | * - if a key is found, it will be attached to the destination keyring if | 553 | * |
544 | * there's one specified | 554 | * If successful, the found key will be linked to the destination keyring if |
545 | * - implements keyctl(KEYCTL_SEARCH) | 555 | * supplied and the key has Link permission, and the found key ID will be |
556 | * returned. | ||
546 | */ | 557 | */ |
547 | long keyctl_keyring_search(key_serial_t ringid, | 558 | long keyctl_keyring_search(key_serial_t ringid, |
548 | const char __user *_type, | 559 | const char __user *_type, |
@@ -626,18 +637,17 @@ error2: | |||
626 | kfree(description); | 637 | kfree(description); |
627 | error: | 638 | error: |
628 | return ret; | 639 | return ret; |
640 | } | ||
629 | 641 | ||
630 | } /* end keyctl_keyring_search() */ | ||
631 | |||
632 | /*****************************************************************************/ | ||
633 | /* | 642 | /* |
634 | * read a user key's payload | 643 | * Read a key's payload. |
635 | * - the keyring must be readable or the key must be searchable from the | 644 | * |
636 | * process's keyrings | 645 | * 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 | 646 | * 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, | 647 | * |
639 | * irrespective of how much we may have copied | 648 | * If successful, we place up to buflen bytes of data into the buffer, if one |
640 | * - implements keyctl(KEYCTL_READ) | 649 | * is provided, and return the amount of data that is available in the key, |
650 | * irrespective of how much we copied into the buffer. | ||
641 | */ | 651 | */ |
642 | long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen) | 652 | long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen) |
643 | { | 653 | { |
@@ -688,15 +698,22 @@ error2: | |||
688 | key_put(key); | 698 | key_put(key); |
689 | error: | 699 | error: |
690 | return ret; | 700 | return ret; |
701 | } | ||
691 | 702 | ||
692 | } /* end keyctl_read_key() */ | ||
693 | |||
694 | /*****************************************************************************/ | ||
695 | /* | 703 | /* |
696 | * change the ownership of a key | 704 | * Change the ownership of a key |
697 | * - the keyring owned by the changer | 705 | * |
698 | * - if the uid or gid is -1, then that parameter is not changed | 706 | * The key must grant the caller Setattr permission for this to work, though |
699 | * - implements keyctl(KEYCTL_CHOWN) | 707 | * the key need not be fully instantiated yet. For the UID to be changed, or |
708 | * for the GID to be changed to a group the caller is not a member of, the | ||
709 | * caller must have sysadmin capability. If either uid or gid is -1 then that | ||
710 | * attribute is not changed. | ||
711 | * | ||
712 | * If the UID is to be changed, the new user must have sufficient quota to | ||
713 | * accept the key. The quota deduction will be removed from the old user to | ||
714 | * the new user should the attribute be changed. | ||
715 | * | ||
716 | * If successful, 0 will be returned. | ||
700 | */ | 717 | */ |
701 | long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) | 718 | long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) |
702 | { | 719 | { |
@@ -796,14 +813,14 @@ quota_overrun: | |||
796 | zapowner = newowner; | 813 | zapowner = newowner; |
797 | ret = -EDQUOT; | 814 | ret = -EDQUOT; |
798 | goto error_put; | 815 | goto error_put; |
816 | } | ||
799 | 817 | ||
800 | } /* end keyctl_chown_key() */ | ||
801 | |||
802 | /*****************************************************************************/ | ||
803 | /* | 818 | /* |
804 | * change the permission mask on a key | 819 | * Change the permission mask on a key. |
805 | * - the keyring owned by the changer | 820 | * |
806 | * - implements keyctl(KEYCTL_SETPERM) | 821 | * The key must grant the caller Setattr permission for this to work, though |
822 | * the key need not be fully instantiated yet. If the caller does not have | ||
823 | * sysadmin capability, it may only change the permission on keys that it owns. | ||
807 | */ | 824 | */ |
808 | long keyctl_setperm_key(key_serial_t id, key_perm_t perm) | 825 | long keyctl_setperm_key(key_serial_t id, key_perm_t perm) |
809 | { | 826 | { |
@@ -838,11 +855,11 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm) | |||
838 | key_put(key); | 855 | key_put(key); |
839 | error: | 856 | error: |
840 | return ret; | 857 | return ret; |
841 | 858 | } | |
842 | } /* end keyctl_setperm_key() */ | ||
843 | 859 | ||
844 | /* | 860 | /* |
845 | * get the destination keyring for instantiation | 861 | * Get the destination keyring for instantiation and check that the caller has |
862 | * Write permission on it. | ||
846 | */ | 863 | */ |
847 | static long get_instantiation_keyring(key_serial_t ringid, | 864 | static long get_instantiation_keyring(key_serial_t ringid, |
848 | struct request_key_auth *rka, | 865 | struct request_key_auth *rka, |
@@ -879,7 +896,7 @@ static long get_instantiation_keyring(key_serial_t ringid, | |||
879 | } | 896 | } |
880 | 897 | ||
881 | /* | 898 | /* |
882 | * change the request_key authorisation key on the current process | 899 | * Change the request_key authorisation key on the current process. |
883 | */ | 900 | */ |
884 | static int keyctl_change_reqkey_auth(struct key *key) | 901 | static int keyctl_change_reqkey_auth(struct key *key) |
885 | { | 902 | { |
@@ -895,10 +912,14 @@ static int keyctl_change_reqkey_auth(struct key *key) | |||
895 | return commit_creds(new); | 912 | return commit_creds(new); |
896 | } | 913 | } |
897 | 914 | ||
898 | /*****************************************************************************/ | ||
899 | /* | 915 | /* |
900 | * instantiate the key with the specified payload, and, if one is given, link | 916 | * Instantiate a key with the specified payload and link the key into the |
901 | * the key into the keyring | 917 | * destination keyring if one is given. |
918 | * | ||
919 | * The caller must have the appropriate instantiation permit set for this to | ||
920 | * work (see keyctl_assume_authority). No other permissions are required. | ||
921 | * | ||
922 | * If successful, 0 will be returned. | ||
902 | */ | 923 | */ |
903 | long keyctl_instantiate_key(key_serial_t id, | 924 | long keyctl_instantiate_key(key_serial_t id, |
904 | const void __user *_payload, | 925 | const void __user *_payload, |
@@ -973,13 +994,22 @@ error2: | |||
973 | vfree(payload); | 994 | vfree(payload); |
974 | error: | 995 | error: |
975 | return ret; | 996 | return ret; |
997 | } | ||
976 | 998 | ||
977 | } /* end keyctl_instantiate_key() */ | ||
978 | |||
979 | /*****************************************************************************/ | ||
980 | /* | 999 | /* |
981 | * negatively instantiate the key with the given timeout (in seconds), and, if | 1000 | * Negatively instantiate the key with the given timeout (in seconds) and link |
982 | * one is given, link the key into the keyring | 1001 | * the key into the destination keyring if one is given. |
1002 | * | ||
1003 | * The caller must have the appropriate instantiation permit set for this to | ||
1004 | * work (see keyctl_assume_authority). No other permissions are required. | ||
1005 | * | ||
1006 | * The key and any links to the key will be automatically garbage collected | ||
1007 | * after the timeout expires. | ||
1008 | * | ||
1009 | * Negative keys are used to rate limit repeated request_key() calls by causing | ||
1010 | * them to return -ENOKEY until the negative key expires. | ||
1011 | * | ||
1012 | * If successful, 0 will be returned. | ||
983 | */ | 1013 | */ |
984 | long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) | 1014 | long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) |
985 | { | 1015 | { |
@@ -1020,13 +1050,14 @@ long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) | |||
1020 | 1050 | ||
1021 | error: | 1051 | error: |
1022 | return ret; | 1052 | return ret; |
1053 | } | ||
1023 | 1054 | ||
1024 | } /* end keyctl_negate_key() */ | ||
1025 | |||
1026 | /*****************************************************************************/ | ||
1027 | /* | 1055 | /* |
1028 | * set the default keyring in which request_key() will cache keys | 1056 | * Read or set the default keyring in which request_key() will cache keys and |
1029 | * - return the old setting | 1057 | * return the old setting. |
1058 | * | ||
1059 | * If a process keyring is specified then this will be created if it doesn't | ||
1060 | * yet exist. The old setting will be returned if successful. | ||
1030 | */ | 1061 | */ |
1031 | long keyctl_set_reqkey_keyring(int reqkey_defl) | 1062 | long keyctl_set_reqkey_keyring(int reqkey_defl) |
1032 | { | 1063 | { |
@@ -1079,12 +1110,19 @@ set: | |||
1079 | error: | 1110 | error: |
1080 | abort_creds(new); | 1111 | abort_creds(new); |
1081 | return ret; | 1112 | return ret; |
1113 | } | ||
1082 | 1114 | ||
1083 | } /* end keyctl_set_reqkey_keyring() */ | ||
1084 | |||
1085 | /*****************************************************************************/ | ||
1086 | /* | 1115 | /* |
1087 | * set or clear the timeout for a key | 1116 | * Set or clear the timeout on a key. |
1117 | * | ||
1118 | * Either the key must grant the caller Setattr permission or else the caller | ||
1119 | * must hold an instantiation authorisation token for the key. | ||
1120 | * | ||
1121 | * The timeout is either 0 to clear the timeout, or a number of seconds from | ||
1122 | * the current time. The key and any links to the key will be automatically | ||
1123 | * garbage collected after the timeout expires. | ||
1124 | * | ||
1125 | * If successful, 0 is returned. | ||
1088 | */ | 1126 | */ |
1089 | long keyctl_set_timeout(key_serial_t id, unsigned timeout) | 1127 | long keyctl_set_timeout(key_serial_t id, unsigned timeout) |
1090 | { | 1128 | { |
@@ -1136,12 +1174,24 @@ okay: | |||
1136 | ret = 0; | 1174 | ret = 0; |
1137 | error: | 1175 | error: |
1138 | return ret; | 1176 | return ret; |
1177 | } | ||
1139 | 1178 | ||
1140 | } /* end keyctl_set_timeout() */ | ||
1141 | |||
1142 | /*****************************************************************************/ | ||
1143 | /* | 1179 | /* |
1144 | * assume the authority to instantiate the specified key | 1180 | * Assume (or clear) the authority to instantiate the specified key. |
1181 | * | ||
1182 | * This sets the authoritative token currently in force for key instantiation. | ||
1183 | * This must be done for a key to be instantiated. It has the effect of making | ||
1184 | * available all the keys from the caller of the request_key() that created a | ||
1185 | * key to request_key() calls made by the caller of this function. | ||
1186 | * | ||
1187 | * The caller must have the instantiation key in their process keyrings with a | ||
1188 | * Search permission grant available to the caller. | ||
1189 | * | ||
1190 | * If the ID given is 0, then the setting will be cleared and 0 returned. | ||
1191 | * | ||
1192 | * If the ID given has a matching an authorisation key, then that key will be | ||
1193 | * set and its ID will be returned. The authorisation key can be read to get | ||
1194 | * the callout information passed to request_key(). | ||
1145 | */ | 1195 | */ |
1146 | long keyctl_assume_authority(key_serial_t id) | 1196 | long keyctl_assume_authority(key_serial_t id) |
1147 | { | 1197 | { |
@@ -1178,16 +1228,17 @@ long keyctl_assume_authority(key_serial_t id) | |||
1178 | ret = authkey->serial; | 1228 | ret = authkey->serial; |
1179 | error: | 1229 | error: |
1180 | return ret; | 1230 | return ret; |
1181 | 1231 | } | |
1182 | } /* end keyctl_assume_authority() */ | ||
1183 | 1232 | ||
1184 | /* | 1233 | /* |
1185 | * get the security label of a key | 1234 | * Get a key's the LSM security label. |
1186 | * - the key must grant us view permission | 1235 | * |
1187 | * - if there's a buffer, we place up to buflen bytes of data into it | 1236 | * 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, | 1237 | * |
1189 | * irrespective of how much we may have copied (including the terminal NUL) | 1238 | * If there's a buffer, then up to buflen bytes of data will be placed into it. |
1190 | * - implements keyctl(KEYCTL_GET_SECURITY) | 1239 | * |
1240 | * If successful, the amount of information available will be returned, | ||
1241 | * irrespective of how much was copied (including the terminal NUL). | ||
1191 | */ | 1242 | */ |
1192 | long keyctl_get_security(key_serial_t keyid, | 1243 | long keyctl_get_security(key_serial_t keyid, |
1193 | char __user *buffer, | 1244 | char __user *buffer, |
@@ -1242,10 +1293,16 @@ long keyctl_get_security(key_serial_t keyid, | |||
1242 | } | 1293 | } |
1243 | 1294 | ||
1244 | /* | 1295 | /* |
1245 | * attempt to install the calling process's session keyring on the process's | 1296 | * Attempt to install the calling process's session keyring on the process's |
1246 | * parent process | 1297 | * parent process. |
1247 | * - the keyring must exist and must grant us LINK permission | 1298 | * |
1248 | * - implements keyctl(KEYCTL_SESSION_TO_PARENT) | 1299 | * The keyring must exist and must grant the caller LINK permission, and the |
1300 | * parent process must be single-threaded and must have the same effective | ||
1301 | * ownership as this process and mustn't be SUID/SGID. | ||
1302 | * | ||
1303 | * The keyring will be emplaced on the parent when it next resumes userspace. | ||
1304 | * | ||
1305 | * If successful, 0 will be returned. | ||
1249 | */ | 1306 | */ |
1250 | long keyctl_session_to_parent(void) | 1307 | long keyctl_session_to_parent(void) |
1251 | { | 1308 | { |
@@ -1348,9 +1405,8 @@ error_keyring: | |||
1348 | #endif /* !TIF_NOTIFY_RESUME */ | 1405 | #endif /* !TIF_NOTIFY_RESUME */ |
1349 | } | 1406 | } |
1350 | 1407 | ||
1351 | /*****************************************************************************/ | ||
1352 | /* | 1408 | /* |
1353 | * the key control system call | 1409 | * The key control system call |
1354 | */ | 1410 | */ |
1355 | SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, | 1411 | SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, |
1356 | unsigned long, arg4, unsigned long, arg5) | 1412 | unsigned long, arg4, unsigned long, arg5) |
@@ -1439,5 +1495,4 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, | |||
1439 | default: | 1495 | default: |
1440 | return -EOPNOTSUPP; | 1496 | return -EOPNOTSUPP; |
1441 | } | 1497 | } |
1442 | 1498 | } | |
1443 | } /* end sys_keyctl() */ | ||