Skip to contentSkip to conversation

gro: bug fix in identifying 0 length tcp packets

PATCH Superseded Kumara Parameshwaran 2 participants 4 messages Apr 3, 2022 – Jul 18, 2022 1 message not in the archive

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gro: bug fix in identifying 0 length tcp packets

As the minimum Ethernet frame size is 64 bytes, a 0 length tcp payload without tcp options would be 54 bytes and hence there would be padding. So it would be incorrect to use the packet length to determine the tcp data length.

Fixes 1e4cf4d6d4fb ("gro: cleanup")

---
v1:
Do not use packet length to determine the tcp data length as the packet length could have padded bytes. This would lead to addition of 0 length tcp packets into the GRO layer when there ethernet fram is padded.

 lib/gro/gro_tcp4.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/gro/gro_tcp4.c +2 -3
index 7498c66..45e3f48 100644
@@ -198,7 +198,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	struct rte_tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	int32_t tcp_dl;
-	uint16_t ip_id, hdr_len, frag_off;
+	uint16_t ip_id, frag_off;
 	uint8_t is_atomic;
 
 	struct tcp4_flow_key key;
@@ -217,7 +217,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
 	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
 	tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
-	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
 	/*
 	 * Don't process the packet which has FIN, SYN, RST, PSH, URG, ECE
@@ -229,7 +228,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	 * Don't process the packet whose payload length is less than or
 	 * equal to 0.
 	 */
-	tcp_dl = pkt->pkt_len - hdr_len;
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - (pkt->l3_len + pkt->l4_len);
 	if (tcp_dl <= 0)
 		return -1;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 55 lines

From: Kumara Parameshwaran [mailto:[email protected]]
Sent: Sunday, 3 April 2022 13.51

As the minimum Ethernet frame size is 64 bytes, a 0 length tcp payload without tcp options would be 54 bytes and hence there would be padding. So it would be incorrect to use the packet length to determine the tcp data length.

Fixes 1e4cf4d6d4fb ("gro: cleanup")

---
v1:
Do not use packet length to determine the tcp data length as the packet length could have padded bytes. This would lead to addition of 0 length tcp packets into the GRO layer when there ethernet fram is padded.

 lib/gro/gro_tcp4.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/gro/gro_tcp4.c +1 -2
index 7498c66..45e3f48 100644
@@ -198,7 +198,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	struct rte_tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	int32_t tcp_dl;
-	uint16_t ip_id, hdr_len, frag_off;
+	uint16_t ip_id, frag_off;
 	uint8_t is_atomic;
 
 	struct tcp4_flow_key key;
@@ -217,7 +217,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
 	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt-
 >l2_len);
 	tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
-	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
 	/*

* Don't process the packet which has FIN, SYN, RST, PSH, URG,
ECE

lib/gro/gro_tcp4.c +2 -2
@@ -229,7 +228,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	 * Don't process the packet whose payload length is less than or
 	 * equal to 0.
 	 */
-	tcp_dl = pkt->pkt_len - hdr_len;
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - (pkt->l3_len
+ pkt->l4_len);
 	if (tcp_dl <= 0)
 		return -1;
 
--
Quoted 2 lines

2.7.4

Please confirm that this does not introduce a buffer overrun regarding malformed packets, e.g. a small packet with ipv4_hdr->total_length set to 65000.

I haven't looked at the patch in context, so my concern may be irrelevant.

-Morten

#2 lore raw

PATCH v2 1/1 gro: bug fix in identifying 0 length tcp packets

In reply to Kumara Parameshwaran

From: Kumara Parameshwaran <[email protected]>

As the minimum Ethernet frame size is 64 bytes, a 0 length tcp payload without tcp options would be 54 bytes and hence there would be padding. So it would be incorrect to use the packet length to determine the tcp data length.

Fixes 1e4cf4d6d4fb ("gro: cleanup")

---
v1:
Do not use packet length to determine the tcp data length as the packet length could have padded bytes. This would lead to addition of 0 length tcp packets into the GRO layer when there ethernet fram is padded.
v2:
Since using ip packet length to determine the tcp data length, validate the ip packet length

 lib/gro/gro_tcp4.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/gro/gro_tcp4.c +5 -4
index 7498c66..30f5922 100644
@@ -198,7 +198,8 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	struct rte_tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	int32_t tcp_dl;
-	uint16_t ip_id, hdr_len, frag_off;
+	uint16_t ip_id, frag_off;
+	uint16_t ip_len;
 	uint8_t is_atomic;
 
 	struct tcp4_flow_key key;
@@ -217,7 +218,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
 	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
 	tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
-	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
 	/*
 	 * Don't process the packet which has FIN, SYN, RST, PSH, URG, ECE
@@ -229,8 +229,9 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	 * Don't process the packet whose payload length is less than or
 	 * equal to 0.
 	 */
-	tcp_dl = pkt->pkt_len - hdr_len;
-	if (tcp_dl <= 0)
+	ip_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
+	tcp_dl = ip_len - (pkt->l3_len + pkt->l4_len);
+	if (tcp_dl <= 0 || ip_len > pkt->pkt_len)
 		return -1;
 
 	/*
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): CANxNyatRmEU8mMag=Z=dg-200pBTmfBdP-ML4VEwYmG6X73EpA@mail.gmail.com

#4 lore raw

Hi Jiayu,
Can you please suggest if the patch can be used ? When timestamps are disabled we would unnecessarily indulge pure TCP ack packets in the GRO layer. Or can we have a fix where if the TCP timestamp option is not present in the packet, do not process the packet, return immediately ?

Thanks,
Param

Quoted 70 lines · kumaraparameshwaran rathinavel

Hi,

I would like you to review this patch and let me know what you think of it.

Thanks,
Kumara.

---------- Forwarded message ---------
From: Kumara Parameshwaran <[email protected]>
Date: Sun, Apr 3, 2022 at 5:20 PM
Subject: [PATCH v1] gro: bug fix in identifying 0 length tcp packets
To: <[email protected]>
Cc: <[email protected]>, Kumara Parameshwaran <[email protected]>, < [email protected]>, Kumara Parameshwaran <[email protected]>

As the minimum Ethernet frame size is 64 bytes, a 0 length tcp payload without tcp options would be 54 bytes and hence there would be padding. So it would be incorrect to use the packet length to determine the tcp data length.

Fixes 1e4cf4d6d4fb ("gro: cleanup")

---
v1:
Do not use packet length to determine the tcp data length as the packet length could have padded bytes. This would lead to addition of 0 length tcp packets into the GRO layer when there ethernet fram is padded.

 lib/gro/gro_tcp4.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/gro/gro_tcp4.c +2 -4
index 7498c66..45e3f48 100644
@@ -198,7 +198,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
        struct rte_tcp_hdr *tcp_hdr;
        uint32_t sent_seq;
        int32_t tcp_dl;
-       uint16_t ip_id, hdr_len, frag_off;
+       uint16_t ip_id, frag_off;
        uint8_t is_atomic;
 
        struct tcp4_flow_key key;
@@ -217,7 +217,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
        eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
        ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
        tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
-       hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
        /*
         * Don't process the packet which has FIN, SYN, RST, PSH, URG, ECE
@@ -229,7 +228,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,
         * Don't process the packet whose payload length is less than or
         * equal to 0.
         */
-       tcp_dl = pkt->pkt_len - hdr_len;
+       tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - (pkt->l3_len +
 pkt->l4_len);
        if (tcp_dl <= 0)
                return -1;
 
--

2.7.4