aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/user.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/user.c')
-rw-r--r--kernel/user.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/kernel/user.c b/kernel/user.c
index 9ca2848fc356..c6387fac932d 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -50,8 +50,41 @@ struct user_struct root_user = {
50 .uid_keyring = &root_user_keyring, 50 .uid_keyring = &root_user_keyring,
51 .session_keyring = &root_session_keyring, 51 .session_keyring = &root_session_keyring,
52#endif 52#endif
53#ifdef CONFIG_FAIR_USER_SCHED
54 .tg = &init_task_grp,
55#endif
53}; 56};
54 57
58#ifdef CONFIG_FAIR_USER_SCHED
59static void sched_destroy_user(struct user_struct *up)
60{
61 sched_destroy_group(up->tg);
62}
63
64static int sched_create_user(struct user_struct *up)
65{
66 int rc = 0;
67
68 up->tg = sched_create_group();
69 if (IS_ERR(up->tg))
70 rc = -ENOMEM;
71
72 return rc;
73}
74
75static void sched_switch_user(struct task_struct *p)
76{
77 sched_move_task(p);
78}
79
80#else /* CONFIG_FAIR_USER_SCHED */
81
82static void sched_destroy_user(struct user_struct *up) { }
83static int sched_create_user(struct user_struct *up) { return 0; }
84static void sched_switch_user(struct task_struct *p) { }
85
86#endif /* CONFIG_FAIR_USER_SCHED */
87
55/* 88/*
56 * These routines must be called with the uidhash spinlock held! 89 * These routines must be called with the uidhash spinlock held!
57 */ 90 */
@@ -109,6 +142,7 @@ void free_uid(struct user_struct *up)
109 if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) { 142 if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
110 uid_hash_remove(up); 143 uid_hash_remove(up);
111 spin_unlock_irqrestore(&uidhash_lock, flags); 144 spin_unlock_irqrestore(&uidhash_lock, flags);
145 sched_destroy_user(up);
112 key_put(up->uid_keyring); 146 key_put(up->uid_keyring);
113 key_put(up->session_keyring); 147 key_put(up->session_keyring);
114 kmem_cache_free(uid_cachep, up); 148 kmem_cache_free(uid_cachep, up);
@@ -150,6 +184,13 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
150 return NULL; 184 return NULL;
151 } 185 }
152 186
187 if (sched_create_user(new) < 0) {
188 key_put(new->uid_keyring);
189 key_put(new->session_keyring);
190 kmem_cache_free(uid_cachep, new);
191 return NULL;
192 }
193
153 /* 194 /*
154 * Before adding this, check whether we raced 195 * Before adding this, check whether we raced
155 * on adding the same user already.. 196 * on adding the same user already..
@@ -157,6 +198,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
157 spin_lock_irq(&uidhash_lock); 198 spin_lock_irq(&uidhash_lock);
158 up = uid_hash_find(uid, hashent); 199 up = uid_hash_find(uid, hashent);
159 if (up) { 200 if (up) {
201 sched_destroy_user(new);
160 key_put(new->uid_keyring); 202 key_put(new->uid_keyring);
161 key_put(new->session_keyring); 203 key_put(new->session_keyring);
162 kmem_cache_free(uid_cachep, new); 204 kmem_cache_free(uid_cachep, new);
@@ -184,6 +226,7 @@ void switch_uid(struct user_struct *new_user)
184 atomic_dec(&old_user->processes); 226 atomic_dec(&old_user->processes);
185 switch_uid_keyring(new_user); 227 switch_uid_keyring(new_user);
186 current->user = new_user; 228 current->user = new_user;
229 sched_switch_user(current);
187 230
188 /* 231 /*
189 * We need to synchronize with __sigqueue_alloc() 232 * We need to synchronize with __sigqueue_alloc()