Skip to content

Commit a6f80fb

Browse files
Andre Osterhuestorvalds
authored andcommitted
ecryptfs: Bugfix for error related to ecryptfs_hash_buckets
The function ecryptfs_uid_hash wrongly assumes that the second parameter to hash_long() is the number of hash buckets instead of the number of hash bits. This patch fixes that and renames the variable ecryptfs_hash_buckets to ecryptfs_hash_bits to make it clearer. Fixes: CVE-2010-2492 Signed-off-by: Andre Osterhues <aosterhues@escrypt.com> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6c50e1a commit a6f80fb

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎fs/ecryptfs/messaging.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ static struct mutex ecryptfs_msg_ctx_lists_mux;
3131

3232
static struct hlist_head *ecryptfs_daemon_hash;
3333
struct mutex ecryptfs_daemon_hash_mux;
34-
static int ecryptfs_hash_buckets;
34+
static int ecryptfs_hash_bits;
3535
#define ecryptfs_uid_hash(uid) \
36-
hash_long((unsigned long)uid, ecryptfs_hash_buckets)
36+
hash_long((unsigned long)uid, ecryptfs_hash_bits)
3737

3838
static u32 ecryptfs_msg_counter;
3939
static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr;
@@ -486,18 +486,19 @@ int ecryptfs_init_messaging(void)
486486
}
487487
mutex_init(&ecryptfs_daemon_hash_mux);
488488
mutex_lock(&ecryptfs_daemon_hash_mux);
489-
ecryptfs_hash_buckets = 1;
490-
while (ecryptfs_number_of_users >> ecryptfs_hash_buckets)
491-
ecryptfs_hash_buckets++;
489+
ecryptfs_hash_bits = 1;
490+
while (ecryptfs_number_of_users >> ecryptfs_hash_bits)
491+
ecryptfs_hash_bits++;
492492
ecryptfs_daemon_hash = kmalloc((sizeof(struct hlist_head)
493-
* ecryptfs_hash_buckets), GFP_KERNEL);
493+
* (1 << ecryptfs_hash_bits)),
494+
GFP_KERNEL);
494495
if (!ecryptfs_daemon_hash) {
495496
rc = -ENOMEM;
496497
printk(KERN_ERR "%s: Failed to allocate memory\n", __func__);
497498
mutex_unlock(&ecryptfs_daemon_hash_mux);
498499
goto out;
499500
}
500-
for (i = 0; i < ecryptfs_hash_buckets; i++)
501+
for (i = 0; i < (1 << ecryptfs_hash_bits); i++)
501502
INIT_HLIST_HEAD(&ecryptfs_daemon_hash[i]);
502503
mutex_unlock(&ecryptfs_daemon_hash_mux);
503504
ecryptfs_msg_ctx_arr = kmalloc((sizeof(struct ecryptfs_msg_ctx)
@@ -554,7 +555,7 @@ void ecryptfs_release_messaging(void)
554555
int i;
555556

556557
mutex_lock(&ecryptfs_daemon_hash_mux);
557-
for (i = 0; i < ecryptfs_hash_buckets; i++) {
558+
for (i = 0; i < (1 << ecryptfs_hash_bits); i++) {
558559
int rc;
559560

560561
hlist_for_each_entry(daemon, elem,

0 commit comments

Comments
 (0)