[PATCH] cpusets: fix possible race in cpuset_tasks_read()

From: Simon Derr
Date: Fri Sep 10 2004 - 09:39:58 EST



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@xxxxxxxx>

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;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/