linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH] nvme: fix KASAN warning when parsing host nqn
Date: Mon, 14 May 2018 14:23:12 +0200	[thread overview]
Message-ID: <20180514122312.62068-1-hare@suse.de> (raw)

The host nqn is actually smaller than the space reserved for it,
so we should only copy the allocated data to keep KASAN happy.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/host/fabrics.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 124c458806df..dec7d4629f38 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -52,12 +52,12 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn)
 		goto out_unlock;
 	}
 
-	host = kmalloc(sizeof(*host), GFP_KERNEL);
+	host = kzalloc(sizeof(*host), GFP_KERNEL);
 	if (!host)
 		goto out_unlock;
 
 	kref_init(&host->ref);
-	memcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
+	memcpy(host->nqn, hostnqn, strlen(hostnqn));
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
-- 
2.12.3

             reply	other threads:[~2018-05-14 12:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-14 12:23 Hannes Reinecke [this message]
2018-05-14 12:44 ` [PATCH] nvme: fix KASAN warning when parsing host nqn Christoph Hellwig
2018-05-25  8:53   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2018-05-25  9:04 Hannes Reinecke
2018-05-25 13:48 ` Christoph Hellwig

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=20180514122312.62068-1-hare@suse.de \
    --to=hare@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).