Skip to contentSkip to conversation

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

PATCH Superseded Wei Wang 3 participants 3 messages Jun 22, 2017 – Jun 23, 2017

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

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
index e011122ebd43..5c786f5ab961 100644
@@ -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
#1 lore raw

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.

maintainer
#2 lore raw
In reply to Wei Wang

From: 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(), 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

Please also add a state test against TCP_ESTABLISHED in UDP v6 early demux to close this race completely.

Thanks.