aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/key.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/keys/key.c')
-rw-r--r--security/keys/key.c80
1 files changed, 20 insertions, 60 deletions
diff --git a/security/keys/key.c b/security/keys/key.c
index c1eac8084ade..3a92d7365870 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -56,7 +56,6 @@ void __key_check(const struct key *key)
56} 56}
57#endif 57#endif
58 58
59/*****************************************************************************/
60/* 59/*
61 * get the key quota record for a user, allocating a new record if one doesn't 60 * get the key quota record for a user, allocating a new record if one doesn't
62 * already exist 61 * already exist
@@ -130,10 +129,8 @@ struct key_user *key_user_lookup(uid_t uid, struct user_namespace *user_ns)
130 kfree(candidate); 129 kfree(candidate);
131 out: 130 out:
132 return user; 131 return user;
132}
133 133
134} /* end key_user_lookup() */
135
136/*****************************************************************************/
137/* 134/*
138 * dispose of a user structure 135 * dispose of a user structure
139 */ 136 */
@@ -146,10 +143,8 @@ void key_user_put(struct key_user *user)
146 143
147 kfree(user); 144 kfree(user);
148 } 145 }
146}
149 147
150} /* end key_user_put() */
151
152/*****************************************************************************/
153/* 148/*
154 * assign a key the next unique serial number 149 * assign a key the next unique serial number
155 * - these are assigned randomly to avoid security issues through covert 150 * - these are assigned randomly to avoid security issues through covert
@@ -211,10 +206,8 @@ serial_exists:
211 if (key->serial < xkey->serial) 206 if (key->serial < xkey->serial)
212 goto attempt_insertion; 207 goto attempt_insertion;
213 } 208 }
209}
214 210
215} /* end key_alloc_serial() */
216
217/*****************************************************************************/
218/* 211/*
219 * allocate a key of the specified type 212 * allocate a key of the specified type
220 * - update the user's quota to reflect the existence of the key 213 * - update the user's quota to reflect the existence of the key
@@ -344,12 +337,10 @@ no_quota:
344 key_user_put(user); 337 key_user_put(user);
345 key = ERR_PTR(-EDQUOT); 338 key = ERR_PTR(-EDQUOT);
346 goto error; 339 goto error;
347 340}
348} /* end key_alloc() */
349 341
350EXPORT_SYMBOL(key_alloc); 342EXPORT_SYMBOL(key_alloc);
351 343
352/*****************************************************************************/
353/* 344/*
354 * reserve an amount of quota for the key's payload 345 * reserve an amount of quota for the key's payload
355 */ 346 */
@@ -384,12 +375,10 @@ int key_payload_reserve(struct key *key, size_t datalen)
384 key->datalen = datalen; 375 key->datalen = datalen;
385 376
386 return ret; 377 return ret;
387 378}
388} /* end key_payload_reserve() */
389 379
390EXPORT_SYMBOL(key_payload_reserve); 380EXPORT_SYMBOL(key_payload_reserve);
391 381
392/*****************************************************************************/
393/* 382/*
394 * instantiate a key and link it into the target keyring atomically 383 * instantiate a key and link it into the target keyring atomically
395 * - called with the target keyring's semaphore writelocked 384 * - called with the target keyring's semaphore writelocked
@@ -441,10 +430,8 @@ static int __key_instantiate_and_link(struct key *key,
441 wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT); 430 wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT);
442 431
443 return ret; 432 return ret;
433}
444 434
445} /* end __key_instantiate_and_link() */
446
447/*****************************************************************************/
448/* 435/*
449 * instantiate a key and link it into the target keyring atomically 436 * instantiate a key and link it into the target keyring atomically
450 */ 437 */
@@ -471,12 +458,10 @@ int key_instantiate_and_link(struct key *key,
471 __key_link_end(keyring, key->type, prealloc); 458 __key_link_end(keyring, key->type, prealloc);
472 459
473 return ret; 460 return ret;
474 461}
475} /* end key_instantiate_and_link() */
476 462
477EXPORT_SYMBOL(key_instantiate_and_link); 463EXPORT_SYMBOL(key_instantiate_and_link);
478 464
479/*****************************************************************************/
480/* 465/*
481 * negatively instantiate a key and link it into the target keyring atomically 466 * negatively instantiate a key and link it into the target keyring atomically
482 */ 467 */
@@ -535,12 +520,10 @@ int key_negate_and_link(struct key *key,
535 wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT); 520 wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT);
536 521
537 return ret == 0 ? link_ret : ret; 522 return ret == 0 ? link_ret : ret;
538 523}
539} /* end key_negate_and_link() */
540 524
541EXPORT_SYMBOL(key_negate_and_link); 525EXPORT_SYMBOL(key_negate_and_link);
542 526
543/*****************************************************************************/
544/* 527/*
545 * do cleaning up in process context so that we don't have to disable 528 * do cleaning up in process context so that we don't have to disable
546 * interrupts all over the place 529 * interrupts all over the place
@@ -601,10 +584,8 @@ static void key_cleanup(struct work_struct *work)
601 584
602 /* there may, of course, be more than one key to destroy */ 585 /* there may, of course, be more than one key to destroy */
603 goto go_again; 586 goto go_again;
587}
604 588
605} /* end key_cleanup() */
606
607/*****************************************************************************/
608/* 589/*
609 * dispose of a reference to a key 590 * dispose of a reference to a key
610 * - when all the references are gone, we schedule the cleanup task to come and 591 * - when all the references are gone, we schedule the cleanup task to come and
@@ -618,12 +599,10 @@ void key_put(struct key *key)
618 if (atomic_dec_and_test(&key->usage)) 599 if (atomic_dec_and_test(&key->usage))
619 schedule_work(&key_cleanup_task); 600 schedule_work(&key_cleanup_task);
620 } 601 }
621 602}
622} /* end key_put() */
623 603
624EXPORT_SYMBOL(key_put); 604EXPORT_SYMBOL(key_put);
625 605
626/*****************************************************************************/
627/* 606/*
628 * find a key by its serial number 607 * find a key by its serial number
629 */ 608 */
@@ -664,10 +643,8 @@ struct key *key_lookup(key_serial_t id)
664 error: 643 error:
665 spin_unlock(&key_serial_lock); 644 spin_unlock(&key_serial_lock);
666 return key; 645 return key;
646}
667 647
668} /* end key_lookup() */
669
670/*****************************************************************************/
671/* 648/*
672 * find and lock the specified key type against removal 649 * find and lock the specified key type against removal
673 * - we return with the sem readlocked 650 * - we return with the sem readlocked
@@ -690,20 +667,16 @@ struct key_type *key_type_lookup(const char *type)
690 667
691 found_kernel_type: 668 found_kernel_type:
692 return ktype; 669 return ktype;
670}
693 671
694} /* end key_type_lookup() */
695
696/*****************************************************************************/
697/* 672/*
698 * unlock a key type 673 * unlock a key type
699 */ 674 */
700void key_type_put(struct key_type *ktype) 675void key_type_put(struct key_type *ktype)
701{ 676{
702 up_read(&key_types_sem); 677 up_read(&key_types_sem);
678}
703 679
704} /* end key_type_put() */
705
706/*****************************************************************************/
707/* 680/*
708 * attempt to update an existing key 681 * attempt to update an existing key
709 * - the key has an incremented refcount 682 * - the key has an incremented refcount
@@ -742,10 +715,8 @@ error:
742 key_put(key); 715 key_put(key);
743 key_ref = ERR_PTR(ret); 716 key_ref = ERR_PTR(ret);
744 goto out; 717 goto out;
718}
745 719
746} /* end __key_update() */
747
748/*****************************************************************************/
749/* 720/*
750 * search the specified keyring for a key of the same description; if one is 721 * search the specified keyring for a key of the same description; if one is
751 * found, update it, otherwise add a new one 722 * found, update it, otherwise add a new one
@@ -855,12 +826,10 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
855 826
856 key_ref = __key_update(key_ref, payload, plen); 827 key_ref = __key_update(key_ref, payload, plen);
857 goto error; 828 goto error;
858 829}
859} /* end key_create_or_update() */
860 830
861EXPORT_SYMBOL(key_create_or_update); 831EXPORT_SYMBOL(key_create_or_update);
862 832
863/*****************************************************************************/
864/* 833/*
865 * update a key 834 * update a key
866 */ 835 */
@@ -891,12 +860,10 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen)
891 860
892 error: 861 error:
893 return ret; 862 return ret;
894 863}
895} /* end key_update() */
896 864
897EXPORT_SYMBOL(key_update); 865EXPORT_SYMBOL(key_update);
898 866
899/*****************************************************************************/
900/* 867/*
901 * revoke a key 868 * revoke a key
902 */ 869 */
@@ -926,12 +893,10 @@ void key_revoke(struct key *key)
926 } 893 }
927 894
928 up_write(&key->sem); 895 up_write(&key->sem);
929 896}
930} /* end key_revoke() */
931 897
932EXPORT_SYMBOL(key_revoke); 898EXPORT_SYMBOL(key_revoke);
933 899
934/*****************************************************************************/
935/* 900/*
936 * register a type of key 901 * register a type of key
937 */ 902 */
@@ -956,12 +921,10 @@ int register_key_type(struct key_type *ktype)
956 out: 921 out:
957 up_write(&key_types_sem); 922 up_write(&key_types_sem);
958 return ret; 923 return ret;
959 924}
960} /* end register_key_type() */
961 925
962EXPORT_SYMBOL(register_key_type); 926EXPORT_SYMBOL(register_key_type);
963 927
964/*****************************************************************************/
965/* 928/*
966 * unregister a type of key 929 * unregister a type of key
967 */ 930 */
@@ -1010,12 +973,10 @@ void unregister_key_type(struct key_type *ktype)
1010 up_write(&key_types_sem); 973 up_write(&key_types_sem);
1011 974
1012 key_schedule_gc(0); 975 key_schedule_gc(0);
1013 976}
1014} /* end unregister_key_type() */
1015 977
1016EXPORT_SYMBOL(unregister_key_type); 978EXPORT_SYMBOL(unregister_key_type);
1017 979
1018/*****************************************************************************/
1019/* 980/*
1020 * initialise the key management stuff 981 * initialise the key management stuff
1021 */ 982 */
@@ -1037,5 +998,4 @@ void __init key_init(void)
1037 998
1038 rb_insert_color(&root_key_user.node, 999 rb_insert_color(&root_key_user.node,
1039 &key_user_tree); 1000 &key_user_tree);
1040 1001}
1041} /* end key_init() */