Skip to contentSkip to conversation

nvmet-tcp: Fix NULL dereference when a connect data comes in h2cdata pdu

PATCH New Ziye Yang 1 participant 1 message Aug 21, 2020

Subsystems (2)
lore
Share & tools
lore

Ziye Yang

author
#0 lore raw

PATCH 1/1 nvmet-tcp: Fix NULL dereference when a connect data comes in h2cdata pdu

When handling commands without in-capsule data, we assign the ttag assuming we already have the queue commands array allocated (based on the queue size information in the connect data payload). However if the connect itself did not send the connect data in-capsule we have yet to allocate the queue commands,and we will assign a bogus ttag and suffer a NULL dereference when we receive the corresponding h2cdata pdu.

Fix this by checking if we already allocated commands before dereferencing it when handling h2cdata, if we didn't, its for sure a connect and we should use the preallocated connect command.

---
 drivers/nvme/target/tcp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +9 -2
index 9eda91162fe4..745a8e3ad61b 100644
@@ -427,7 +427,11 @@ static void nvmet_setup_r2t_pdu(struct nvmet_tcp_cmd *cmd)
 	pdu->hdr.plen = cpu_to_le32(pdu->hdr.hlen + hdgst);
 
 	pdu->command_id = cmd->req.cmd->common.command_id;
-	pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd);
+	if (likely(queue->nr_cmds))
+		pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd);
+	else
+		pdu->ttag = 0xffff;
+
 	pdu->r2t_length = cpu_to_le32(cmd->req.transfer_len - cmd->rbytes_done);
 	pdu->r2t_offset = cpu_to_le32(cmd->rbytes_done);
 	if (cmd->queue->hdr_digest) {
@@ -866,7 +870,10 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
 	struct nvme_tcp_data_pdu *data = &queue->pdu.data;
 	struct nvmet_tcp_cmd *cmd;
 
-	cmd = &queue->cmds[data->ttag];
+	if (likely(queue->nr_cmds))
+		cmd = &queue->cmds[data->ttag];
+	else
+		cmd = &queue->connect;
 
 	if (le32_to_cpu(data->data_offset) != cmd->rbytes_done) {
 		pr_err("ttag %u unexpected data offset %u (expected %u)\n",
Signature · 7 lines
2.21.3


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme