Skip to content

Commit 0bf04c8

Browse files
Hannes ReineckeChristoph Hellwig
authored andcommitted
nvme-tcp: sanitize request list handling
Validate the request in nvme_tcp_handle_r2t() to ensure it's not part of any list, otherwise a malicious R2T PDU might inject a loop in request list processing. Signed-off-by: Hannes Reinecke <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent e714370 commit 0bf04c8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/nvme/host/tcp.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ nvme_tcp_fetch_request(struct nvme_tcp_queue *queue)
452452
return NULL;
453453
}
454454

455-
list_del(&req->entry);
455+
list_del_init(&req->entry);
456+
init_llist_node(&req->lentry);
456457
return req;
457458
}
458459

@@ -560,6 +561,8 @@ static int nvme_tcp_init_request(struct blk_mq_tag_set *set,
560561
req->queue = queue;
561562
nvme_req(rq)->ctrl = &ctrl->ctrl;
562563
nvme_req(rq)->cmd = &pdu->cmd;
564+
init_llist_node(&req->lentry);
565+
INIT_LIST_HEAD(&req->entry);
563566

564567
return 0;
565568
}
@@ -764,6 +767,14 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue,
764767
return -EPROTO;
765768
}
766769

770+
if (llist_on_list(&req->lentry) ||
771+
!list_empty(&req->entry)) {
772+
dev_err(queue->ctrl->ctrl.device,
773+
"req %d unexpected r2t while processing request\n",
774+
rq->tag);
775+
return -EPROTO;
776+
}
777+
767778
req->pdu_len = 0;
768779
req->h2cdata_left = r2t_length;
769780
req->h2cdata_offset = r2t_offset;
@@ -2638,6 +2649,8 @@ static void nvme_tcp_submit_async_event(struct nvme_ctrl *arg)
26382649
ctrl->async_req.offset = 0;
26392650
ctrl->async_req.curr_bio = NULL;
26402651
ctrl->async_req.data_len = 0;
2652+
init_llist_node(&ctrl->async_req.lentry);
2653+
INIT_LIST_HEAD(&ctrl->async_req.entry);
26412654

26422655
nvme_tcp_queue_request(&ctrl->async_req, true);
26432656
}

0 commit comments

Comments
 (0)