public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpusets: fix possible race in cpuset_tasks_read()
@ 2004-09-10 14:38 Simon Derr
  2004-09-11  8:01 ` [PATCH] cpusets: alternative fix for " Paul Jackson
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Derr @ 2004-09-10 14:38 UTC (permalink / raw)
  To: pj, akpm, linux-kernel


Hi,

this patch fixes a possible race between two threads of a single process
in cpuset_tasks_read().

It is mostly the same issue as the one that was in sysfs.

This patch is against 2.6.9-rc1-mm4.


Signed-Off-By: Simon Derr <simon.derr@bull.net>

Index: mm4/kernel/cpuset.c
===================================================================
--- mm4.orig/kernel/cpuset.c	2004-09-07 11:36:18.000000000 +0200
+++ mm4/kernel/cpuset.c	2004-09-10 15:10:01.657243216 +0200
@@ -1100,20 +1100,27 @@
 static ssize_t cpuset_tasks_read(struct file *file, char __user *buf,
 						size_t nbytes, loff_t *ppos)
 {
-	struct ctr_struct *ctr = (struct ctr_struct *)file->private_data;
+	struct ctr_struct *ctr;

+	down(&cpuset_sem);
+	ctr = (struct ctr_struct *)file->private_data;
 	/* allocate buffer and fill it on first call to read() */
 	if (!ctr) {
 		ctr = cpuset_tasks_mkctr(file);
-		if (!ctr)
+		if (!ctr) {
+			up(&cpuset_sem);
 			return -ENOMEM;
+		}
 	}

 	if (*ppos + nbytes > ctr->bufsz)
 		nbytes = ctr->bufsz - *ppos;
-	if (copy_to_user(buf, ctr->buf + *ppos, nbytes))
+	if (copy_to_user(buf, ctr->buf + *ppos, nbytes)) {
+		up(&cpuset_sem);
 		return -EFAULT;
+	}
 	*ppos += nbytes;
+	up(&cpuset_sem);
 	return nbytes;
 }


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

end of thread, other threads:[~2004-09-13  9:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-10 14:38 [PATCH] cpusets: fix possible race in cpuset_tasks_read() Simon Derr
2004-09-11  8:01 ` [PATCH] cpusets: alternative fix for " Paul Jackson
2004-09-13  8:24   ` Simon.Derr
2004-09-13  9:25     ` Paul Jackson
2004-09-13  9:39       ` Paul Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox