Skip to contentSkip to conversation

net: fix skb leak in __skb_tstamp_tx()

PATCH Applied Pratyush Yadav 7 participants 12 messages May 22, 2023 – May 24, 2023

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

PATCH 1/1 net: fix skb leak in __skb_tstamp_tx()

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

---

I do not know this code very well, this was caught by our static analysis tool. I did not try specifically reproducing the leak but I did do a boot test by adding this patch on 6.4-rc3 and the kernel boots fine.

 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -1
index 515ec5cdc79c..cea28d30abb5 100644
@@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
 	} else {
 		skb = skb_clone(orig_skb, GFP_ATOMIC);
 
-		if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+		if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) {
+			kfree_skb(skb);
 			return;
+		}
 	}
 	if (!skb)
 		return;

--
2.39.2

Reviewed-by on v1 1/1
#1 lore raw

From: Pratyush Yadav <[email protected]>
Date: Mon, 22 May 2023 17:30:20 +0200

Quoted 11 lines

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Good catch, thanks!

Quoted 28 lines

---

I do not know this code very well, this was caught by our static analysis tool. I did not try specifically reproducing the leak but I did do a boot test by adding this patch on 6.4-rc3 and the kernel boots fine.

 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -2
index 515ec5cdc79c..cea28d30abb5 100644
@@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
 	} else {
 		skb = skb_clone(orig_skb, GFP_ATOMIC);
 
-		if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+		if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) {
+			kfree_skb(skb);
 			return;
+		}
 	}
 	if (!skb)
 		return;
--

2.39.2

Reviewed-by
#2 lore raw
Quoted 9 lines · Kuniyuki Iwashima

From: Pratyush Yadav <[email protected]>
Date: Mon, 22 May 2023 17:30:20 +0200

Quoted 6 lines

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 7 lines
Quoted 5 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")
#3 lore raw
In reply to Pratyush Yadav

Hi Pratyush,

Quoted 10 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

Thanks,
SJ

Quoted 30 lines

---

I do not know this code very well, this was caught by our static analysis tool. I did not try specifically reproducing the leak but I did do a boot test by adding this patch on 6.4-rc3 and the kernel boots fine.

 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -2
index 515ec5cdc79c..cea28d30abb5 100644
@@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
 	} else {
 		skb = skb_clone(orig_skb, GFP_ATOMIC);
 
-		if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+		if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) {
+			kfree_skb(skb);
 			return;
+		}
 	}
 	if (!skb)
 		return;
--

2.39.2

#4 lore raw
Quoted 10 lines · SeongJae Park

Hi Pratyush,

Quoted 6 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 8 lines
Quoted 4 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

It affects v5.4.243 at least, since that is where I first saw this. But I would expect it to affect other stable kernels it has been backported to as well. I thought using the Fixes tag pointing to the bad upstream commit would be enough for the stable maintainers' tooling/bots to pick this patch up.

In either case, +Cc stable. Link to the patch this thread is talking about [0].

[0] https://lore.kernel.org/netdev/[email protected]/T/#u

Quoted 35 lines

Thanks,
SJ

Quoted 30 lines

---

I do not know this code very well, this was caught by our static analysis tool. I did not try specifically reproducing the leak but I did do a boot test by adding this patch on 6.4-rc3 and the kernel boots fine.

 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -2
index 515ec5cdc79c..cea28d30abb5 100644
@@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
      } else {
              skb = skb_clone(orig_skb, GFP_ATOMIC);
 
-             if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+             if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) {
+                     kfree_skb(skb);
                      return;
+             }
      }
      if (!skb)
              return;
--

2.39.2

Signature · 12 lines
Regards,
Pratyush Yadav



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
maintainer
#5 lore raw
Quoted 21 lines · Pratyush Yadav
Quoted 10 lines · SeongJae Park

Hi Pratyush,

Quoted 6 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 8 lines
Quoted 4 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

Quoted 8 lines

It affects v5.4.243 at least, since that is where I first saw this. But I would expect it to affect other stable kernels it has been backported to as well. I thought using the Fixes tag pointing to the bad upstream commit would be enough for the stable maintainers' tooling/bots to pick this patch up.

In either case, +Cc stable. Link to the patch this thread is talking about [0].

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

#6 lore raw
In reply to SeongJae Park

From: SeongJae Park <[email protected]>
Date: Mon, 22 May 2023 16:55:05 +0000

Quoted 10 lines

Hi Pratyush,

Quoted 6 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 7 lines
Quoted 4 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

In netdev, we add 'net' in Subject for bugfix, then netdev maintainers send a pull request weekly, and stable maintainers backport the fixes to affected trees.

So we usually need not CC stable for netdev patches.

Thanks,
Kuniyuki

Quoted 35 lines

Thanks,
SJ

Quoted 30 lines

---

I do not know this code very well, this was caught by our static analysis tool. I did not try specifically reproducing the leak but I did do a boot test by adding this patch on 6.4-rc3 and the kernel boots fine.

 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -2
