public inbox for linux-bcache@vger.kernel.org
 help / color / mirror / Atom feed
From: Dongbo Cao <cdbdyx@163.com>
To: colyli@suse.de
Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org,
	linux-kernel@vger.kernel.org, Dongbo Cao <cdbdyx@163.com>
Subject: [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs
Date: Fri, 14 Sep 2018 18:12:59 +0800	[thread overview]
Message-ID: <20180914101259.4169-1-cdbdyx@163.com> (raw)

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

             reply	other threads:[~2018-09-14 10:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-14 10:12 Dongbo Cao [this message]
2018-09-15  1:20 ` [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs Junhui Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180914101259.4169-1-cdbdyx@163.com \
    --to=cdbdyx@163.com \
    --cc=colyli@suse.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox