LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs
@ 2018-09-14 10:12 Dongbo Cao
  2018-09-15  1:20 ` Junhui Tang
  0 siblings, 1 reply; 2+ messages in thread
From: Dongbo Cao @ 2018-09-14 10:12 UTC (permalink / raw)
  To: colyli; +Cc: kent.overstreet, linux-bcache, linux-kernel, Dongbo Cao

do some checks on the label's length and ending.

Signed-off-by: Dongbo Cao <cdbdyx@163.com>
---
 drivers/md/bcache/sysfs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index e64c718f..cce793ef 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -447,8 +447,15 @@ STORE(__bch_flash_dev)
 	}
 
 	if (attr == &sysfs_label) {
+		if (size > SB_LABEL_SIZE)
+			return -EINVAL;
 		memcpy(u->label, buf, SB_LABEL_SIZE);
-		bch_uuid_write(d->c);
+		if (size < SB_LABEL_SIZE)
+			u->label[size] = '\0';
+		if (size && u->label[size - 1] == '\n')
+			u->label[size - 1] = '\0';
+		if(d->c)
+			bch_uuid_write(d->c);
 	}
 
 	if (attr == &sysfs_unregister) {
-- 
2.17.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs
  2018-09-14 10:12 [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs Dongbo Cao
@ 2018-09-15  1:20 ` Junhui Tang
  0 siblings, 0 replies; 2+ messages in thread
From: Junhui Tang @ 2018-09-15  1:20 UTC (permalink / raw)
  To: cdbdyx; +Cc: colyli, Kent Overstreet, linux-bcache, linux-kernel

Seems something wrong
when  size = SB_LABEL_SIZE and   u->label[size - 1] != '\n'
please check again.

---------------------------------------------------------------------------
Tang Junhui
Forever me is me
---------------------------------------------------------------------------

Dongbo Cao <cdbdyx@163.com> 于2018年9月14日周五 下午6:13写道:
>
> do some checks on the label's length and ending.
>
> Signed-off-by: Dongbo Cao <cdbdyx@163.com>
> ---
>  drivers/md/bcache/sysfs.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index e64c718f..cce793ef 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -447,8 +447,15 @@ STORE(__bch_flash_dev)
>         }
>
>         if (attr == &sysfs_label) {
> +               if (size > SB_LABEL_SIZE)
> +                       return -EINVAL;
>                 memcpy(u->label, buf, SB_LABEL_SIZE);
> -               bch_uuid_write(d->c);
> +               if (size < SB_LABEL_SIZE)
> +                       u->label[size] = '\0';
> +               if (size && u->label[size - 1] == '\n')
> +                       u->label[size - 1] = '\0';
> +               if(d->c)
> +                       bch_uuid_write(d->c);
>         }
>
>         if (attr == &sysfs_unregister) {
> --
> 2.17.1
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-14 10:12 [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs Dongbo Cao
2018-09-15  1:20 ` Junhui Tang

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox