sysfs: correctly handle read offset on PREALLOC attrs
Subsystems (2)
PATCH 1/1 sysfs: correctly handle read offset on PREALLOC attrs
Attributes declared with __ATTR_PREALLOC use sysfs_kf_read() which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where /bin/sh is 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from /sys/block/$dev/md/sync_action and as a result does nothing.
This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/sysfs/file.c +7 -1
@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf); +if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }
Quoted 6 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.
Quoted 7 lines
This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+
Thanks.
Signature · 1 line
tejun
Bump
Quoted 39 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +7
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf); +if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }
Greg Kroah-Hartman
maintainerQuoted 1 line · Konstantin Khlebnikov
Bump
Huh?
Quoted 31 lines
Quoted 29 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +1
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf);
Quoted 8 lines
fs/sysfs/file.c static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, · line 127
Quoted 8 lines
fs/sysfs/file.c +6
-0+if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }
I don't have this in any queue of mine, so I don't understand what you are asking about.
totally confused,
greg k-h
Konstantin Khlebnikov
Acked-by Tejun HeoQuoted 48 lines · Greg Kroah-Hartman
Quoted 1 line · Konstantin Khlebnikov
Bump
Huh?
Quoted 31 lines
Quoted 29 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +1
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf);Quoted 8 lines
fs/sysfs/file.c static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, · line 127
Quoted 8 lines
fs/sysfs/file.c +6
-0+if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }I don't have this in any queue of mine, so I don't understand what you are asking about.
Quoted 2 lines
totally confused,
Well.. One user poked me about this bug.
Patch was
get_maintainer.pl points to you but probably this more VFS problem. so... this time I've added Al into CC Should I resend patch once again, or this very trivial but pretty dangerous problem could be solved without this?
IIRR this breaks automatic recheck of MD RAIDs for all debian-based systems
Signature · 1 line
Konstantin
Greg Kroah-Hartman
maintainerQuoted 48 lines · Greg Kroah-Hartman
Quoted 1 line · Konstantin Khlebnikov
Bump
Huh?
Quoted 31 lines
Quoted 29 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +1
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf);Quoted 8 lines
fs/sysfs/file.c static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, · line 127
Quoted 8 lines
fs/sysfs/file.c +6
-0+if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }I don't have this in any queue of mine, so I don't understand what you are asking about.
Quoted 1 line
totally confused,
Wait, this is already in Linus's tree, what are you asking for here?
still confused,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 49 lines · Konstantin Khlebnikov
Quoted 48 lines · Greg Kroah-Hartman
Quoted 1 line · Konstantin Khlebnikov
Bump
Huh?
Quoted 31 lines
Quoted 29 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +1
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf);Quoted 8 lines
fs/sysfs/file.c static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, · line 127
Quoted 8 lines
fs/sysfs/file.c +6
-0+if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }I don't have this in any queue of mine, so I don't understand what you are asking about.
Quoted 4 lines
Quoted 2 lines
totally confused,
Well.. One user poked me about this bug.
As I just mentioned, this is in 4.8-rc5, and will show up in a stable release "soon". So I don't understand what else we can do here :)
thanks,
greg k-h
Quoted 49 lines · Greg Kroah-Hartman
Quoted 48 lines · Greg Kroah-Hartman
Quoted 1 line · Konstantin Khlebnikov
Bump
Huh?
Quoted 31 lines
Quoted 29 lines · Konstantin Khlebnikov
Attributes declared with
__ATTR_PREALLOCusesysfs_kf_read()which returns zero bytes for non-zero offset. This breaks script checkarray in mdadm tool in debian where/bin/shis 'dash' because its builtin 'read' reads only one byte at a time. Script gets 'i' instead of 'idle' when reads current action from/sys/block/$dev/md/sync_actionand as a result does nothing.This patch adds trivial implementation of partial read: generate whole string and move required part into buffer head.
Signed-off-by Konstantin Khlebnikov <[email protected]>Fixes 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")Cc Stable <[email protected]> # v3.19+--- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/sysfs/file.c +1
-1@@ -114,9 +114,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,* If buf != of->prealloc_buf, we don't know how * large it is, so cannot safely pass it to ->show */ -if (pos ||WARN_ON_ONCE (buf != of->prealloc_buf)) +if (WARN_ON_ONCE (buf != of->prealloc_buf))return 0 ; len = ops->show (kobj, of->kn->priv, buf);Quoted 8 lines
fs/sysfs/file.c static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, · line 127
Quoted 8 lines
fs/sysfs/file.c +6
-0+if (pos) { +if (len <= pos) +return 0 ; + len -= pos; +memmove (buf, buf + pos, len); + }return min (count, len); }I don't have this in any queue of mine, so I don't understand what you are asking about.
Quoted 6 lines
Quoted 1 line
totally confused,
Wait, this is already in Linus's tree, what are you asking for here?
still confused,
Huh. Sorry. Haven't done git pull before checking - it only in lastest v4.8-rc5