Skip to contentSkip to conversation

net: gro: fix double aggregation of flush-marked skbs

PATCH Superseded Shiming Cheng 2 participants 3 messages Jul 6 – Jul 7

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 net: gro: fix double aggregation of flush-marked skbs

The skb_gro_receive_list() function is missing a critical safety check that exists in the skb_gro_receive() implementation. Specifically, it does not validate NAPI_GRO_CB(skb)->flush before allowing packet aggregation

This allows already-GRO'd packets with existing frag_list to be re-aggregated into a new GRO session, corrupting the frag_list chain structure. When skb_segment() attempts to unpack these malformed packets, it encounters invalid state and triggers a kernel panic.

Scenario (Tethering/Device forwarding):
1. Driver: Generated aggregated packet P1 via LRO with frag_list
2. Dev A: Receives aggregated fraglist packet and flush flag set
3. Dev A: Re-enters GRO, skb_gro_receive_list() is called
4. Missing flush check allows re-aggregation despite flush flag
5. Frag_list chain becomes corrupted (loops or dangling refs)
6. Dev B: TX path calls skb_segment(), crashes on corrupted frag_list

Root cause in skb_segment():
The check at line ~4891:

    if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
        (skb_headlen(list_skb) == len || sg)) {

When frag_list is corrupted by double aggregation, when list_skb is a NULL pointer from skb->next, skb_headlen(list_skb) dereference NULL/corrupted pointers occurs.

Call Trace:
 skb_headlen(NULL skb)
 skb_segment
 tcp_gso_segment
 tcp4_gso_segment
 inet_gso_segment
 skb_mac_gso_segment
 __skb_gso_segment
 skb_gso_segment
 validate_xmit_skb
 validate_xmit_skb_list
 sch_direct_xmit
 qdisc_restart
 __qdisc_run
 qdisc_run
 net_tx_action

Fix: Add NAPI_GRO_CB(skb)->flush validation to the early-return check in skb_gro_receive_list(), matching the defensive programming pattern of skb_gro_receive().

Fixes 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
---
 net/core/gro.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/gro.c +8 -1
index 35f2f708f010..b1573d98f3a5 100644
@@ -229,7 +229,14 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
 
 int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb)
 {
-	if (unlikely(p->len + skb->len >= 65536))
+	/*
+	 * Packets marked with NAPI_GRO_CB(skb)->flush have already gone
+	 * through GRO/LRO processing and must not be aggregated again.
+	 * Re-entering frag_list GRO may corrupt the frag_list chain and
+	 * later crash during GSO segmentaiont.
+	 */
+	if (unlikely(p->len + skb->len >= 65536 ||
+		     NAPI_GRO_CB(skb)->flush))
 		return -E2BIG;
 
 	if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
Signature · 1 line
2.45.2
#1 lore raw

[PATCH net v5]

Quoted 4 lines · Shiming Cheng

The skb_gro_receive_list() function is missing a critical safety check that exists in the skb_gro_receive() implementation. Specifically, it does not validate NAPI_GRO_CB(skb)->flush before allowing packet aggregation

In v3 I requested referring to the commit that fixed this in
skb_gro_receive: commit 0ab03f353d36 ("net-gro: Fix GRO flush when receiving a GSO packet."). That explains the issue well.

Quoted 56 lines

This allows already-GRO'd packets with existing frag_list to be re-aggregated into a new GRO session, corrupting the frag_list chain structure. When skb_segment() attempts to unpack these malformed packets, it encounters invalid state and triggers a kernel panic.

Scenario (Tethering/Device forwarding):
1. Driver: Generated aggregated packet P1 via LRO with frag_list
2. Dev A: Receives aggregated fraglist packet and flush flag set
3. Dev A: Re-enters GRO, skb_gro_receive_list() is called
4. Missing flush check allows re-aggregation despite flush flag
5. Frag_list chain becomes corrupted (loops or dangling refs)
6. Dev B: TX path calls skb_segment(), crashes on corrupted frag_list

Root cause in skb_segment():
The check at line ~4891:

    if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
        (skb_headlen(list_skb) == len || sg)) {

When frag_list is corrupted by double aggregation, when list_skb is a NULL pointer from skb->next, skb_headlen(list_skb) dereference NULL/corrupted pointers occurs.

Call Trace:
 skb_headlen(NULL skb)
 skb_segment
 tcp_gso_segment
 tcp4_gso_segment
 inet_gso_segment
 skb_mac_gso_segment
 __skb_gso_segment
 skb_gso_segment
 validate_xmit_skb
 validate_xmit_skb_list
 sch_direct_xmit
 qdisc_restart
 __qdisc_run
 qdisc_run
 net_tx_action

Fix: Add NAPI_GRO_CB(skb)->flush validation to the early-return check in skb_gro_receive_list(), matching the defensive programming pattern of skb_gro_receive().

Fixes 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
---
 net/core/gro.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/gro.c +0 -0
index 35f2f708f010..b1573d98f3a5 100644

net/core/gro.c int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · line 237

Quoted 10 lines
net/core/gro.c +6 -1
@@ -229,7 +229,14 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
 
 int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb)
 {
-	if (unlikely(p->len + skb->len >= 65536))
+	/*
+	 * Packets marked with NAPI_GRO_CB(skb)->flush have already gone
+	 * through GRO/LRO processing and must not be aggregated again.
+	 * Re-entering frag_list GRO may corrupt the frag_list chain and
+	 * later crash during GSO segmentaiont.
+	 */

Such a verbose comment is not needed. Code would be overwhelmed by comments if done everywhere.

Quoted 8 lines
net/core/gro.c +2 -0
+	if (unlikely(p->len + skb->len >= 65536 ||
+		     NAPI_GRO_CB(skb)->flush))
 		return -E2BIG;
 
 	if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
Signature · 1 line
2.45.2
#2 lore raw
Quoted 14 lines · Willem de Bruijn

External email : Please do not click links or open attachments until you have verified the sender or the content.

[PATCH net v5]

Quoted 6 lines · Shiming Cheng

The skb_gro_receive_list() function is missing a critical safety check
that exists in the skb_gro_receive() implementation. Specifically, it
does not validate NAPI_GRO_CB(skb)->flush before allowing packet aggregation

Quoted 3 lines

In v3 I requested referring to the commit that fixed this in
skb_gro_receive: commit 0ab03f353d36 ("net-gro: Fix GRO flush when receiving a GSO packet."). That explains the issue well.

updated in PATCH V6.

Quoted 64 lines
Quoted 64 lines

This allows already-GRO'd packets with existing frag_list to be re-aggregated into a new GRO session, corrupting the frag_list chain
structure. When skb_segment() attempts to unpack these malformed packets,
it encounters invalid state and triggers a kernel panic.

Scenario (Tethering/Device forwarding):
1. Driver: Generated aggregated packet P1 via LRO with frag_list
2. Dev A: Receives aggregated fraglist packet and flush flag set
3. Dev A: Re-enters GRO, skb_gro_receive_list() is called
4. Missing flush check allows re-aggregation despite flush flag
5. Frag_list chain becomes corrupted (loops or dangling refs)
6. Dev B: TX path calls skb_segment(), crashes on corrupted
frag_list

Root cause in skb_segment():
The check at line ~4891:

    if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
        (skb_headlen(list_skb) == len || sg)) {

When frag_list is corrupted by double aggregation, when list_skb
is
a NULL pointer from skb->next, skb_headlen(list_skb) dereference NULL/corrupted pointers occurs.

Call Trace:
 skb_headlen(NULL skb)
 skb_segment
 tcp_gso_segment
 tcp4_gso_segment
 inet_gso_segment
 skb_mac_gso_segment
 __skb_gso_segment
 skb_gso_segment
 validate_xmit_skb
 validate_xmit_skb_list
 sch_direct_xmit
 qdisc_restart
 __qdisc_run
 qdisc_run
 net_tx_action

Fix: Add NAPI_GRO_CB(skb)->flush validation to the early-return check in
skb_gro_receive_list(), matching the defensive programming pattern of
skb_gro_receive().

Fixes 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
---
 net/core/gro.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/gro.c +0 -0
index 35f2f708f010..b1573d98f3a5 100644
@@ -229,7 +229,14 @@ int skb_gro_receive(struct sk_buff *p, struct
 sk_buff *skb)
 
Quoted 16 lines

net/core/gro.c int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · line 237

Quoted 12 lines
net/core/gro.c +2 -1
 int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb)
 {
-     if (unlikely(p->len + skb->len >= 65536))
+     /*
+      * Packets marked with NAPI_GRO_CB(skb)->flush have already

gone
+ * through GRO/LRO processing and must not be aggregated
again.
+ * Re-entering frag_list GRO may corrupt the frag_list chain
and

net/core/gro.c +2 -0
+      * later crash during GSO segmentaiont.
+      */

Such a verbose comment is not needed. Code would be overwhelmed by comments if done everywhere.

updated comment in PATCH V6.

Quoted 10 lines
Quoted 8 lines
net/core/gro.c +2 -1
+     if (unlikely(p->len + skb->len >= 65536 ||
+                  NAPI_GRO_CB(skb)->flush))
              return -E2BIG;
 
      if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
--

2.45.2