nvme-tcp: check that full ICResp is received
PATCH 1/1 nvme-tcp: check that full ICResp is received
nvme_tcp_init_connection() attempts to receive an ICResp PDU but only checks that the return value from recvmsg() is non-negative. If the sender closes the TCP connection or sends fewer than 128 bytes, this check will pass even though the full PDU wasn't received.
Ensure the full ICResp PDU is received by checking that recvmsg() returns the expected 128 bytes.
Additionally set the MSG_WAITALL flag for recvmsg(), as a sender could split the ICResp over multiple TCP frames. Without MSG_WAITALL, recvmsg() could return prematurely with only part of the PDU.
--- drivers/nvme/host/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/tcp.c +2 -1
@@ -1447,13 +1447,14 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) iov.iov_len =sizeof (*icresp);if (nvme_tcp_queue_tls (queue)) { msg.msg_control = cbuf; msg.msg_controllen =sizeof (cbuf); } + msg.msg_flags =MSG_WAITALL ; ret =kernel_recvmsg (queue->sock, &msg, &iov,1 , iov.iov_len, msg.msg_flags); -if (ret <0 ) { +if (ret <sizeof (*icresp)) {pr_warn ("queue %d: failed to receive icresp, error %d\n" ,nvme_tcp_queue_id (queue), ret); goto free_icresp; } ret = -ENOTCONN ;
Signature · 1 line
2.45.2
Sagi Grimberg
maintainerQuoted 11 lines · Caleb Sander Mateos
nvme_tcp_init_connection()attempts to receive an ICResp PDU but only checks that the return value fromrecvmsg()is non-negative. If the sender closes the TCP connection or sends fewer than 128 bytes, this check will pass even though the full PDU wasn't received.Ensure the full ICResp PDU is received by checking that
recvmsg()returns the expected 128 bytes.Additionally set the
MSG_WAITALLflag forrecvmsg(), as a sender could split the ICResp over multiple TCP frames. WithoutMSG_WAITALL,recvmsg()could return prematurely with only part of the PDU.
Thanks Caleb, this looks good.
I think we want to adjust the title to express that this is a bug fix, as well as adding a fixes tag - so it can be picked up by stable kernels as back as possible.
The title can perhaps be:
nvme-tcp: Fix possible connection establishment failure when receiving partial ICResp PDUs