All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: fix KASAN warning when parsing host nqn
@ 2018-05-25  9:04 Hannes Reinecke
  2018-05-25 13:48 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Reinecke @ 2018-05-25  9:04 UTC (permalink / raw)


The host nqn actually is smaller than the space reserved for it,
so we should be using strlcpy to keep KASAN happy.

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

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index a5c8ebf24eaa..9961eabb0321 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -57,7 +57,7 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn)
 		goto out_unlock;
 
 	kref_init(&host->ref);
-	memcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
+	strlcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
-- 
2.12.3

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

* [PATCH] nvme: fix KASAN warning when parsing host nqn
  2018-05-25  9:04 [PATCH] nvme: fix KASAN warning when parsing host nqn Hannes Reinecke
@ 2018-05-25 13:48 ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-05-25 13:48 UTC (permalink / raw)


Thanks,

applied to nvme-4.18-2.

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

* [PATCH] nvme: fix KASAN warning when parsing host nqn
  2018-05-14 12:44 ` Christoph Hellwig
@ 2018-05-25  8:53   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-05-25  8:53 UTC (permalink / raw)


On Mon, May 14, 2018@02:44:14PM +0200, Christoph Hellwig wrote:
> On Mon, May 14, 2018@02:23:12PM +0200, Hannes Reinecke wrote:
> > -	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.

Can you resend a fixed up version?

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

* [PATCH] nvme: fix KASAN warning when parsing host nqn
  2018-05-14 12:23 Hannes Reinecke
@ 2018-05-14 12:44 ` Christoph Hellwig
  2018-05-25  8:53   ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2018-05-14 12:44 UTC (permalink / raw)


On Mon, May 14, 2018@02:23:12PM +0200, Hannes Reinecke wrote:
> -	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.

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

* [PATCH] nvme: fix KASAN warning when parsing host nqn
@ 2018-05-14 12:23 Hannes Reinecke
  2018-05-14 12:44 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Reinecke @ 2018-05-14 12:23 UTC (permalink / 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

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

end of thread, other threads:[~2018-05-25 13:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-25  9:04 [PATCH] nvme: fix KASAN warning when parsing host nqn Hannes Reinecke
2018-05-25 13:48 ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2018-05-14 12:23 Hannes Reinecke
2018-05-14 12:44 ` Christoph Hellwig
2018-05-25  8:53   ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.