udpv6: reset daddr and dport in sk if connect() fails
Subsystems (2)
PATCH v2 1/1 udpv6: reset daddr and dport in sk if connect() fails
From: Wei Wang <[email protected]>
In __ip6_datagram_connect(), reset sk->sk_v6_daddr and inet->dport if error occurs so that udp_v6_early_demux() won't consider this socket as a valid candidate for early demux.
v2: fix compilation error
--- net/ipv6/datagram.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv6/datagram.c +7 -1
@@ -250,8 +250,14 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,*/ 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; + } sk->sk_state =TCP_ESTABLISHED ;sk_set_txhash (sk);
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
So this is clearly an improvement over the current state of things.
However, I think there is still a very slight race condition in the error case, since I imagine udp early demux might find the socket while ip6_datagram_dst_update() is running.
It's possible that inet_dport assignment could simply be postponed until after the ip6_datagram_dst_update() call.
Another possibility would be to make the early demux code only capable of finding TCP_ESTABLISHED sockets.
That said, I'm not sure what the right call would be.
David Miller
maintainerFrom: Wei Wang <[email protected]>
Date: Thu, 22 Jun 2017 12:03:41 -0700
Quoted 10 lines
From: Wei Wang <[email protected]>
In
__ip6_datagram_connect(), resetsk->sk_v6_daddrandinet->dportif error occurs so thatudp_v6_early_demux()won't consider this socket as a valid candidate for early demux.v2: fix compilation error
Signed-off-by Wei Wang <[email protected]>
Please also add a state test against TCP_ESTABLISHED in UDP v6 early demux to close this race completely.
Thanks.