nvmet-tcp: fix a segmentation fault during io parsing error
Subsystems (2)
PATCH 1/1 nvmet-tcp: fix a segmentation fault during io parsing error
From: Elad Grupi <[email protected]>
In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.
--- drivers/nvme/target/tcp.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/nvme/target/tcp.c +16 -1
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,return 0 ; } +if (unlikely ((cmd->flags &NVMET_TCP_F_INIT_FAILED ) && +nvmet_tcp_has_data_in (cmd) && +nvmet_tcp_has_inline_data (cmd))) { +/* +* wait for inline data before processing the response +* so the iov will not be freed +*/ + queue->snd_cmd =NULL ; + goto done_send; + } +if (cmd->state ==NVMET_TCP_SEND_DATA_PDU ) { ret =nvmet_try_send_data_pdu (cmd);if (ret <=0 )
@@ -1106,7 +1117,9 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) { cmd->req.execute (&cmd->req); - } + }else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED ) && + cmd->rbytes_done == cmd->req.transfer_len) +nvmet_tcp_queue_response (&cmd->req);nvmet_prepare_receive_pdu (queue);return 0 ;
@@ -1146,6 +1159,8 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) cmd->req.execute (&cmd->req); +else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_tcp_queue_response (&cmd->req); ret =0 ; out:nvmet_prepare_receive_pdu (queue);
Signature · 7 lines
2.18.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 9 lines
drivers/nvme/target/tcp.c +1
-0@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,return 0 ; } + if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
drivers/nvme/target/tcp.c static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, · line 715
Quoted 10 lines
drivers/nvme/target/tcp.c +10
-0+ nvmet_tcp_has_data_in(cmd) && + nvmet_tcp_has_inline_data(cmd))) { +/* +* wait for inline data before processing the response +* so the iov will not be freed +*/ + queue->snd_cmd =NULL ; + goto done_send; + } +
Hi Elad,
Although this works, I think Sagi would prefer not adding this to the response queue in nvmet_tcp_queue_response().
Quoted 15 lines
drivers/nvme/target/tcp.c +3
-1if (cmd->state ==NVMET_TCP_SEND_DATA_PDU ) { ret =nvmet_try_send_data_pdu (cmd);if (ret <=0 )@@ -1106,7 +1117,9 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) { cmd->req.execute (&cmd->req); - } + }else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED ) && + cmd->rbytes_done == cmd->req.transfer_len) +nvmet_tcp_queue_response (&cmd->req);nvmet_prepare_receive_pdu (queue);return 0 ;
drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1163
Quoted 5 lines
drivers/nvme/target/tcp.c +2
-0@@ -1146,6 +1159,8 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) cmd->req.execute (&cmd->req); +else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_tcp_queue_response (&cmd->req);
Here we also need to check cmd->rbytes_done == cmd->req.transfer_len as we could get multiple data pdu.
(BTW, did you forget to add [PATCH v2] to the subject line?)
Thanks,
Hou
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Right, I see.
But when calling nvmet_tcp_queue_response, the flag for NVMET_TCP_F_INIT_FAILED is not yet set.
The flag is being set only after nvmet_req_init returns in nvmet_tcp_handle_req_failure.
It is possible to block in nvmet_tcp_queue_response any command that has unattended inline data, will that work for you?
Thanks,
Elad
-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Friday, 19 March 2021 5:53
To: Grupi, Elad
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] nvmet-tcp: fix a segmentation fault during io parsing error
[EXTERNAL EMAIL]
Quoted 9 lines
drivers/nvme/target/tcp.c +1
-0@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,return 0 ; } + if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
drivers/nvme/target/tcp.c static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, · line 715
Quoted 10 lines
drivers/nvme/target/tcp.c +10
-0+ nvmet_tcp_has_data_in(cmd) && + nvmet_tcp_has_inline_data(cmd))) { +/* +* wait for inline data before processing the response +* so the iov will not be freed +*/ + queue->snd_cmd =NULL ; + goto done_send; + } +
Hi Elad,
Although this works, I think Sagi would prefer not adding this to the response queue in nvmet_tcp_queue_response().
Quoted 15 lines
drivers/nvme/target/tcp.c +3
-1if (cmd->state ==NVMET_TCP_SEND_DATA_PDU ) { ret =nvmet_try_send_data_pdu (cmd);if (ret <=0 )@@ -1106,7 +1117,9 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) { cmd->req.execute (&cmd->req); - } + }else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED ) && + cmd->rbytes_done == cmd->req.transfer_len) +nvmet_tcp_queue_response (&cmd->req);nvmet_prepare_receive_pdu (queue);return 0 ;
drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1163
Quoted 5 lines
drivers/nvme/target/tcp.c +2
-0@@ -1146,6 +1159,8 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) cmd->req.execute (&cmd->req); +else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_tcp_queue_response (&cmd->req);
Here we also need to check cmd->rbytes_done == cmd->req.transfer_len as we could get multiple data pdu.
(BTW, did you forget to add [PATCH v2] to the subject line?)
Thanks,
Hou
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 4 lines · Elad
Right, I see.
But when calling
nvmet_tcp_queue_response, the flag forNVMET_TCP_F_INIT_FAILEDis not yet set. The flag is being set only afternvmet_req_initreturns innvmet_tcp_handle_req_failure.
Hmm, that's true.
Quoted 1 line
It is possible to block in
nvmet_tcp_queue_responseany command that has unattended inline data, will that work for you?
It's OK with me.
Thnaks,
Hou
Quoted 60 lines
Thanks,
Elad-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Friday, 19 March 2021 5:53
To: Grupi, Elad
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] nvmet-tcp: fix a segmentation fault during io parsing error[EXTERNAL EMAIL]
Quoted 9 lines
drivers/nvme/target/tcp.c +1
-0@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,return 0 ; } + if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&drivers/nvme/target/tcp.c static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, · line 715
Quoted 10 lines
drivers/nvme/target/tcp.c +10
-0+ nvmet_tcp_has_data_in(cmd) && + nvmet_tcp_has_inline_data(cmd))) { +/* +* wait for inline data before processing the response +* so the iov will not be freed +*/ + queue->snd_cmd =NULL ; + goto done_send; + } +Hi Elad,
Although this works, I think Sagi would prefer not adding this to the response queue innvmet_tcp_queue_response().Quoted 15 lines
drivers/nvme/target/tcp.c +3
-1if (cmd->state ==NVMET_TCP_SEND_DATA_PDU ) { ret =nvmet_try_send_data_pdu (cmd);if (ret <=0 )@@ -1106,7 +1117,9 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) { cmd->req.execute (&cmd->req); - } + }else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED ) && + cmd->rbytes_done == cmd->req.transfer_len) +nvmet_tcp_queue_response (&cmd->req);nvmet_prepare_receive_pdu (queue);return 0 ;drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1163
Quoted 5 lines
drivers/nvme/target/tcp.c +2
-0@@ -1146,6 +1159,8 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED ) && cmd->rbytes_done == cmd->req.transfer_len) cmd->req.execute (&cmd->req); +else if ((cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_tcp_queue_response (&cmd->req);Here we also need to check
cmd->rbytes_done==cmd->req.transfer_lenas we could get multiple data pdu.
Quoted 4 lines
(BTW, did you forget to add [PATCH v2] to the subject line?)
Thanks,
Hou
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme