* [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails
@ 2017-06-22 19:03 Wei Wang
2017-06-22 19:21 ` Maciej Żenczykowski
2017-06-23 18:03 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Wei Wang @ 2017-06-22 19:03 UTC (permalink / raw)
To: David Miller, netdev
Cc: Maciej Żenczykowski, Subash Abhinov Kasiviswanathan, Wei Wang
From: Wei Wang <weiwan@google.com>
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
Signed-off-by: Wei Wang <weiwan@google.com>
Acked-by: Maciej Żenczykowski <maze@google.com>
---
net/ipv6/datagram.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index e011122ebd43..5c786f5ab961 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -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);
--
2.13.1.611.g7e3b11ae1-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails
2017-06-22 19:03 [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails Wei Wang
@ 2017-06-22 19:21 ` Maciej Żenczykowski
2017-06-23 18:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Maciej Żenczykowski @ 2017-06-22 19:21 UTC (permalink / raw)
To: Wei Wang
Cc: David Miller, Linux NetDev, Subash Abhinov Kasiviswanathan, Wei Wang
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails
2017-06-22 19:03 [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails Wei Wang
2017-06-22 19:21 ` Maciej Żenczykowski
@ 2017-06-23 18:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-06-23 18:03 UTC (permalink / raw)
To: tracywwnj; +Cc: netdev, maze, subashab, weiwan
From: Wei Wang <tracywwnj@gmail.com>
Date: Thu, 22 Jun 2017 12:03:41 -0700
> From: Wei Wang <weiwan@google.com>
>
> 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
>
> Signed-off-by: Wei Wang <weiwan@google.com>
> Acked-by: Maciej Żenczykowski <maze@google.com>
Please also add a state test against TCP_ESTABLISHED in UDP v6 early
demux to close this race completely.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-23 18:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-22 19:03 [PATCH v2 net] udpv6: reset daddr and dport in sk if connect() fails Wei Wang
2017-06-22 19:21 ` Maciej Żenczykowski
2017-06-23 18:03 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.