aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2009-12-08 15:24:16 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-09 04:01:06 -0500
commit3160568371da441b7f2fb57f2f1225404207e8f2 (patch)
treebf717db23c352fe14138863157433a79f5edf3e6 /kernel/sched.c
parent6ad4c18884e864cf4c77f9074d3d1816063f99cd (diff)
sched: Protect task->cpus_allowed access in sched_getaffinity()
sched_getaffinity() is not protected against a concurrent modification of the tasks affinity. Serialize the access with task_rq_lock(task). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra <peterz@infradead.org> LKML-Reference: <20091208202026.769251187@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 281da29d0801..c4635f74540c 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6631,6 +6631,8 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t, pid, unsigned int, len,
6631long sched_getaffinity(pid_t pid, struct cpumask *mask) 6631long sched_getaffinity(pid_t pid, struct cpumask *mask)
6632{ 6632{
6633 struct task_struct *p; 6633 struct task_struct *p;
6634 unsigned long flags;
6635 struct rq *rq;
6634 int retval; 6636 int retval;
6635 6637
6636 get_online_cpus(); 6638 get_online_cpus();
@@ -6645,7 +6647,9 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask)
6645 if (retval) 6647 if (retval)
6646 goto out_unlock; 6648 goto out_unlock;
6647 6649
6650 rq = task_rq_lock(p, &flags);
6648 cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); 6651 cpumask_and(mask, &p->cpus_allowed, cpu_online_mask);
6652 task_rq_unlock(rq, &flags);
6649 6653
6650out_unlock: 6654out_unlock:
6651 read_unlock(&tasklist_lock); 6655 read_unlock(&tasklist_lock);