Re: [PATCH] Possible race in sysfs_read_file() and sysfs_write_file()

From: Simon Derr
Date: Fri Sep 03 2004 - 07:03:35 EST


On Fri, 3 Sep 2004, Simon Derr wrote:

> Possible fix would be to add a 'dirty' flag to the sysfs_buffer when
> write() is called, so we force a call to fill_read_buffer() on the next
> read().

This additional patch does just that.
I'm just afraid the flag has not a very good name.

Signed-off-by: Simon Derr <simon.derr@xxxxxxxx>


Index: 269mm2kdb/fs/sysfs/file.c
===================================================================
--- 269mm2kdb.orig/fs/sysfs/file.c 2004-09-03 11:43:01.744675609 +0200
+++ 269mm2kdb/fs/sysfs/file.c 2004-09-03 11:56:06.993689427 +0200
@@ -55,6 +55,7 @@
char * page;
struct sysfs_ops * ops;
struct semaphore sem;
+ int needs_read_fill;
};


@@ -82,6 +83,7 @@
return -ENOMEM;

count = ops->show(kobj,attr,buffer->page);
+ buffer->needs_read_fill = 0;
BUG_ON(count > (ssize_t)PAGE_SIZE);
if (count >= 0)
buffer->count = count;
@@ -146,7 +148,7 @@
ssize_t retval = 0;

down(&buffer->sem);
- if ((!*ppos) || (!buffer->page)) {
+ if (buffer->needs_read_fill) {
if ((retval = fill_read_buffer(file->f_dentry,buffer)))
goto out;
}
@@ -182,6 +184,7 @@
if (count >= PAGE_SIZE)
count = PAGE_SIZE - 1;
error = copy_from_user(buffer->page,buf,count);
+ buffer->needs_read_fill = 1;
return error ? -EFAULT : count;
}

@@ -299,6 +302,7 @@
if (buffer) {
memset(buffer,0,sizeof(struct sysfs_buffer));
init_MUTEX(&buffer->sem);
+ buffer->needs_read_fill = 1;
buffer->ops = ops;
file->private_data = buffer;
} else
-
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/