Skip to content

Commit 98096d8

Browse files
Christoph Hellwigsagigrimberg
authored andcommitted
nvme-fabrics: get a reference when reusing a nvme_host structure
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 <[email protected]> Reviewed-by: Jay Freyensee <[email protected]> Signed-off-by: Sagi Grimberg <[email protected]>
1 parent 7a665d2 commit 98096d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/nvme/host/fabrics.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn)
4747

4848
mutex_lock(&nvmf_hosts_mutex);
4949
host = __nvmf_host_find(hostnqn);
50-
if (host)
50+
if (host) {
51+
kref_get(&host->ref);
5152
goto out_unlock;
53+
}
5254

5355
host = kmalloc(sizeof(*host), GFP_KERNEL);
5456
if (!host)

0 commit comments

Comments
 (0)