* [PATCH] sysfs: correctly handle read offset on PREALLOC attrs @ 2016-06-22 18:42 Konstantin Khlebnikov 2016-06-23 21:18 ` Tejun Heo 2016-09-05 13:25 ` Konstantin Khlebnikov 0 siblings, 2 replies; 8+ messages in thread From: Konstantin Khlebnikov @ 2016-06-22 18:42 UTC (permalink / raw) To: Greg Kroah-Hartman, linux-kernel; +Cc: NeilBrown, Tejun Heo, stable 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. Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 Cc: Stable <stable@vger.kernel.org> # v3.19+ --- fs/sysfs/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index f35523d4fa3a..b803213d1307 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -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); } ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-06-22 18:42 [PATCH] sysfs: correctly handle read offset on PREALLOC attrs Konstantin Khlebnikov @ 2016-06-23 21:18 ` Tejun Heo 2016-09-05 13:25 ` Konstantin Khlebnikov 1 sibling, 0 replies; 8+ messages in thread From: Tejun Heo @ 2016-06-23 21:18 UTC (permalink / raw) To: Konstantin Khlebnikov; +Cc: Greg Kroah-Hartman, linux-kernel, NeilBrown, stable On Wed, Jun 22, 2016 at 09:42:16PM +0300, Konstantin Khlebnikov wrote: > 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. > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 > Cc: Stable <stable@vger.kernel.org> # v3.19+ Acked-by: Tejun Heo <tj@kernel.org> Thanks. -- tejun ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-06-22 18:42 [PATCH] sysfs: correctly handle read offset on PREALLOC attrs Konstantin Khlebnikov 2016-06-23 21:18 ` Tejun Heo @ 2016-09-05 13:25 ` Konstantin Khlebnikov 2016-09-05 13:46 ` Greg Kroah-Hartman 1 sibling, 1 reply; 8+ messages in thread From: Konstantin Khlebnikov @ 2016-09-05 13:25 UTC (permalink / raw) To: Konstantin Khlebnikov Cc: Greg Kroah-Hartman, Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro Bump On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov <khlebnikov@yandex-team.ru> wrote: > 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. > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 > Cc: Stable <stable@vger.kernel.org> # v3.19+ > --- > fs/sysfs/file.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > index f35523d4fa3a..b803213d1307 100644 > --- a/fs/sysfs/file.c > +++ b/fs/sysfs/file.c > @@ -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); > } > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-09-05 13:25 ` Konstantin Khlebnikov @ 2016-09-05 13:46 ` Greg Kroah-Hartman 2016-09-05 14:02 ` Konstantin Khlebnikov 2016-09-05 14:13 ` Greg Kroah-Hartman 0 siblings, 2 replies; 8+ messages in thread From: Greg Kroah-Hartman @ 2016-09-05 13:46 UTC (permalink / raw) To: Konstantin Khlebnikov Cc: Konstantin Khlebnikov, Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro On Mon, Sep 05, 2016 at 04:25:48PM +0300, Konstantin Khlebnikov wrote: > Bump Huh? > On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov > <khlebnikov@yandex-team.ru> wrote: > > 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. > > > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> > > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 > > Cc: Stable <stable@vger.kernel.org> # v3.19+ > > --- > > fs/sysfs/file.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > > index f35523d4fa3a..b803213d1307 100644 > > --- a/fs/sysfs/file.c > > +++ b/fs/sysfs/file.c > > @@ -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); > > } 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-09-05 13:46 ` Greg Kroah-Hartman @ 2016-09-05 14:02 ` Konstantin Khlebnikov 2016-09-05 14:15 ` Greg Kroah-Hartman 2016-09-05 14:13 ` Greg Kroah-Hartman 1 sibling, 1 reply; 8+ messages in thread From: Konstantin Khlebnikov @ 2016-09-05 14:02 UTC (permalink / raw) To: Greg Kroah-Hartman, Konstantin Khlebnikov Cc: Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro On 05.09.2016 16:46, Greg Kroah-Hartman wrote: > On Mon, Sep 05, 2016 at 04:25:48PM +0300, Konstantin Khlebnikov wrote: >> Bump > > Huh? > >> On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov >> <khlebnikov@yandex-team.ru> wrote: >>> 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. >>> >>> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> >>> Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") >>> Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 >>> Cc: Stable <stable@vger.kernel.org> # v3.19+ >>> --- >>> fs/sysfs/file.c | 8 +++++++- >>> 1 file changed, 7 insertions(+), 1 deletion(-) >>> >>> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c >>> index f35523d4fa3a..b803213d1307 100644 >>> --- a/fs/sysfs/file.c >>> +++ b/fs/sysfs/file.c >>> @@ -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); >>> } > > I don't have this in any queue of mine, so I don't understand what you > are asking about. > > totally confused, > Well.. One user poked me about this bug. Patch was Acked-by: Tejun Heo <tj@kernel.org> 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 -- Konstantin ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-09-05 14:02 ` Konstantin Khlebnikov @ 2016-09-05 14:15 ` Greg Kroah-Hartman 0 siblings, 0 replies; 8+ messages in thread From: Greg Kroah-Hartman @ 2016-09-05 14:15 UTC (permalink / raw) To: Konstantin Khlebnikov Cc: Konstantin Khlebnikov, Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro On Mon, Sep 05, 2016 at 05:02:43PM +0300, Konstantin Khlebnikov wrote: > On 05.09.2016 16:46, Greg Kroah-Hartman wrote: > > On Mon, Sep 05, 2016 at 04:25:48PM +0300, Konstantin Khlebnikov wrote: > > > Bump > > > > Huh? > > > > > On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov > > > <khlebnikov@yandex-team.ru> wrote: > > > > 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. > > > > > > > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> > > > > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > > > > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 > > > > Cc: Stable <stable@vger.kernel.org> # v3.19+ > > > > --- > > > > fs/sysfs/file.c | 8 +++++++- > > > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > > > > index f35523d4fa3a..b803213d1307 100644 > > > > --- a/fs/sysfs/file.c > > > > +++ b/fs/sysfs/file.c > > > > @@ -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); > > > > } > > > > I don't have this in any queue of mine, so I don't understand what you > > are asking about. > > > > 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-09-05 13:46 ` Greg Kroah-Hartman 2016-09-05 14:02 ` Konstantin Khlebnikov @ 2016-09-05 14:13 ` Greg Kroah-Hartman 2016-09-05 14:17 ` Konstantin Khlebnikov 1 sibling, 1 reply; 8+ messages in thread From: Greg Kroah-Hartman @ 2016-09-05 14:13 UTC (permalink / raw) To: Konstantin Khlebnikov Cc: Konstantin Khlebnikov, Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro On Mon, Sep 05, 2016 at 03:46:28PM +0200, Greg Kroah-Hartman wrote: > On Mon, Sep 05, 2016 at 04:25:48PM +0300, Konstantin Khlebnikov wrote: > > Bump > > Huh? > > > On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov > > <khlebnikov@yandex-team.ru> wrote: > > > 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. > > > > > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> > > > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > > > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 > > > Cc: Stable <stable@vger.kernel.org> # v3.19+ > > > --- > > > fs/sysfs/file.c | 8 +++++++- > > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > > > index f35523d4fa3a..b803213d1307 100644 > > > --- a/fs/sysfs/file.c > > > +++ b/fs/sysfs/file.c > > > @@ -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); > > > } > > I don't have this in any queue of mine, so I don't understand what you > are asking about. > > totally confused, Wait, this is already in Linus's tree, what are you asking for here? still confused, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sysfs: correctly handle read offset on PREALLOC attrs 2016-09-05 14:13 ` Greg Kroah-Hartman @ 2016-09-05 14:17 ` Konstantin Khlebnikov 0 siblings, 0 replies; 8+ messages in thread From: Konstantin Khlebnikov @ 2016-09-05 14:17 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Konstantin Khlebnikov, Linux Kernel Mailing List, NeilBrown, Tejun Heo, Stable, Alexander Viro On Mon, Sep 5, 2016 at 5:13 PM, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > On Mon, Sep 05, 2016 at 03:46:28PM +0200, Greg Kroah-Hartman wrote: >> On Mon, Sep 05, 2016 at 04:25:48PM +0300, Konstantin Khlebnikov wrote: >> > Bump >> >> Huh? >> >> > On Wed, Jun 22, 2016 at 9:42 PM, Konstantin Khlebnikov >> > <khlebnikov@yandex-team.ru> wrote: >> > > 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. >> > > >> > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> >> > > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") >> > > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787950 >> > > Cc: Stable <stable@vger.kernel.org> # v3.19+ >> > > --- >> > > fs/sysfs/file.c | 8 +++++++- >> > > 1 file changed, 7 insertions(+), 1 deletion(-) >> > > >> > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c >> > > index f35523d4fa3a..b803213d1307 100644 >> > > --- a/fs/sysfs/file.c >> > > +++ b/fs/sysfs/file.c >> > > @@ -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); >> > > } >> >> I don't have this in any queue of mine, so I don't understand what you >> are asking about. >> >> 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-09-05 14:17 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-22 18:42 [PATCH] sysfs: correctly handle read offset on PREALLOC attrs Konstantin Khlebnikov 2016-06-23 21:18 ` Tejun Heo 2016-09-05 13:25 ` Konstantin Khlebnikov 2016-09-05 13:46 ` Greg Kroah-Hartman 2016-09-05 14:02 ` Konstantin Khlebnikov 2016-09-05 14:15 ` Greg Kroah-Hartman 2016-09-05 14:13 ` Greg Kroah-Hartman 2016-09-05 14:17 ` Konstantin Khlebnikov
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).