Commit ecddc523 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Jakub Kicinski
Browse files

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: 28044fc1 ("net: Add a bhash2 table hashed by port and address")
Reported-by: default avatarDamiano Melotti <melotti@google.com>
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260506070443.1699879-1-kuniyu@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 019c892e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -288,9 +288,11 @@ 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 */
	np->saddr = *saddr;