Skip to contentSkip to conversation

nvmet-tcp: Fix the H2C expected PDU len calculation

PATCH Applied Maurizio Lombardi 3 participants 4 messages Jan 5, 2024 – Jan 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvmet-tcp: Fix the H2C expected PDU len calculation

The nvmet_tcp_handle_h2c_data_pdu() function should take into consideration the possibility that the header digest and/or the data digests are enabled when calculating the expected PDU length, before comparing it to the value stored in cmd->pdu_len.

Fixes efa56305908b ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length")

---

v2: change the variable name, minor code style fixes.

 drivers/nvme/target/tcp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/nvme/target/tcp.c +7 -3
index 3569c1255c5e..4566be0ffe06 100644
@@ -979,7 +979,7 @@ 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;
-	unsigned int plen;
+	unsigned int exp_data_len;
 
 	if (likely(queue->nr_cmds)) {
 		if (unlikely(data->ttag >= queue->nr_cmds)) {
@@ -999,9 +999,13 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
 		goto err_proto;
 	}
 
-	plen = le32_to_cpu(data->hdr.plen);
+	exp_data_len = le32_to_cpu(data->hdr.plen) -
+			nvmet_tcp_hdgst_len(queue) -
+			nvmet_tcp_ddgst_len(queue) -
+			sizeof(*data);
+
 	cmd->pdu_len = le32_to_cpu(data->data_length);
-	if (unlikely(cmd->pdu_len != (plen - sizeof(*data)) ||
+	if (unlikely(cmd->pdu_len != exp_data_len ||
 		     cmd->pdu_len == 0 ||
 		     cmd->pdu_len > NVMET_TCP_MAXH2CDATA)) {
 		pr_err("H2CData PDU len %u is invalid\n", cmd->pdu_len);
Signature · 1 line
2.39.3
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Maurizio Lombardi

The nvmet_tcp_handle_h2c_data_pdu() function should take into consideration the possibility that the header digest and/or the data digests are enabled when calculating the expected PDU length, before comparing it to the value stored in cmd->pdu_len.

Fixes efa56305908b ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length")

Looks good to me.

maintainer Applied
#3 lore raw
In reply to Maurizio Lombardi
Quoted 7 lines · Maurizio Lombardi

The nvmet_tcp_handle_h2c_data_pdu() function should take into consideration the possibility that the header digest and/or the data digests are enabled when calculating the expected PDU length, before comparing it to the value stored in cmd->pdu_len.

Fixes efa56305908b ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length")

Thanks, applied to nvme-6.8.