Skip to contentSkip to conversation

AB-BA deadlock between uidhash_lock and tasklist_lock.

PATCH New Robin Holt 1 participant 1 message Dec 22, 2004

lore
Share & tools
lore

Robin Holt

author
#0 lore raw

PATCH 1/1 AB-BA deadlock between uidhash_lock and tasklist_lock.

We have uncovered a very difficult to trip AB-BA deadlock between the uidhash_lock and tasklist_lock.

reparent_to_init() does write_lock_irq(&tasklist_lock) then calls switch_uid() which calls free_uid() which grabs the uidhash_lock.

Independent of that, we have seen a different cpu call free_uid as a result of sys_wait4 and, immediately after acquiring the uidhash_lock, receive a timer interrupt which eventually leads to an attempt to grab the tasklist_lock.

kernel/user.c +4 -0
Index: linux/kernel/user.c
===================================================================
@@ -90,6 +90,9 @@
 
 void free_uid(struct user_struct *up)
 {
+	unsigned long   flags;
+
+	local_irq_save(flags);
 	if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
 		uid_hash_remove(up);
 		key_put(up->uid_keyring);
@@ -97,6 +100,7 @@
 		kmem_cache_free(uid_cachep, up);
 		spin_unlock(&uidhash_lock);
 	}
+	local_irq_restore(flags);
 }
 
 struct user_struct * alloc_uid(uid_t uid)