Skip to contentSkip to conversation

tcp: do not recycle cloned skbs

PATCH In review Eric Dumazet 2 participants 5 messages May 15, 2019

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

PATCH 1/1 tcp: do not recycle cloned skbs

It is illegal to change arbitrary fields in skb_shared_info if the skb is cloned.

Before calling skb_zcopy_clear() we need to ensure this rule, therefore we need to move the test from sk_stream_alloc_skb() to sk_wmem_free_skb()

Fixes 4f661542a402 ("tcp: fix zerocopy and notsent_lowat issues")
---
 include/net/sock.h | 2 +-
 net/ipv4/tcp.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/net/sock.h +1 -1
index 4d208c0f9c14b7c8f5975dcc69e13d89d1880df5..0680fa98849761d187c0149a57fa2d5d683a9a76 100644
@@ -1473,7 +1473,7 @@ static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
 	sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
 	sk->sk_wmem_queued -= skb->truesize;
 	sk_mem_uncharge(sk, skb->truesize);
-	if (!sk->sk_tx_skb_cache) {
+	if (!sk->sk_tx_skb_cache && !skb_cloned(skb)) {
 		skb_zcopy_clear(skb, true);
 		sk->sk_tx_skb_cache = skb;
 		return;
net/ipv4/tcp.c +1 -1
index 1fa15beb83806696a6b4f5eddb7e45c13a2dea45..53d61ca3ac4b4ee8992742247629bce7f71ee659 100644
@@ -855,7 +855,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
 
 	if (likely(!size)) {
 		skb = sk->sk_tx_skb_cache;
-		if (skb && !skb_cloned(skb)) {
+		if (skb) {
 			skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
 			sk->sk_tx_skb_cache = NULL;
 			pskb_trim(skb, 0);
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
maintainer
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:10:15 -0700

Quoted 10 lines

It is illegal to change arbitrary fields in skb_shared_info if the skb is cloned.

Before calling skb_zcopy_clear() we need to ensure this rule, therefore we need to move the test from sk_stream_alloc_skb() to sk_wmem_free_skb()

Fixes 4f661542a402 ("tcp: fix zerocopy and notsent_lowat issues")

Applied and queued up for -stable.

#2 lore raw
Quoted 11 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:10:15 -0700

Quoted 7 lines

It is illegal to change arbitrary fields in skb_shared_info if the skb is cloned.

Before calling skb_zcopy_clear() we need to ensure this rule, therefore we need to move the test from sk_stream_alloc_skb() to sk_wmem_free_skb()

Quoted 5 lines
Quoted 3 lines
Fixes 4f661542a402 ("tcp: fix zerocopy and notsent_lowat issues")

Applied and queued up for -stable.

Note the patch targets current net tree, but does not need to be backported to older kernel versions
(4f661542a402 is only in upcoming 5.2)

Thanks !

maintainer
#3 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:26:54 -0700

Quoted 16 lines · David Miller
Quoted 15 lines

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:10:15 -0700

Quoted 10 lines

It is illegal to change arbitrary fields in skb_shared_info if the skb is cloned.

Before calling skb_zcopy_clear() we need to ensure this rule, therefore we need to move the test from sk_stream_alloc_skb() to sk_wmem_free_skb()

Fixes 4f661542a402 ("tcp: fix zerocopy and notsent_lowat issues")
Quoted 5 lines
Quoted 1 line

Applied and queued up for -stable.

Note the patch targets current net tree, but does not need to be backported to older kernel versions
(4f661542a402 is only in upcoming 5.2)

Doesn't it fix a fix for something in 5.0?

#4 lore raw
Quoted 20 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:26:54 -0700

Quoted 16 lines · David Miller
Quoted 15 lines

From: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 09:10:15 -0700

Quoted 10 lines

It is illegal to change arbitrary fields in skb_shared_info if the skb is cloned.

Before calling skb_zcopy_clear() we need to ensure this rule, therefore we need to move the test from sk_stream_alloc_skb() to sk_wmem_free_skb()

Fixes 4f661542a402 ("tcp: fix zerocopy and notsent_lowat issues")
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Applied and queued up for -stable.

Note the patch targets current net tree, but does not need to be backported to older kernel versions
(4f661542a402 is only in upcoming 5.2)

Doesn't it fix a fix for something in 5.0?

Hmm no, the whole thing is new for 5.2 only.

commit 472c2e07eef045145bc1493cc94a01c87140780a

Author: Eric Dumazet <[email protected]>
Date:   Fri Mar 22 08:56:39 2019 -0700

tcp: add one skb cache for tx