Skip to contentSkip to conversation

nvmet_tcp: fix header digest verification

PATCH Sagi Grimberg 2 participants 6 messages Oct 19, 2021 – Oct 27, 2021 1 message not in the archive NVMe

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Sagi Grimberg

author maintainer
#1 lore raw
Quoted 5 lines

pass the correct length to nvmet_tcp_hdgst. when verify_hdgst, need to pass pdu header len. This fixes a wrong behaviour where
header digest verification pass although digest is wrong

Amit, can you describe what you mean here?
what is wrong about the digest?

What is currently passed in len is queue->offset, which is the temporary offset from the pdu, which is equal to hdr->hlen because we verify the digest right after we finish reading the PDU header.

Quoted 11 lines
---
  drivers/nvme/target/tcp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/tcp.c +0 -0
index 6eb0b3153477..954c27a94561 100644

drivers/nvme/target/tcp.c static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue, · line 271

Quoted 5 lines
drivers/nvme/target/tcp.c +1 -1
@@ -268,7 +268,7 @@ static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue,
  	}
 
  	recv_digest = *(__le32 *)(pdu + hdr->hlen);
-	nvmet_tcp_hdgst(queue->rcv_hash, pdu, len);
+	nvmet_tcp_hdgst(queue->rcv_hash, pdu, hdr->hlen);

If at all, the caller should pass hdr->hlen and keep this generic.

#2 lore raw

One of our tests found that
With the current code,
recv_digest == exp_digest even if the pdu header digest is being modified (synthetically)
For example:
In case that pdu header digest is changed to 0xffffffff, recv == exp == 0xfffffff, and nvmet_tcp_verify_hdgst returns 0 - which is wrong

Internal Use - Confidential

-----Original Message-----
From: Sagi Grimberg <[email protected]>
Sent: Tuesday, October 19, 2021 3:19 PM
To: Engel, Amit; [email protected]; [email protected]
Subject: Re: [PATCH] nvmet_tcp: fix header digest verification

[EXTERNAL EMAIL]

Quoted 4 lines

pass the correct length to nvmet_tcp_hdgst. when verify_hdgst, need to pass pdu header len. This fixes a wrong behaviour where
header digest verification pass although digest is wrong

Amit, can you describe what you mean here?
what is wrong about the digest?

What is currently passed in len is queue->offset, which is the temporary offset from the pdu, which is equal to hdr->hlen because we verify the digest right after we finish reading the PDU header.

Quoted 11 lines
---
  drivers/nvme/target/tcp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/tcp.c +0 -0
index 6eb0b3153477..954c27a94561 100644

drivers/nvme/target/tcp.c static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue, · line 271

Quoted 5 lines
drivers/nvme/target/tcp.c +1 -1
@@ -268,7 +268,7 @@ static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue,
  	}
 
  	recv_digest = *(__le32 *)(pdu + hdr->hlen);
-	nvmet_tcp_hdgst(queue->rcv_hash, pdu, len);
+	nvmet_tcp_hdgst(queue->rcv_hash, pdu, hdr->hlen);

If at all, the caller should pass hdr->hlen and keep this generic.

author maintainer
#3 lore raw
Quoted 6 lines

One of our tests found that
With the current code,
recv_digest == exp_digest even if the pdu header digest is being modified (synthetically)
For example:
In case that pdu header digest is changed to 0xffffffff, recv == exp == 0xfffffff, and nvmet_tcp_verify_hdgst returns 0 - which is wrong

Not sure I follow. Can you describe in which case the passed offset != hdr->hlen?

Quoted 1 line

Internal Use - Confidential

Is this confidential?

#4 lore raw

In nvmet_tcp_try_recv_pdu:
1. After kernel_recvmsg, 'queue->offset' is equal to 'sizeof(struct nvme_tcp_hdr)'

2. update queue->left = hdr->hlen - queue->offset + hdgst and 'goto recv'

3. after recvmsg , the offset is greater than the digest.

So , In this case offset != hdr->hlen

This will lead to nvmet_tcp_verify_hdgst to always pass, which

Thanks
Amit

Internal Use - Confidential

-----Original Message-----
From: Sagi Grimberg <[email protected]>
Sent: Wednesday, October 20, 2021 8:53 PM
To: Engel, Amit; [email protected]; [email protected]
Subject: Re: [PATCH] nvmet_tcp: fix header digest verification

[EXTERNAL EMAIL]

Quoted 6 lines

One of our tests found that
With the current code,
recv_digest == exp_digest even if the pdu header digest is being modified (synthetically) For example:
In case that pdu header digest is changed to 0xffffffff, recv == exp == 0xfffffff, and nvmet_tcp_verify_hdgst returns 0 - which is wrong

Not sure I follow. Can you describe in which case the passed offset != hdr->hlen?

Quoted 1 line

Internal Use - Confidential

Is this confidential?

author maintainer
#5 lore raw
Quoted 11 lines

In nvmet_tcp_try_recv_pdu:
1. After kernel_recvmsg, 'queue->offset' is equal to 'sizeof(struct nvme_tcp_hdr)'

2. update queue->left = hdr->hlen - queue->offset + hdgst and 'goto recv'

3. after recvmsg , the offset is greater than the digest.

So , In this case offset != hdr->hlen

This will lead to nvmet_tcp_verify_hdgst to always pass, which

I see, so the patch should modify the call-site to nvmet_tcp_verify_hdgst to pass in hdr->hlen.

Quoted 6 lines

Thanks
Amit

Internal Use - Confidential

You should remove this footer from your emails to the public mailing list...

#6 lore raw

Thank you Sagi. I just sent the patch

Amit

-----Original Message-----
From: Sagi Grimberg <[email protected]>
Sent: Tuesday, October 26, 2021 6:35 PM
To: Engel, Amit; [email protected]; [email protected]
Subject: Re: [PATCH] nvmet_tcp: fix header digest verification

[EXTERNAL EMAIL]

Quoted 10 lines

In nvmet_tcp_try_recv_pdu:
1. After kernel_recvmsg, 'queue->offset' is equal to 'sizeof(struct nvme_tcp_hdr)'

2. update queue->left = hdr->hlen - queue->offset + hdgst and 'goto recv'

3. after recvmsg , the offset is greater than the digest.

So , In this case offset != hdr->hlen

This will lead to nvmet_tcp_verify_hdgst to always pass, which

I see, so the patch should modify the call-site to nvmet_tcp_verify_hdgst to pass in hdr->hlen.

Quoted 6 lines

Thanks
Amit

Internal Use - Confidential

You should remove this footer from your emails to the public mailing list...