Skip to content
/ linux Public
forked from torvalds/linux

Commit 76d54bf

Browse files
mitaChristoph Hellwig
authored and
Christoph Hellwig
committed
nvme-tcp: don't access released socket during error recovery
While the error recovery work is temporarily failing reconnect attempts, running the 'nvme list' command causes a kernel NULL pointer dereference by calling getsockname() with a released socket. During error recovery work, the nvme tcp socket is released and a new one created, so it is not safe to access the socket without proper check. Signed-off-by: Akinobu Mita <[email protected]> Fixes: 02c57a8 ("nvme-tcp: print actual source IP address through sysfs "address" attr") Reviewed-by: Martin Belanger <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 51d24f7 commit 76d54bf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/nvme/host/tcp.c

+6
Original file line numberDiff line numberDiff line change
@@ -2489,13 +2489,19 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
24892489

24902490
len = nvmf_get_address(ctrl, buf, size);
24912491

2492+
mutex_lock(&queue->queue_lock);
2493+
2494+
if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags))
2495+
goto done;
24922496
ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr);
24932497
if (ret > 0) {
24942498
if (len > 0)
24952499
len--; /* strip trailing newline */
24962500
len += scnprintf(buf + len, size - len, "%ssrc_addr=%pISc\n",
24972501
(len) ? "," : "", &src_addr);
24982502
}
2503+
done:
2504+
mutex_unlock(&queue->queue_lock);
24992505

25002506
return len;
25012507
}

0 commit comments

Comments
 (0)