netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: fix skb leak in __skb_tstamp_tx()
@ 2023-05-22 15:30 Pratyush Yadav
  2023-05-22 15:45 ` Kuniyuki Iwashima
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Pratyush Yadav @ 2023-05-22 15:30 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Pratyush Yadav, Kuniyuki Iwashima, Willem de Bruijn,
	Norbert Manthey, netdev, linux-kernel

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.")
Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
---

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(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 515ec5cdc79c..cea28d30abb5 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-24  4:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-22 15:30 [PATCH net] net: fix skb leak in __skb_tstamp_tx() Pratyush Yadav
2023-05-22 15:45 ` Kuniyuki Iwashima
2023-05-22 16:11   ` Willem de Bruijn
2023-05-22 16:55 ` SeongJae Park
2023-05-22 17:03   ` Pratyush Yadav
2023-05-22 17:08     ` Greg KH
2023-05-22 17:04   ` Kuniyuki Iwashima
2023-05-22 17:18     ` SeongJae Park
2023-05-22 17:23       ` SeongJae Park
2023-05-22 17:33         ` SeongJae Park
2023-05-22 18:57           ` Eric Dumazet
2023-05-24  4:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).