aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/user.c
diff options
context:
space:
mode:
authorSteven Whitehouse <steve@men-an-tol.chygwyn.com>2006-02-23 04:49:43 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2006-02-23 04:49:43 -0500
commitd35462b4bb847b68321c55e95c926aa485aecce2 (patch)
treeb08e18bf6e672633402871ee763102fdb5e63229 /kernel/user.c
parent91ffd7db71e7451f89941a8f428b4daa2a7c1e38 (diff)
parent9e956c2dac9bec602ed1ba29181b45ba6d2b6448 (diff)
Merge branch 'master'
Diffstat (limited to 'kernel/user.c')
-rw-r--r--kernel/user.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/kernel/user.c b/kernel/user.c
index 89e562feb1b1..d9deae43a9ab 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,16 @@
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 * But free_uid() is also called with local interrupts disabled, and running
37 * local_bh_enable() with local interrupts disabled is an error - we'll run
38 * softirq callbacks, and they can unconditionally enable interrupts, and
39 * the caller of free_uid() didn't expect that..
40 */
30static DEFINE_SPINLOCK(uidhash_lock); 41static DEFINE_SPINLOCK(uidhash_lock);
31 42
32struct user_struct root_user = { 43struct user_struct root_user = {
@@ -82,15 +93,19 @@ static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *has
82struct user_struct *find_user(uid_t uid) 93struct user_struct *find_user(uid_t uid)
83{ 94{
84 struct user_struct *ret; 95 struct user_struct *ret;
96 unsigned long flags;
85 97
86 spin_lock(&uidhash_lock); 98 spin_lock_irqsave(&uidhash_lock, flags);
87 ret = uid_hash_find(uid, uidhashentry(uid)); 99 ret = uid_hash_find(uid, uidhashentry(uid));
88 spin_unlock(&uidhash_lock); 100 spin_unlock_irqrestore(&uidhash_lock, flags);
89 return ret; 101 return ret;
90} 102}
91 103
92void free_uid(struct user_struct *up) 104void free_uid(struct user_struct *up)
93{ 105{
106 unsigned long flags;
107
108 local_irq_save(flags);
94 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { 109 if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
95 uid_hash_remove(up); 110 uid_hash_remove(up);
96 key_put(up->uid_keyring); 111 key_put(up->uid_keyring);
@@ -98,6 +113,7 @@ void free_uid(struct user_struct *up)
98 kmem_cache_free(uid_cachep, up); 113 kmem_cache_free(uid_cachep, up);
99 spin_unlock(&uidhash_lock); 114 spin_unlock(&uidhash_lock);
100 } 115 }
116 local_irq_restore(flags);
101} 117}
102 118
103struct user_struct * alloc_uid(uid_t uid) 119struct user_struct * alloc_uid(uid_t uid)
@@ -105,9 +121,9 @@ struct user_struct * alloc_uid(uid_t uid)
105 struct list_head *hashent = uidhashentry(uid); 121 struct list_head *hashent = uidhashentry(uid);
106 struct user_struct *up; 122 struct user_struct *up;
107 123
108 spin_lock(&uidhash_lock); 124 spin_lock_irq(&uidhash_lock);
109 up = uid_hash_find(uid, hashent); 125 up = uid_hash_find(uid, hashent);
110 spin_unlock(&uidhash_lock); 126 spin_unlock_irq(&uidhash_lock);
111 127
112 if (!up) { 128 if (!up) {
113 struct user_struct *new; 129 struct user_struct *new;
@@ -137,7 +153,7 @@ struct user_struct * alloc_uid(uid_t uid)
137 * Before adding this, check whether we raced 153 * Before adding this, check whether we raced
138 * on adding the same user already.. 154 * on adding the same user already..
139 */ 155 */
140 spin_lock(&uidhash_lock); 156 spin_lock_irq(&uidhash_lock);
141 up = uid_hash_find(uid, hashent); 157 up = uid_hash_find(uid, hashent);
142 if (up) { 158 if (up) {
143 key_put(new->uid_keyring); 159 key_put(new->uid_keyring);
@@ -147,7 +163,7 @@ struct user_struct * alloc_uid(uid_t uid)
147 uid_hash_insert(new, hashent); 163 uid_hash_insert(new, hashent);
148 up = new; 164 up = new;
149 } 165 }
150 spin_unlock(&uidhash_lock); 166 spin_unlock_irq(&uidhash_lock);
151 167
152 } 168 }
153 return up; 169 return up;
@@ -183,9 +199,9 @@ static int __init uid_cache_init(void)
183 INIT_LIST_HEAD(uidhash_table + n); 199 INIT_LIST_HEAD(uidhash_table + n);
184 200
185 /* Insert the root user immediately (init already runs as root) */ 201 /* Insert the root user immediately (init already runs as root) */
186 spin_lock(&uidhash_lock); 202 spin_lock_irq(&uidhash_lock);
187 uid_hash_insert(&root_user, uidhashentry(0)); 203 uid_hash_insert(&root_user, uidhashentry(0));
188 spin_unlock(&uidhash_lock); 204 spin_unlock_irq(&uidhash_lock);
189 205
190 return 0; 206 return 0;
191} 207}