Commit 85cb73ff authored by Wei Wang's avatar Wei Wang Committed by David S. Miller

net: ipv6: reset daddr and dport in sk if connect() fails

In __ip6_datagram_connect(), reset sk->sk_v6_daddr and inet->dport if
error occurs.
In udp_v6_early_demux(), check for sk_state to make sure it is in
TCP_ESTABLISHED state.
Together, it makes sure unconnected UDP socket won't be considered as a
valid candidate for early demux.

v3: add TCP_ESTABLISHED state check in udp_v6_early_demux()
v2: fix compilation error

Fixes: 5425077d ("net: ipv6: Add early demux handler for UDP unicast")
Signed-off-by: default avatarWei Wang <weiwan@google.com>
Acked-by: default avatarMaciej Żenczykowski <maze@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d0c32a16
...@@ -250,8 +250,14 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, ...@@ -250,8 +250,14 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,
*/ */
err = ip6_datagram_dst_update(sk, true); err = ip6_datagram_dst_update(sk, true);
if (err) if (err) {
/* Reset daddr and dport so that udp_v6_early_demux()
* fails to find this socket
*/
memset(&sk->sk_v6_daddr, 0, sizeof(sk->sk_v6_daddr));
inet->inet_dport = 0;
goto out; goto out;
}
sk->sk_state = TCP_ESTABLISHED; sk->sk_state = TCP_ESTABLISHED;
sk_set_txhash(sk); sk_set_txhash(sk);
......
...@@ -879,7 +879,8 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net, ...@@ -879,7 +879,8 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net,
struct sock *sk; struct sock *sk;
udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) { udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
if (INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif)) if (sk->sk_state == TCP_ESTABLISHED &&
INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif))
return sk; return sk;
/* Only check first socket in chain */ /* Only check first socket in chain */
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment