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

From: Simon Derr
Date: Fri Sep 03 2004 - 04:44:20 EST


On Fri, 3 Sep 2004, Simon Derr wrote:

> On Thu, 2 Sep 2004, Andrew Morton wrote:
>
> > Simon Derr <Simon.Derr@xxxxxxxx> wrote:
> > >
> > > @@ -140,13 +145,17 @@
> > > struct sysfs_buffer * buffer = file->private_data;
> > > ssize_t retval = 0;
> > >
> > > - if (!*ppos) {
> > > + down(&buffer->sem);
> > > + if ((!*ppos) || (!buffer->page)) {
> > > if ((retval = fill_read_buffer(file->f_dentry,buffer)))
> > > - return retval;
> > > + goto out;
> >
> > Why are we testing *ppos at all in here?
>
> And if we open a sysfs file with O_RDWR, and write() into it, then this is
> needed if we want to read(), because else the buffer will have been
> allocated, but ops->show() not called. I'm not too sure about this being
> useful either.

Hmmm...
We are still screwed if we read at offset >0 after a write.

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().

Or maybe simply forbid O_RDWR open() ? Are they of any use ?
-
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/