aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2010-05-26 17:43:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-27 12:12:45 -0400
commitc70a626d3eba373514c72287c93588b6974a0059 (patch)
treec23b890cbbeb824e52e1eaee6812bc88496a246d
parent685bfd2c48bb3284d31e73ff3151c957d76deda9 (diff)
umh: creds: kill subprocess_info->cred logic
Now that nobody ever changes subprocess_info->cred we can kill this member and related code. ____call_usermodehelper() always runs in the context of freshly forked kernel thread, it has the proper ->cred copied from its parent kthread, keventd. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/cred.h1
-rw-r--r--include/linux/kmod.h1
-rw-r--r--kernel/cred.c60
-rw-r--r--kernel/kmod.c19
4 files changed, 0 insertions, 81 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 52507c3e1387..75c0fa881308 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -156,7 +156,6 @@ extern int copy_creds(struct task_struct *, unsigned long);
156extern struct cred *cred_alloc_blank(void); 156extern struct cred *cred_alloc_blank(void);
157extern struct cred *prepare_creds(void); 157extern struct cred *prepare_creds(void);
158extern struct cred *prepare_exec_creds(void); 158extern struct cred *prepare_exec_creds(void);
159extern struct cred *prepare_usermodehelper_creds(void);
160extern int commit_creds(struct cred *); 159extern int commit_creds(struct cred *);
161extern void abort_creds(struct cred *); 160extern void abort_creds(struct cred *);
162extern const struct cred *override_creds(const struct cred *); 161extern const struct cred *override_creds(const struct cred *);
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index d876dce217f0..6efd7a78de6a 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -56,7 +56,6 @@ enum umh_wait {
56struct subprocess_info { 56struct subprocess_info {
57 struct work_struct work; 57 struct work_struct work;
58 struct completion *complete; 58 struct completion *complete;
59 struct cred *cred;
60 char *path; 59 char *path;
61 char **argv; 60 char **argv;
62 char **envp; 61 char **envp;
diff --git a/kernel/cred.c b/kernel/cred.c
index 2c24870c55d1..a2d5504fbcc2 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -347,66 +347,6 @@ struct cred *prepare_exec_creds(void)
347} 347}
348 348
349/* 349/*
350 * prepare new credentials for the usermode helper dispatcher
351 */
352struct cred *prepare_usermodehelper_creds(void)
353{
354#ifdef CONFIG_KEYS
355 struct thread_group_cred *tgcred = NULL;
356#endif
357 struct cred *new;
358
359#ifdef CONFIG_KEYS
360 tgcred = kzalloc(sizeof(*new->tgcred), GFP_ATOMIC);
361 if (!tgcred)
362 return NULL;
363#endif
364
365 new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
366 if (!new)
367 goto free_tgcred;
368
369 kdebug("prepare_usermodehelper_creds() alloc %p", new);
370
371 memcpy(new, &init_cred, sizeof(struct cred));
372
373 atomic_set(&new->usage, 1);
374 set_cred_subscribers(new, 0);
375 get_group_info(new->group_info);
376 get_uid(new->user);
377
378#ifdef CONFIG_KEYS
379 new->thread_keyring = NULL;
380 new->request_key_auth = NULL;
381 new->jit_keyring = KEY_REQKEY_DEFL_DEFAULT;
382
383 atomic_set(&tgcred->usage, 1);
384 spin_lock_init(&tgcred->lock);
385 new->tgcred = tgcred;
386#endif
387
388#ifdef CONFIG_SECURITY
389 new->security = NULL;
390#endif
391 if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0)
392 goto error;
393 validate_creds(new);
394
395 BUG_ON(atomic_read(&new->usage) != 1);
396 return new;
397
398error:
399 put_cred(new);
400 return NULL;
401
402free_tgcred:
403#ifdef CONFIG_KEYS
404 kfree(tgcred);
405#endif
406 return NULL;
407}
408
409/*
410 * Copy credentials for the new process created by fork() 350 * Copy credentials for the new process created by fork()
411 * 351 *
412 * We share if we can, but under some circumstances we have to generate a new 352 * We share if we can, but under some circumstances we have to generate a new
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 743d3883517c..6194ec2f737b 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -134,8 +134,6 @@ static int ____call_usermodehelper(void *data)
134 struct subprocess_info *sub_info = data; 134 struct subprocess_info *sub_info = data;
135 int retval; 135 int retval;
136 136
137 BUG_ON(atomic_read(&sub_info->cred->usage) != 1);
138
139 /* Unblock all signals */ 137 /* Unblock all signals */
140 spin_lock_irq(&current->sighand->siglock); 138 spin_lock_irq(&current->sighand->siglock);
141 flush_signal_handlers(current, 1); 139 flush_signal_handlers(current, 1);
@@ -143,10 +141,6 @@ static int ____call_usermodehelper(void *data)
143 recalc_sigpending(); 141 recalc_sigpending();
144 spin_unlock_irq(&current->sighand->siglock); 142 spin_unlock_irq(&current->sighand->siglock);
145 143
146 /* Install the credentials */
147 commit_creds(sub_info->cred);
148 sub_info->cred = NULL;
149
150 /* We can run anywhere, unlike our parent keventd(). */ 144 /* We can run anywhere, unlike our parent keventd(). */
151 set_cpus_allowed_ptr(current, cpu_all_mask); 145 set_cpus_allowed_ptr(current, cpu_all_mask);
152 146
@@ -174,8 +168,6 @@ void call_usermodehelper_freeinfo(struct subprocess_info *info)
174{ 168{
175 if (info->cleanup) 169 if (info->cleanup)
176 (*info->cleanup)(info); 170 (*info->cleanup)(info);
177 if (info->cred)
178 put_cred(info->cred);
179 kfree(info); 171 kfree(info);
180} 172}
181EXPORT_SYMBOL(call_usermodehelper_freeinfo); 173EXPORT_SYMBOL(call_usermodehelper_freeinfo);
@@ -231,8 +223,6 @@ static void __call_usermodehelper(struct work_struct *work)
231 pid_t pid; 223 pid_t pid;
232 enum umh_wait wait = sub_info->wait; 224 enum umh_wait wait = sub_info->wait;
233 225
234 BUG_ON(atomic_read(&sub_info->cred->usage) != 1);
235
236 /* CLONE_VFORK: wait until the usermode helper has execve'd 226 /* CLONE_VFORK: wait until the usermode helper has execve'd
237 * successfully We need the data structures to stay around 227 * successfully We need the data structures to stay around
238 * until that is done. */ 228 * until that is done. */
@@ -355,12 +345,6 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
355 sub_info->path = path; 345 sub_info->path = path;
356 sub_info->argv = argv; 346 sub_info->argv = argv;
357 sub_info->envp = envp; 347 sub_info->envp = envp;
358 sub_info->cred = prepare_usermodehelper_creds();
359 if (!sub_info->cred) {
360 kfree(sub_info);
361 return NULL;
362 }
363
364 out: 348 out:
365 return sub_info; 349 return sub_info;
366} 350}
@@ -411,9 +395,6 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info,
411 DECLARE_COMPLETION_ONSTACK(done); 395 DECLARE_COMPLETION_ONSTACK(done);
412 int retval = 0; 396 int retval = 0;
413 397
414 BUG_ON(atomic_read(&sub_info->cred->usage) != 1);
415 validate_creds(sub_info->cred);
416
417 helper_lock(); 398 helper_lock();
418 if (sub_info->path[0] == '\0') 399 if (sub_info->path[0] == '\0')
419 goto out; 400 goto out;