* Possible unwanted behaviour in configfs
@ 2016-06-25 9:43 Tal Shorer
2016-06-30 9:32 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: Tal Shorer @ 2016-06-25 9:43 UTC (permalink / raw)
To: <linux-kernel@vger.kernel.org>, Joel Becker, hch
Hey,
I encountered a possible unwanted behaviour in the way configfs
handles read() on items' attributes.
The show() function is called only once (which is good) on the first
time the user attempts to read from the file. If show() returns an
error that error is returned to the user. However, if the user calls
read() again, no data is copied (good) and a value of zero is
returned.
This is especially evident when using busybox's cat utility, which
first attempts sendfile64() and if that fails falls back to read(),
giving the user the impression that reading the attribute was
successful but no data was returned.
I traced this to the function configfs_read_file in fs/configfs/file.c
and have two fixes in mind:
1. In fill_read_buffer(), If an error is returned by show(), don't set
buffer->needs_read_fill to zero, making the next read() call show()
again and either get an error or data.
2. Add an "err" field to struct configfs_buffer and keep the returned
error from show() there. Any additional read() on this file will
return this error.
Any thoughts?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Possible unwanted behaviour in configfs
2016-06-25 9:43 Possible unwanted behaviour in configfs Tal Shorer
@ 2016-06-30 9:32 ` Christoph Hellwig
2016-07-01 9:28 ` [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error Tal Shorer
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2016-06-30 9:32 UTC (permalink / raw)
To: Tal Shorer; +Cc: <linux-kernel@vger.kernel.org>, Joel Becker, hch
On Sat, Jun 25, 2016 at 12:43:34PM +0300, Tal Shorer wrote:
> I traced this to the function configfs_read_file in fs/configfs/file.c
> and have two fixes in mind:
> 1. In fill_read_buffer(), If an error is returned by show(), don't set
> buffer->needs_read_fill to zero, making the next read() call show()
> again and either get an error or data.
> 2. Add an "err" field to struct configfs_buffer and keep the returned
> error from show() there. Any additional read() on this file will
> return this error.
>
> Any thoughts?
I think fix 1 is a good idea and I'd love to see a patch for it.
Fix 2 might be problematic as the errors don't need to be persistent,
but I think fix 1 alone should be enough anyway.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error
2016-06-30 9:32 ` Christoph Hellwig
@ 2016-07-01 9:28 ` Tal Shorer
2016-07-26 18:23 ` Tal Shorer
0 siblings, 1 reply; 5+ messages in thread
From: Tal Shorer @ 2016-07-01 9:28 UTC (permalink / raw)
To: jlbec, hch, linux-kernel; +Cc: Tal Shorer
A confgifs attribute's show() callback is called once the first time
the user attempts to read from it. If it returns an error, that
error is returned to the user. However, the open file's
buffer_needs_fill is still set to zero and consecutive read() calls
will find an empty buffer that doesn't need filling and return 0 to
the user. This could give the user the wrong impression that the
attribute was read successfully.
Fix this by not setting buffer_needs_fill if show() returns an error,
making consecutive read() calls call show() again and either get an
error again or get data.
Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
fs/configfs/file.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 33b7ee3..68645c9 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -80,11 +80,11 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
count = attr->show(item, buffer->page);
- buffer->needs_read_fill = 0;
BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE);
- if (count >= 0)
+ if (count >= 0) {
+ buffer->needs_read_fill = 0;
buffer->count = count;
- else
+ } else
ret = count;
return ret;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error
2016-07-01 9:28 ` [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error Tal Shorer
@ 2016-07-26 18:23 ` Tal Shorer
2016-07-27 11:30 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: Tal Shorer @ 2016-07-26 18:23 UTC (permalink / raw)
To: Joel Becker, hch, <linux-kernel@vger.kernel.org>; +Cc: Tal Shorer
On Fri, Jul 1, 2016 at 12:28 PM, Tal Shorer <tal.shorer@gmail.com> wrote:
> A confgifs attribute's show() callback is called once the first time
> the user attempts to read from it. If it returns an error, that
> error is returned to the user. However, the open file's
> buffer_needs_fill is still set to zero and consecutive read() calls
> will find an empty buffer that doesn't need filling and return 0 to
> the user. This could give the user the wrong impression that the
> attribute was read successfully.
>
> Fix this by not setting buffer_needs_fill if show() returns an error,
> making consecutive read() calls call show() again and either get an
> error again or get data.
>
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
> ---
> fs/configfs/file.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/configfs/file.c b/fs/configfs/file.c
> index 33b7ee3..68645c9 100644
> --- a/fs/configfs/file.c
> +++ b/fs/configfs/file.c
> @@ -80,11 +80,11 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
>
> count = attr->show(item, buffer->page);
>
> - buffer->needs_read_fill = 0;
> BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE);
> - if (count >= 0)
> + if (count >= 0) {
> + buffer->needs_read_fill = 0;
> buffer->count = count;
> - else
> + } else
> ret = count;
> return ret;
> }
> --
> 2.7.4
>
Ping?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error
2016-07-26 18:23 ` Tal Shorer
@ 2016-07-27 11:30 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2016-07-27 11:30 UTC (permalink / raw)
To: Tal Shorer; +Cc: Joel Becker, hch, <linux-kernel@vger.kernel.org>
Hi Tal,
I've queued up the patch a while ago, and it will go to Linus later this week.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-07-27 11:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-25 9:43 Possible unwanted behaviour in configfs Tal Shorer
2016-06-30 9:32 ` Christoph Hellwig
2016-07-01 9:28 ` [PATCH] fs: configfs: don't set buffer_needs_fill to zero if show() returns error Tal Shorer
2016-07-26 18:23 ` Tal Shorer
2016-07-27 11:30 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).