public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipv6: udp: fix memory leak in udpv6_sendmsg error path
@ 2026-04-22 10:58 Mingyu Wang
  2026-04-22 11:55 ` Sabrina Dubroca
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mingyu Wang @ 2026-04-22 10:58 UTC (permalink / raw)
  To: willemdebruijn.kernel, davem, dsahern, edumazet, kuba, pabeni
  Cc: horms, netdev, linux-kernel, Mingyu Wang

During fuzzing with failslab enabled, a memory leak was observed in the
IPv6 UDP send path.

When sending via the lockless fast path (!corkreq), udpv6_sendmsg()
calls ip6_make_skb() and assumes that the routing entry (dst_entry)
reference has been stolen by the callee. However, if ip6_make_skb()
fails early (e.g., due to an ENOMEM from memory allocation failure),
it returns an error pointer without consuming the dst reference.

Since udpv6_sendmsg() unconditionally jumps to the 'out_no_dst' label,
the unconsumed dst_entry is never released, resulting in a memory leak.

Fix this by explicitly calling dst_release(dst) when ip6_make_skb()
returns an error.

Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
---
 net/ipv6/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 15e032194ecc..b83ecfd729af 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1706,8 +1706,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 				   dst_rt6_info(dst),
 				   msg->msg_flags, &cork);
 		err = PTR_ERR(skb);
-		if (!IS_ERR_OR_NULL(skb))
+		if (!IS_ERR_OR_NULL(skb)) {
 			err = udp_v6_send_skb(skb, fl6, &cork.base);
+		} else {
+			dst_release(dst);
+		}
 		/* ip6_make_skb steals dst reference */
 		goto out_no_dst;
 	}
-- 
2.34.1


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

end of thread, other threads:[~2026-04-22 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 10:58 [PATCH] ipv6: udp: fix memory leak in udpv6_sendmsg error path Mingyu Wang
2026-04-22 11:55 ` Sabrina Dubroca
2026-04-22 15:04 ` Jakub Kicinski
2026-04-22 15:41 ` [syzbot ci] " syzbot ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox