nvme-fabrics: get a reference when reusing a nvme_host structure
authorChristoph Hellwig <hch@lst.de>
Thu, 18 Aug 2016 18:16:35 +0000 (11:16 -0700)
committerSagi Grimberg <sagi@grimberg.me>
Fri, 19 Aug 2016 11:22:12 +0000 (14:22 +0300)
Without this we'll get a use after free after connecting two controller
using the same hostnqn and then disconnecting one of them.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jay Freyensee <james_p_freyensee@linux.intel.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
drivers/nvme/host/fabrics.c

index be0b106..4eff491 100644 (file)
@@ -47,8 +47,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn)
 
        mutex_lock(&nvmf_hosts_mutex);
        host = __nvmf_host_find(hostnqn);
-       if (host)
+       if (host) {
+               kref_get(&host->ref);
                goto out_unlock;
+       }
 
        host = kmalloc(sizeof(*host), GFP_KERNEL);
        if (!host)