Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1201283 > unrolled thread
| Started by | NeilBrown <neilb@suse.com> |
|---|---|
| First post | 2015-08-06 00:30 +0200 |
| Last post | 2015-08-06 16:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] sysfs: correctly handle short reads on PREALLOC attrs. NeilBrown <neilb@suse.com> - 2015-08-06 00:30 +0200
Re: [PATCH] sysfs: correctly handle short reads on PREALLOC attrs. Tejun Heo <tj@kernel.org> - 2015-08-06 16:00 +0200
| From | NeilBrown <neilb@suse.com> |
|---|---|
| Date | 2015-08-06 00:30 +0200 |
| Subject | [PATCH] sysfs: correctly handle short reads on PREALLOC attrs. |
| Message-ID | <pUfm9-6lp-1@gated-at.bofh.it> |
attributes declared with __ATTR_PREALLOC use sysfs_kf_read()
which ignores the 'count' arg.
So a 1-byte read request can return more bytes than that.
This is seen with the 'dash' shell when 'read' is used on
some 'md' sysfs attributes.
So only return the 'min' of count and the attribute length.
Signed-off-by: NeilBrown <neilb@suse.com>
---
Possibly kernfs_file_direct_read should be changed instead (or as well)
to use the min of 'count' and the return value from ops->read()
Thanks,
NeilBrown
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 6c95628ea377..f35523d4fa3a 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -108,6 +108,7 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
{
const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
struct kobject *kobj = of->kn->parent->priv;
+ size_t len;
/*
* If buf != of->prealloc_buf, we don't know how
@@ -115,7 +116,8 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
*/
if (pos || WARN_ON_ONCE(buf != of->prealloc_buf))
return 0;
- return ops->show(kobj, of->kn->priv, buf);
+ len = ops->show(kobj, of->kn->priv, buf);
+ return min(count, len);
}
/* kernfs write callback for regular sysfs files */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Tejun Heo <tj@kernel.org> |
|---|---|
| Date | 2015-08-06 16:00 +0200 |
| Message-ID | <pUtSa-2in-15@gated-at.bofh.it> |
| In reply to | #1201283 |
On Thu, Aug 06, 2015 at 08:27:55AM +1000, NeilBrown wrote: > > > attributes declared with __ATTR_PREALLOC use sysfs_kf_read() > which ignores the 'count' arg. > So a 1-byte read request can return more bytes than that. > > This is seen with the 'dash' shell when 'read' is used on > some 'md' sysfs attributes. > > So only return the 'min' of count and the attribute length. > > Signed-off-by: NeilBrown <neilb@suse.com> Acked-by: Tejun Heo <tj@kernel.org> Thanks. -- tejun -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web