diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-07-31 01:25:37 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-09-06 15:26:17 +0200 |
commit | f462107c1f4df6f74f161afb5b4e8aa3726e39a7 (patch) | |
tree | ad4e35b582f088584c0f136e4c0be987b8912c15 | |
parent | 0f981ee35028602b9e60ac82b07d54972f6f7331 (diff) | |
download | kernel-crypto-f462107c1f4df6f74f161afb5b4e8aa3726e39a7.tar.gz kernel-crypto-f462107c1f4df6f74f161afb5b4e8aa3726e39a7.tar.xz kernel-crypto-f462107c1f4df6f74f161afb5b4e8aa3726e39a7.zip |
Assign integer IDs to ncr.h contexts
-rw-r--r-- | crypto/userspace/ncr-int.h | 2 | ||||
-rw-r--r-- | crypto/userspace/ncr.c | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/crypto/userspace/ncr-int.h b/crypto/userspace/ncr-int.h index 42c500f83da..60e2f080fff 100644 --- a/crypto/userspace/ncr-int.h +++ b/crypto/userspace/ncr-int.h @@ -108,6 +108,8 @@ struct key_item_st { * are here. */ struct ncr_lists { + int id; /* Used only for auditing */ + struct mutex key_idr_mutex; struct idr key_idr; diff --git a/crypto/userspace/ncr.c b/crypto/userspace/ncr.c index e643fe139a0..6cae7167c9d 100644 --- a/crypto/userspace/ncr.c +++ b/crypto/userspace/ncr.c @@ -26,6 +26,7 @@ #include <linux/crypto.h> #include <linux/ioctl.h> #include <linux/mm.h> +#include <linux/mutex.h> #include <linux/highmem.h> #include <linux/random.h> #include <linux/uaccess.h> @@ -42,6 +43,9 @@ */ struct key_item_st master_key; +static struct mutex lists_ida_mutex; +static DEFINE_IDA(lists_ida); + void* ncr_init_lists(void) { struct ncr_lists *lst; @@ -54,6 +58,19 @@ void* ncr_init_lists(void) memset(lst, 0, sizeof(*lst)); + mutex_init(&lists_ida_mutex); + mutex_lock(&lists_ida_mutex); + /* ida_pre_get() should preallocate enough, and, due to lists_ida_mutex, + nobody else can use the preallocated data. Therefore the loop + recommended in idr_get_new() documentation is not necessary. */ + if (ida_pre_get(&lists_ida, GFP_KERNEL) == 0 || + ida_get_new(&lists_ida, &lst->id) != 0) { + mutex_unlock(&lists_ida_mutex); + kfree(lst); + return NULL; + } + mutex_unlock(&lists_ida_mutex); + mutex_init(&lst->key_idr_mutex); idr_init(&lst->key_idr); @@ -68,6 +85,11 @@ void ncr_deinit_lists(struct ncr_lists *lst) if(lst) { ncr_key_list_deinit(lst); ncr_sessions_list_deinit(lst); + + mutex_lock(&lists_ida_mutex); + ida_remove(&lists_ida, lst->id); + mutex_unlock(&lists_ida_mutex); + kfree(lst); } } |