Commit 31605683 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

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: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
LKML-Reference: <20091208202026.769251187@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 6ad4c188
...@@ -6631,6 +6631,8 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t, pid, unsigned int, len, ...@@ -6631,6 +6631,8 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t, pid, unsigned int, len,
long sched_getaffinity(pid_t pid, struct cpumask *mask) long sched_getaffinity(pid_t pid, struct cpumask *mask)
{ {
struct task_struct *p; struct task_struct *p;
unsigned long flags;
struct rq *rq;
int retval; int retval;
get_online_cpus(); get_online_cpus();
...@@ -6645,7 +6647,9 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask) ...@@ -6645,7 +6647,9 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask)
if (retval) if (retval)
goto out_unlock; goto out_unlock;
rq = task_rq_lock(p, &flags);
cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); cpumask_and(mask, &p->cpus_allowed, cpu_online_mask);
task_rq_unlock(rq, &flags);
out_unlock: out_unlock:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
......
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