Skip to contentSkip to conversation

tcp: Fix dst leak in tcp_v6_connect().

PATCH Applied Kuniyuki Iwashima 3 participants 3 messages May 6 – May 7

Subsystems (3)
lore
Share & tools
lore

Kuniyuki Iwashima

author reviewer
#0 lore raw

PATCH 1/1 tcp: Fix dst leak in tcp_v6_connect().

If a socket is bound to a wildcard address, tcp_v[46]_connect() updates it with a non-wildcard address based on the route lookup.

After bhash2 was introduced in the cited commit, we must call inet_bhash2_update_saddr() to update the bhash2 entry as well.

If inet_bhash2_update_saddr() fails, we must release the refcount for dst by ip_route_connect() or ip6_dst_lookup_flow().

While tcp_v4_connect() calls ip_rt_put() in the error path, tcp_v6_connect() does not call dst_release().

Let's call dst_release() when inet_bhash2_update_saddr() fails in tcp_v6_connect().

Fixes 28044fc1d495 ("net: Add a bhash2 table hashed by port and address")
---
 net/ipv6/tcp_ipv6.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +3 -1
index 2c3f7a739709..3f7bab6faf9c 100644
@@ -288,8 +288,10 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
 		saddr = &fl6->saddr;
 
 		err = inet_bhash2_update_saddr(sk, saddr, AF_INET6);
-		if (err)
+		if (err) {
+			dst_release(dst);
 			goto failure;
+		}
 	}
 
 	/* set the source address */
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Kuniyuki Iwashima

If a socket is bound to a wildcard address, tcp_v[46]_connect() updates it with a non-wildcard address based on the route lookup.

After bhash2 was introduced in the cited commit, we must call inet_bhash2_update_saddr() to update the bhash2 entry as well.

If inet_bhash2_update_saddr() fails, we must release the refcount for dst by ip_route_connect() or ip6_dst_lookup_flow().

While tcp_v4_connect() calls ip_rt_put() in the error path, tcp_v6_connect() does not call dst_release().

Quoted 6 lines

Let's call dst_release() when inet_bhash2_update_saddr() fails in tcp_v6_connect().

Fixes 28044fc1d495 ("net: Add a bhash2 table hashed by port and address")
#2 lore raw
In reply to Kuniyuki Iwashima
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 Wed, 6 May 2026 07:04:42 +0000 you wrote:

If a socket is bound to a wildcard address, tcp_v[46]_connect() updates it with a non-wildcard address based on the route lookup.

After bhash2 was introduced in the cited commit, we must call inet_bhash2_update_saddr() to update the bhash2 entry as well.

If inet_bhash2_update_saddr() fails, we must release the refcount for dst by ip_route_connect() or ip6_dst_lookup_flow().

[...]

Here is the summary with links:
- [v1,net] tcp: Fix dst leak in tcp_v6_connect().
https://git.kernel.org/netdev/net/c/ecddc523cfdb

You are awesome, thank you!

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