index 515ec5cdc79c..cea28d30abb5 100644
@@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
 	} else {
 		skb = skb_clone(orig_skb, GFP_ATOMIC);
 
-		if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+		if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) {
+			kfree_skb(skb);
 			return;
+		}
 	}
 	if (!skb)
 		return;
--

2.39.2

#7 lore raw
Quoted 17 lines · On Mon, 22 May 2023 10:04:30 -0700 Kuniyuki Iwashima <[email protected]> wrote:

From: SeongJae Park <[email protected]>
Date: Mon, 22 May 2023 16:55:05 +0000

Quoted 15 lines

Hi Pratyush,

Quoted 10 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")
Quoted 8 lines
Quoted 2 lines

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

In netdev, we add 'net' in Subject for bugfix, then netdev maintainers send a pull request weekly, and stable maintainers backport the fixes to affected trees.

So we usually need not CC stable for netdev patches.

Thank you for the nice explanation! Seems it is also well documented at
https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html#q-i-see-a-network-patch-and-i-think-it-should-be-backported-to-stable

However, I don't show the 'net' subject rule on the document. Is it documented somewhere else?

Thanks,
SJ

Quoted 4 lines

Thanks,
Kuniyuki

#8 lore raw
Quoted 26 lines · On Mon, 22 May 2023 17:18:53 +0000 SeongJae Park <[email protected]> wrote:
Quoted 24 lines · On Mon, 22 May 2023 10:04:30 -0700 Kuniyuki Iwashima <[email protected]> wrote:

From: SeongJae Park <[email protected]>
Date: Mon, 22 May 2023 16:55:05 +0000

Quoted 10 lines

Hi Pratyush,

Quoted 6 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 7 lines
Quoted 4 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

In netdev, we add 'net' in Subject for bugfix, then netdev maintainers send a pull request weekly, and stable maintainers backport the fixes to affected trees.

Quoted 7 lines
Quoted 1 line

So we usually need not CC stable for netdev patches.

Thank you for the nice explanation! Seems it is also well documented at
https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html#q-i-see-a-network-patch-and-i-think-it-should-be-backported-to-stable

However, I don't show the 'net' subject rule on the document. Is it documented somewhere else?

Seems I overlooked this:
https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html#q-how-do-i-indicate-which-tree-net-vs-net-next-my-patch-should-be-in

Thanks,
SJ

Quoted 9 lines

Thanks,
SJ

Quoted 4 lines

Thanks,
Kuniyuki

#9 lore raw
Quoted 30 lines · On Mon, 22 May 2023 17:23:02 +0000 SeongJae Park <[email protected]> wrote:
Quoted 28 lines · On Mon, 22 May 2023 17:18:53 +0000 SeongJae Park <[email protected]> wrote:
Quoted 25 lines · On Mon, 22 May 2023 10:04:30 -0700 Kuniyuki Iwashima <[email protected]> wrote:

From: SeongJae Park <[email protected]>
Date: Mon, 22 May 2023 16:55:05 +0000

Quoted 10 lines

Hi Pratyush,

Quoted 6 lines · On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav <[email protected]> wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

Quoted 7 lines
Quoted 4 lines

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.")

Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc [email protected]?

In netdev, we add 'net' in Subject for bugfix, then netdev maintainers send a pull request weekly, and stable maintainers backport the fixes to affected trees.

So we usually need not CC stable for netdev patches.

Quoted 8 lines
Quoted 5 lines

Thank you for the nice explanation! Seems it is also well documented at
https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html#q-i-see-a-network-patch-and-i-think-it-should-be-backported-to-stable

However, I don't show the 'net' subject rule on the document. Is it documented somewhere else?

Seems I overlooked this:
https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html#q-how-do-i-indicate-which-tree-net-vs-net-next-my-patch-should-be-in

Sorry for continuing adding noises, but seems the process is, or will be, changed by to the mainline commit dbbe7c962c3a8 ("docs: networking: drop special stable handling").

Thanks,
SJ

[...]

#10 lore raw
Quoted 3 lines · SeongJae Park

Sorry for continuing adding noises, but seems the process is, or will be, changed by to the mainline commit dbbe7c962c3a8 ("docs: networking: drop special stable handling").

Whoever backported the patch because it had a Fixes: tag will do the same if another patch also has a Fixes: tag.

I personally prefer Fixes: very precise tags to weak ones.

#11 lore raw
In reply to Pratyush Yadav
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 22 May 2023 17:30:20 +0200 you wrote:

Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with zerocopy skbs. But it ended up adding a leak of its own. When skb_orphan_frags_rx() fails, the function just returns, leaking the skb it just cloned. Free it before returning.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

[...]

Here is the summary with links:
- [net] net: fix skb leak in __skb_tstamp_tx()

    https://git.kernel.org/netdev/net/c/8a02fb71d719

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html