Skip to contentSkip to conversation

nvme: fix KASAN warning when parsing host nqn

PATCH New Hannes Reinecke 3 participants 3 messages May 14, 2018 – May 25, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix KASAN warning when parsing host nqn

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(-)
drivers/nvme/host/fabrics.c +2 -2
index 124c458806df..dec7d4629f38 100644
@@ -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:
Signature · 1 line
2.12.3
#1 lore raw

PATCH 1/1 nvme: fix KASAN warning when parsing host nqn

drivers/nvme/host/fabrics.c static struct nvmf_host *nvmf_host_add(const char *hostnqn) · line 60

Quoted 8 lines · Hannes Reinecke
drivers/nvme/host/fabrics.c +2 -2
-	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));

That pattern is called strcpy :) And we better use strlcpy here, just in case.

#2 lore raw

PATCH 1/1 nvme: fix KASAN warning when parsing host nqn

Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Hannes Reinecke
drivers/nvme/host/fabrics.c +1 -1
-	host = kmalloc(sizeof(*host), GFP_KERNEL);
+	host = kzalloc(sizeof(*host), GFP_KERNEL);
 	if (!host)
 		goto out_unlock;
Quoted 6 lines

drivers/nvme/host/fabrics.c static struct nvmf_host *nvmf_host_add(const char *hostnqn) · line 60

Quoted 3 lines
drivers/nvme/host/fabrics.c +1 -1
 	kref_init(&host->ref);
-	memcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
+	memcpy(host->nqn, hostnqn, strlen(hostnqn));

That pattern is called strcpy :) And we better use strlcpy here, just in case.

Can you resend a fixed up version?