Skip to content

Commit ce7723e

Browse files
Varun PrakashChristoph Hellwig
authored andcommitted
nvme-tcp: fix possible req->offset corruption
With commit db5ad6b ("nvme-tcp: try to send request in queue_rq context") r2t and response PDU can get processed while send function is executing. Current data digest send code uses req->offset after kernel_sendmsg(), this creates a race condition where req->offset gets reset before it is used in send function. This can happen in two cases - 1. Target sends r2t PDU which resets req->offset. 2. Target send response PDU which completes the req and then req is used for a new command, nvme_tcp_setup_cmd_pdu() resets req->offset. Fix this by storing req->offset in a local variable and using this local variable after kernel_sendmsg(). Fixes: db5ad6b ("nvme-tcp: try to send request in queue_rq context") Signed-off-by: Varun Prakash <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 25e1f67 commit ce7723e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvme/host/tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ static int nvme_tcp_try_send_data_pdu(struct nvme_tcp_request *req)
10501050
static int nvme_tcp_try_send_ddgst(struct nvme_tcp_request *req)
10511051
{
10521052
struct nvme_tcp_queue *queue = req->queue;
1053+
size_t offset = req->offset;
10531054
int ret;
10541055
struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
10551056
struct kvec iov = {
@@ -1066,7 +1067,7 @@ static int nvme_tcp_try_send_ddgst(struct nvme_tcp_request *req)
10661067
if (unlikely(ret <= 0))
10671068
return ret;
10681069

1069-
if (req->offset + ret == NVME_TCP_DIGEST_LENGTH) {
1070+
if (offset + ret == NVME_TCP_DIGEST_LENGTH) {
10701071
nvme_tcp_done_send_req(queue);
10711072
return 1;
10721073
}

0 commit comments

Comments
 (0)