nvme-tcp: don't access released socket during error recovery
PATCH 1/1 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.
--- drivers/nvme/host/tcp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/nvme/host/tcp.c +6 -0
@@ -2492,6 +2492,10 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len =nvmf_get_address (ctrl, buf, size); +mutex_lock (&queue->queue_lock); + +if (!test_bit (NVME_TCP_Q_LIVE , &queue->flags)) + goto done; ret =kernel_getsockname (queue->sock, (struct sockaddr *)&src_addr);if (ret >0 ) {if (len >0 )
@@ -2499,6 +2503,8 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len +=scnprintf (buf + len, size - len,"%ssrc_addr=%pISc\n" , (len) ?"," :"" , &src_addr); } +done: +mutex_unlock (&queue->queue_lock);return len; }
Signature · 1 line
2.34.1
Quoted 36 lines · Akinobu Mita
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 02c57a82c008 ("nvme-tcp: print actual source IP address through sysfs "address" attr")Cc Martin Belanger <[email protected]>Cc Sagi Grimberg <[email protected]>Cc Chaitanya Kulkarni <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Keith Busch <[email protected]>Cc Jens Axboe <[email protected]>Cc Hannes Reinecke <[email protected]>--- drivers/nvme/host/tcp.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/nvme/host/tcp.c +4
-0@@ -2492,6 +2492,10 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len =nvmf_get_address (ctrl, buf, size); +mutex_lock (&queue->queue_lock); + +if (!test_bit (NVME_TCP_Q_LIVE , &queue->flags)) + goto done; ret =kernel_getsockname (queue->sock, (struct sockaddr *)&src_addr);if (ret >0 ) {if (len >0 )
drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · line 2510
Quoted 8 lines
drivers/nvme/host/tcp.c +2
-0@@ -2499,6 +2503,8 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len +=scnprintf (buf + len, size - len,"%ssrc_addr=%pISc\n" , (len) ?"," :"" , &src_addr); } +done: +mutex_unlock (&queue->queue_lock);return len; }
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
Belanger, Martin
Reviewed-byQuoted 47 lines · Akinobu Mita
Quoted 26 lines
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 02c57a82c008 ("nvme-tcp: print actual source IP address throughsysfs "address" attr")
Cc: Martin Belanger <[email protected]>
Cc: Sagi Grimberg <[email protected]>
Cc: Chaitanya Kulkarni <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Keith Busch <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Hannes Reinecke <[email protected]>--- drivers/nvme/host/tcp.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/nvme/host/tcp.c index renamed from drivers/nvme/host/tcp.c +0
-0
1955c0ec209e..7723a4989524100644drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct · line 2500
Quoted 9 lines
drivers/nvme/host/tcp.c +4
-0@@ -2492,6 +2492,10 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len =nvmf_get_address (ctrl, buf, size); +mutex_lock (&queue->queue_lock); + +if (!test_bit (NVME_TCP_Q_LIVE , &queue->flags)) + goto done; ret = kernel_getsockname(queue->sock, (struct sockaddr*)&src_addr);
drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct
Quoted 3 lines
drivers/nvme/host/tcp.c +0
-0if (ret >0 ) {if (len > 0)
drivers/nvme/host/tcp.c +0
-0@@ -2499,6 +2503,8 @@ static int nvme_tcp_get_address(struct
nvme_ctrl*ctrl, char *buf, int size)Quoted 6 lines
drivers/nvme/host/tcp.c +2
-0len +=scnprintf (buf + len, size - len,"%ssrc_addr=%pISc\n" , (len) ?"," :"" , &src_addr); } +done: +mutex_unlock (&queue->queue_lock);
Quoted 3 lines
drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · line 2510
Quoted 2 lines
drivers/nvme/host/tcp.c +0
-0return len; }Reviewed-by Hannes Reinecke <[email protected]>
Thanks,
applied to nvme-6.3.