All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 1/2] sched: Protect task->cpus_allowed access in sched_getaffinity()
@ 2009-12-08 20:24 Thomas Gleixner
  2009-12-09  8:00 ` Peter Zijlstra
  2009-12-09  9:52 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Gleixner @ 2009-12-08 20:24 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Peter Zijlstra

[-- Attachment #1: sched-fix-sched-get-affinity-racy-access.patch --]
[-- Type: text/plain, Size: 925 bytes --]

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>
---
 kernel/sched.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux-2.6-tip/kernel/sched.c
===================================================================
--- linux-2.6-tip.orig/kernel/sched.c
+++ linux-2.6-tip/kernel/sched.c
@@ -6631,6 +6631,8 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t
 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
 	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);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/2] sched: Protect task->cpus_allowed access in sched_getaffinity()
  2009-12-08 20:24 [patch 1/2] sched: Protect task->cpus_allowed access in sched_getaffinity() Thomas Gleixner
@ 2009-12-09  8:00 ` Peter Zijlstra
  2009-12-09  9:52 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2009-12-09  8:00 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Ingo Molnar

On Tue, 2009-12-08 at 20:24 +0000, Thomas Gleixner wrote:
> plain text document attachment
> (sched-fix-sched-get-affinity-racy-access.patch)
> 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>
> ---
>  kernel/sched.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> Index: linux-2.6-tip/kernel/sched.c
> ===================================================================
> --- linux-2.6-tip.orig/kernel/sched.c
> +++ linux-2.6-tip/kernel/sched.c
> @@ -6631,6 +6631,8 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t
>  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
>  	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);
> 

Hehe, I wrote the exact same patch last night :-)

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/urgent] sched: Protect task->cpus_allowed access in sched_getaffinity()
  2009-12-08 20:24 [patch 1/2] sched: Protect task->cpus_allowed access in sched_getaffinity() Thomas Gleixner
  2009-12-09  8:00 ` Peter Zijlstra
@ 2009-12-09  9:52 ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Thomas Gleixner @ 2009-12-09  9:52 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, peterz, tglx, mingo

Commit-ID:  3160568371da441b7f2fb57f2f1225404207e8f2
Gitweb:     http://git.kernel.org/tip/3160568371da441b7f2fb57f2f1225404207e8f2
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 8 Dec 2009 20:24:16 +0000
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 9 Dec 2009 10:01:06 +0100

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>
---
 kernel/sched.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 281da29..c4635f7 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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-09  9:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-08 20:24 [patch 1/2] sched: Protect task->cpus_allowed access in sched_getaffinity() Thomas Gleixner
2009-12-09  8:00 ` Peter Zijlstra
2009-12-09  9:52 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.