Skip to contentSkip to conversation

tcp: cleanup sk_tx_skb_cache before reuse

PATCH Applied Eric Dumazet 3 participants 3 messages Mar 29, 2019 – Apr 1, 2019

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

PATCH 1/1 tcp: cleanup sk_tx_skb_cache before reuse

TCP stack relies on the fact that a freshly allocated skb has skb->cb[] and skb_shinfo(skb)->tx_flags cleared.

When recycling tx skb, we must ensure these fields are cleared.

Fixes 472c2e07eef0 ("tcp: add one skb cache for tx")
Cc Soheil Hassas Yeganeh <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/tcp.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/tcp.c +2 -0
index 82bd707c03472f2cebb1a90d5f1c13acc821468f..603e770d59b3db96adca9602319d2f6970a56285 100644
@@ -872,6 +872,8 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
 			sk->sk_tx_skb_cache = NULL;
 			pskb_trim(skb, 0);
 			INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
+			skb_shinfo(skb)->tx_flags = 0;
+			memset(TCP_SKB_CB(skb), 0, sizeof(struct tcp_skb_cb));
 			return skb;
 		}
 	}
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Dumazet

TCP stack relies on the fact that a freshly allocated skb has skb->cb[] and skb_shinfo(skb)->tx_flags cleared.

When recycling tx skb, we must ensure these fields are cleared.

Fixes 472c2e07eef0 ("tcp: add one skb cache for tx")
Cc Soheil Hassas Yeganeh <[email protected]>
Cc Willem de Bruijn <[email protected]>

Nice catch! Thank you!

Quoted 20 lines
---
 net/ipv4/tcp.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/tcp.c +2 -1
index 82bd707c03472f2cebb1a90d5f1c13acc821468f..603e770d59b3db96adca9602319d2f6970a56285 100644
@@ -872,6 +872,8 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
                        sk->sk_tx_skb_cache = NULL;
                        pskb_trim(skb, 0);
                        INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
+                       skb_shinfo(skb)->tx_flags = 0;
+                       memset(TCP_SKB_CB(skb), 0, sizeof(struct tcp_skb_cb));
                        return skb;
                }
        }
--

2.21.0.392.gf8f6787159e-goog