nvme: fix KASAN warning when parsing host nqn
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
@@ -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
Christoph Hellwig
maintainerPATCH 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.
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
-1kref_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?