diff options
Diffstat (limited to 'security/keys/key.c')
-rw-r--r-- | security/keys/key.c | 72 |
1 files changed, 2 insertions, 70 deletions
diff --git a/security/keys/key.c b/security/keys/key.c index f7f9d93f08d9..991a15f1e85f 100644 --- a/security/keys/key.c +++ b/security/keys/key.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include <linux/user_namespace.h> | 21 | #include <linux/user_namespace.h> |
22 | #include "internal.h" | 22 | #include "internal.h" |
23 | 23 | ||
24 | static struct kmem_cache *key_jar; | 24 | struct kmem_cache *key_jar; |
25 | struct rb_root key_serial_tree; /* tree of keys indexed by serial */ | 25 | struct rb_root key_serial_tree; /* tree of keys indexed by serial */ |
26 | DEFINE_SPINLOCK(key_serial_lock); | 26 | DEFINE_SPINLOCK(key_serial_lock); |
27 | 27 | ||
@@ -36,9 +36,6 @@ unsigned int key_quota_maxbytes = 20000; /* general key space quota */ | |||
36 | static LIST_HEAD(key_types_list); | 36 | static LIST_HEAD(key_types_list); |
37 | static DECLARE_RWSEM(key_types_sem); | 37 | static DECLARE_RWSEM(key_types_sem); |
38 | 38 | ||
39 | static void key_cleanup(struct work_struct *work); | ||
40 | static DECLARE_WORK(key_cleanup_task, key_cleanup); | ||
41 | |||
42 | /* We serialise key instantiation and link */ | 39 | /* We serialise key instantiation and link */ |
43 | DEFINE_MUTEX(key_construction_mutex); | 40 | DEFINE_MUTEX(key_construction_mutex); |
44 | 41 | ||
@@ -591,71 +588,6 @@ int key_reject_and_link(struct key *key, | |||
591 | } | 588 | } |
592 | EXPORT_SYMBOL(key_reject_and_link); | 589 | EXPORT_SYMBOL(key_reject_and_link); |
593 | 590 | ||
594 | /* | ||
595 | * Garbage collect keys in process context so that we don't have to disable | ||
596 | * interrupts all over the place. | ||
597 | * | ||
598 | * key_put() schedules this rather than trying to do the cleanup itself, which | ||
599 | * means key_put() doesn't have to sleep. | ||
600 | */ | ||
601 | static void key_cleanup(struct work_struct *work) | ||
602 | { | ||
603 | struct rb_node *_n; | ||
604 | struct key *key; | ||
605 | |||
606 | go_again: | ||
607 | /* look for a dead key in the tree */ | ||
608 | spin_lock(&key_serial_lock); | ||
609 | |||
610 | for (_n = rb_first(&key_serial_tree); _n; _n = rb_next(_n)) { | ||
611 | key = rb_entry(_n, struct key, serial_node); | ||
612 | |||
613 | if (atomic_read(&key->usage) == 0) | ||
614 | goto found_dead_key; | ||
615 | } | ||
616 | |||
617 | spin_unlock(&key_serial_lock); | ||
618 | return; | ||
619 | |||
620 | found_dead_key: | ||
621 | /* we found a dead key - once we've removed it from the tree, we can | ||
622 | * drop the lock */ | ||
623 | rb_erase(&key->serial_node, &key_serial_tree); | ||
624 | spin_unlock(&key_serial_lock); | ||
625 | |||
626 | key_check(key); | ||
627 | |||
628 | security_key_free(key); | ||
629 | |||
630 | /* deal with the user's key tracking and quota */ | ||
631 | if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { | ||
632 | spin_lock(&key->user->lock); | ||
633 | key->user->qnkeys--; | ||
634 | key->user->qnbytes -= key->quotalen; | ||
635 | spin_unlock(&key->user->lock); | ||
636 | } | ||
637 | |||
638 | atomic_dec(&key->user->nkeys); | ||
639 | if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) | ||
640 | atomic_dec(&key->user->nikeys); | ||
641 | |||
642 | key_user_put(key->user); | ||
643 | |||
644 | /* now throw away the key memory */ | ||
645 | if (key->type->destroy) | ||
646 | key->type->destroy(key); | ||
647 | |||
648 | kfree(key->description); | ||
649 | |||
650 | #ifdef KEY_DEBUGGING | ||
651 | key->magic = KEY_DEBUG_MAGIC_X; | ||
652 | #endif | ||
653 | kmem_cache_free(key_jar, key); | ||
654 | |||
655 | /* there may, of course, be more than one key to destroy */ | ||
656 | goto go_again; | ||
657 | } | ||
658 | |||
659 | /** | 591 | /** |
660 | * key_put - Discard a reference to a key. | 592 | * key_put - Discard a reference to a key. |
661 | * @key: The key to discard a reference from. | 593 | * @key: The key to discard a reference from. |
@@ -670,7 +602,7 @@ void key_put(struct key *key) | |||
670 | key_check(key); | 602 | key_check(key); |
671 | 603 | ||
672 | if (atomic_dec_and_test(&key->usage)) | 604 | if (atomic_dec_and_test(&key->usage)) |
673 | schedule_work(&key_cleanup_task); | 605 | schedule_work(&key_gc_unused_work); |
674 | } | 606 | } |
675 | } | 607 | } |
676 | EXPORT_SYMBOL(key_put); | 608 | EXPORT_SYMBOL(key_put); |