From: Thomas Gleixner Date: Tue, 8 Dec 2009 20:24:16 +0000 (+0000) Subject: sched: Protect task->cpus_allowed access in sched_getaffinity() X-Git-Tag: Ubuntu-5.2.0-15.16~26931^2~18 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=3160568371da441b7f2fb57f2f1225404207e8f2;p=mirror_ubuntu-eoan-kernel.git 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 Acked-by: Peter Zijlstra LKML-Reference: <20091208202026.769251187@linutronix.de> Signed-off-by: Ingo Molnar --- 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, long sched_getaffinity(pid_t pid, struct cpumask *mask) { struct task_struct *p; + unsigned long flags; + struct rq *rq; int retval; get_online_cpus(); @@ -6645,7 +6647,9 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask) if (retval) goto out_unlock; + rq = task_rq_lock(p, &flags); cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); + task_rq_unlock(rq, &flags); out_unlock: read_unlock(&tasklist_lock);