Commit 4f821987 authored by Mike Galbraith's avatar Mike Galbraith Committed by Ingo Molnar

sched, autogroup: Fix potential access to freed memory

Oleg pointed out that the /proc interface kref_get() useage may race with
the final put during autogroup_move_group().  A signal->autogroup assignment
may be in flight when the /proc interface dereference, leaving them taking
a reference to an already dead group.
Reported-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarMike Galbraith <efault@gmx.de>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1292508592.5940.28.camel@maggy.simson.net>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 6706125e
...@@ -41,6 +41,20 @@ static inline struct autogroup *autogroup_kref_get(struct autogroup *ag) ...@@ -41,6 +41,20 @@ static inline struct autogroup *autogroup_kref_get(struct autogroup *ag)
return ag; return ag;
} }
static inline struct autogroup *autogroup_task_get(struct task_struct *p)
{
struct autogroup *ag;
unsigned long flags;
if (!lock_task_sighand(p, &flags))
return autogroup_kref_get(&autogroup_default);
ag = autogroup_kref_get(p->signal->autogroup);
unlock_task_sighand(p, &flags);
return ag;
}
static inline struct autogroup *autogroup_create(void) static inline struct autogroup *autogroup_create(void)
{ {
struct autogroup *ag = kzalloc(sizeof(*ag), GFP_KERNEL); struct autogroup *ag = kzalloc(sizeof(*ag), GFP_KERNEL);
...@@ -149,11 +163,7 @@ EXPORT_SYMBOL(sched_autogroup_detach); ...@@ -149,11 +163,7 @@ EXPORT_SYMBOL(sched_autogroup_detach);
void sched_autogroup_fork(struct signal_struct *sig) void sched_autogroup_fork(struct signal_struct *sig)
{ {
struct task_struct *p = current; sig->autogroup = autogroup_task_get(current);
spin_lock_irq(&p->sighand->siglock);
sig->autogroup = autogroup_kref_get(p->signal->autogroup);
spin_unlock_irq(&p->sighand->siglock);
} }
void sched_autogroup_exit(struct signal_struct *sig) void sched_autogroup_exit(struct signal_struct *sig)
...@@ -172,7 +182,6 @@ __setup("noautogroup", setup_autogroup); ...@@ -172,7 +182,6 @@ __setup("noautogroup", setup_autogroup);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
/* Called with siglock held. */
int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice) int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice)
{ {
static unsigned long next = INITIAL_JIFFIES; static unsigned long next = INITIAL_JIFFIES;
...@@ -194,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice) ...@@ -194,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice)
return -EAGAIN; return -EAGAIN;
next = HZ / 10 + jiffies; next = HZ / 10 + jiffies;
ag = autogroup_kref_get(p->signal->autogroup); ag = autogroup_task_get(p);
down_write(&ag->lock); down_write(&ag->lock);
err = sched_group_set_shares(ag->tg, prio_to_weight[*nice + 20]); err = sched_group_set_shares(ag->tg, prio_to_weight[*nice + 20]);
...@@ -209,7 +218,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice) ...@@ -209,7 +218,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice)
void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m) void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m)
{ {
struct autogroup *ag = autogroup_kref_get(p->signal->autogroup); struct autogroup *ag = autogroup_task_get(p);
down_read(&ag->lock); down_read(&ag->lock);
seq_printf(m, "/autogroup-%ld nice %d\n", ag->id, ag->nice); seq_printf(m, "/autogroup-%ld nice %d\n", ag->id, ag->nice);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment