Skip to content

Commit

Permalink
nvme-fabrics: get a reference when reusing a nvme_host structure
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and sagigrimberg committed Aug 19, 2016
1 parent 7a665d2 commit 98096d8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/nvme/host/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 98096d8

Please sign in to comment.