aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2006-01-25 09:23:07 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-31 14:30:18 -0500
commit4021cb279a532728c3208a16b9b09b0ca8016850 (patch)
tree1103bc655772ea388eb1fb2b259797bc9c703926 /kernel
parentd5bee775137c56ed993f1b3c9d66c268b3525d7d (diff)
[PATCH] fix uidhash_lock <-> RCU deadlock
RCU task-struct freeing can call free_uid(), which is taking uidhash_lock - while other users of uidhash_lock are softirq-unsafe. The fix is to always take the uidhash_spinlock in a softirq-safe manner. Signed-off-by: Ingo Molnar <mingo@elte.hu> Acked-by: Paul E. McKenney <paulmck@us.ibm.com> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/user.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/kernel/user.c b/kernel/user.c
index 89e562feb1b1..d1ae2349347e 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/bitops.h> 14#include <linux/bitops.h>
15#include <linux/key.h> 15#include <linux/key.h>
16#include <linux/interrupt.h>
16 17
17/* 18/*
18 * UID task count cache, to get fast user lookup in "alloc_uid" 19 * UID task count cache, to get fast user lookup in "alloc_uid"
@@ -27,6 +28,12 @@
27 28
28static kmem_cache_t *uid_cachep; 29static kmem_cache_t *uid_cachep;
29static struct list_head uidhash_table[UIDHASH_SZ]; 30static struct list_head uidhash_table[UIDHASH_SZ];
31
32/*
33 * The uidhash_lock is mostly taken from process context, but it is
34 * occasionally also taken from softirq/tasklet context, when
35 * task-structs get RCU-freed. Hence all locking must be softirq-safe.
36 */
30static DEFINE_SPINLOCK(uidhash_lock); 37static DEFINE_SPINLOCK(uidhash_lock);
31 38
32struct user_struct root_user = { 39struct user_struct root_user = {
@@ -83,14 +90,15 @@ struct user_struct *find_user(uid_t uid)
83{ 90{
84 struct user_struct *ret; 91 struct user_struct *ret;
85 92
86 spin_lock(&uidhash_lock); 93 spin_lock_bh(&uidhash_lock);
87 ret = uid_hash_find(uid, uidhashentry(uid)); 94 ret = uid_hash_find(uid, uidhashentry(uid));
88 spin_unlock(&uidhash_lock); 95 spin_unlock_bh(&uidhash_lock);
89 return ret; 96 return ret;
90} 97}
91 98
92void free_uid(struct user_struct *up) 99void free_uid(struct user_struct *up)
93{ 100{
101 local_bh_disable();
94 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { 102 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
95 uid_hash_remove(up); 103 uid_hash_remove(up);
96 key_put(up->uid_keyring); 104 key_put(up->uid_keyring);
@@ -98,6 +106,7 @@ void free_uid(struct user_struct *up)
98 kmem_cache_free(uid_cachep, up); 106 kmem_cache_free(uid_cachep, up);
99 spin_unlock(&uidhash_lock); 107 spin_unlock(&uidhash_lock);
100 } 108 }
109 local_bh_enable();
101} 110}
102 111
103struct user_struct * alloc_uid(uid_t uid) 112struct user_struct * alloc_uid(uid_t uid)
@@ -105,9 +114,9 @@ struct user_struct * alloc_uid(uid_t uid)
105 struct list_head *hashent = uidhashentry(uid); 114 struct list_head *hashent = uidhashentry(uid);
106 struct user_struct *up; 115 struct user_struct *up;
107 116
108 spin_lock(&uidhash_lock); 117 spin_lock_bh(&uidhash_lock);
109 up = uid_hash_find(uid, hashent); 118 up = uid_hash_find(uid, hashent);
110 spin_unlock(&uidhash_lock); 119 spin_unlock_bh(&uidhash_lock);
111 120
112 if (!up) { 121 if (!up) {
113 struct user_struct *new; 122 struct user_struct *new;
@@ -137,7 +146,7 @@ struct user_struct * alloc_uid(uid_t uid)
137 * Before adding this, check whether we raced 146 * Before adding this, check whether we raced
138 * on adding the same user already.. 147 * on adding the same user already..
139 */ 148 */
140 spin_lock(&uidhash_lock); 149 spin_lock_bh(&uidhash_lock);
141 up = uid_hash_find(uid, hashent); 150 up = uid_hash_find(uid, hashent);
142 if (up) { 151 if (up) {
143 key_put(new->uid_keyring); 152 key_put(new->uid_keyring);
@@ -147,7 +156,7 @@ struct user_struct * alloc_uid(uid_t uid)
147 uid_hash_insert(new, hashent); 156 uid_hash_insert(new, hashent);
148 up = new; 157 up = new;
149 } 158 }
150 spin_unlock(&uidhash_lock); 159 spin_unlock_bh(&uidhash_lock);
151 160
152 } 161 }
153 return up; 162 return up;
@@ -183,9 +192,9 @@ static int __init uid_cache_init(void)
183 INIT_LIST_HEAD(uidhash_table + n); 192 INIT_LIST_HEAD(uidhash_table + n);
184 193
185 /* Insert the root user immediately (init already runs as root) */ 194 /* Insert the root user immediately (init already runs as root) */
186 spin_lock(&uidhash_lock); 195 spin_lock_bh(&uidhash_lock);
187 uid_hash_insert(&root_user, uidhashentry(0)); 196 uid_hash_insert(&root_user, uidhashentry(0));
188 spin_unlock(&uidhash_lock); 197 spin_unlock_bh(&uidhash_lock);
189 198
190 return 0; 199 return 0;
191} 200}