Skip to contentSkip to conversation

nvme: initialize hostid uuid in nvmf_host_default to not leak kernel memory

PATCH In review Johannes Thumshirn 4 participants 4 messages Jan 9, 2018 – Jan 10, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: initialize hostid uuid in nvmf_host_default to not leak kernel memory

Alexander reports:
according to KMSAN (and common sense as well) the following code in drivers/nvme/host/fabrics.c
(http://elixir.free-electrons.com/linux/latest/source/drivers/nvme/host/fabrics.c#L68):

    72         host = kmalloc(sizeof(*host), GFP_KERNEL);
    73         if (!host)
    74                 return NULL;
    75
    76         kref_init(&host->ref);
    77         snprintf(host->nqn, NVMF_NQN_SIZE,
    78                 "nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id);

uses uninitialized heap memory to generate the unique id for the NVMF host. If I'm understanding correctly, it can be then passed to the userspace, so the contents of the uninitialized chunk may potentially leak.
If the specification doesn't rely on this UID to be random or unique, I suggest using kzalloc() here, otherwise it might be a good idea to use a real RNG.

this assumption is correct so initialize the host->id using uuid_gen() as it was done before commit 6bfe04255d5e ("nvme: add hostid token to fabric options").

Fixes 6bfe04255d5e ("nvme: add hostid token to fabric options")
Reported-by Alexander Potapenko <glider at google.com>
Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 drivers/nvme/host/fabrics.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/fabrics.c +1 -0
index 76b4fe6816a0..894c2ccb3891 100644
@@ -74,6 +74,7 @@ static struct nvmf_host *nvmf_host_default(void)
 		return NULL;
 
 	kref_init(&host->ref);
+	uuid_gen(&host->id);
 	snprintf(host->nqn, NVMF_NQN_SIZE,
 		"nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id);
 
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Johannes Thumshirn

Alexander reports:
according to KMSAN (and common sense as well) the following code in drivers/nvme/host/fabrics.c
(http://elixir.free-electrons.com/linux/latest/source/drivers/nvme/host/fabrics.c#L68):

    72         host = kmalloc(sizeof(*host), GFP_KERNEL);
    73         if (!host)
    74                 return NULL;
    75
    76         kref_init(&host->ref);
    77         snprintf(host->nqn, NVMF_NQN_SIZE,
    78                 "nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id);

uses uninitialized heap memory to generate the unique id for the NVMF host. If I'm understanding correctly, it can be then passed to the userspace, so the contents of the uninitialized chunk may potentially leak.
If the specification doesn't rely on this UID to be random or unique, I suggest using kzalloc() here, otherwise it might be a good idea to use a real RNG.

Quoted 7 lines

this assumption is correct so initialize the host->id using uuid_gen() as it was done before commit 6bfe04255d5e ("nvme: add hostid token to fabric options").

Fixes 6bfe04255d5e ("nvme: add hostid token to fabric options")

Thanks for the report and the fix. It'd still be good to use the kzalloc variant in addition to this.

#2 lore raw

I've already got the equivalent fix from Ewan queued up in nvme-4.15.

#3 lore raw

PATCH 1/1 nvme: initialize hostid uuid in nvmf_host_default to not leak kernel memory

In reply to Keith Busch
Quoted 3 lines · Keith Busch

Thanks for the report and the fix. It'd still be good to use the kzalloc variant in addition to this.

Yes, thanks. Good point.

kmalloc() is used elsewhere as well, so maybe another patch?

-Ewan