[PATCH v3 net] net: ipv6: reset daddr and dport in sk if connect() fails

Subsystems: networking [general], the rest, user datagram protocol (udp)

STALE3399d REVIEWED: 1 (0M)

1 review trailer.

3 messages, 3 authors, 2017-06-25 · open the first message on its own page

[PATCH v3 net] net: ipv6: reset daddr and dport in sk if connect() fails

From: Wei Wang <hidden>
Date: 2017-06-23 22:25:45

From: Wei Wang <redacted>

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.

Fixes: 5425077d73e0 ("net: ipv6: Add early demux handler for UDP unicast")

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

Signed-off-by: Wei Wang <redacted>
Acked-by: Maciej Żenczykowski <redacted>
---
 net/ipv6/datagram.c | 8 +++++++-
 net/ipv6/udp.c      | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
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);
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 2b33847bf931..d494b2621b11 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -880,7 +880,8 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net,
 	struct sock *sk;
 
 	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;
 		/* Only check first socket in chain */
 		break;
-- 
2.13.1.611.g7e3b11ae1-goog

Re: [PATCH v3 net] net: ipv6: reset daddr and dport in sk if connect() fails

From: David Miller <davem@davemloft.net>
Date: 2017-06-25 15:46:56

From: Wei Wang <redacted>
Date: Fri, 23 Jun 2017 15:25:37 -0700
From: Wei Wang <redacted>

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.

Fixes: 5425077d73e0 ("net: ipv6: Add early demux handler for UDP unicast")

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

Signed-off-by: Wei Wang <redacted>
Acked-by: Maciej Żenczykowski <redacted>
Please don't format the tag area like this, if you want to put a change
log put it first.

Then put all of the tags (Fixes:, Signed-off-by:, Acked-by:, etc.)
together with no empty line separators, at the end.

I fixed it up this time.

Applied and queued up for -stable, thanks.

Re: [PATCH v3 net] net: ipv6: reset daddr and dport in sk if connect() fails

From: Wei Wang <hidden>
Date: 2017-06-25 20:47:55

On Sun, Jun 25, 2017 at 8:46 AM, David Miller [off-list ref] wrote:
From: Wei Wang <redacted>
Date: Fri, 23 Jun 2017 15:25:37 -0700
quoted
From: Wei Wang <redacted>

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.

Fixes: 5425077d73e0 ("net: ipv6: Add early demux handler for UDP unicast")

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

Signed-off-by: Wei Wang <redacted>
Acked-by: Maciej Żenczykowski <redacted>
Please don't format the tag area like this, if you want to put a change
log put it first.

Then put all of the tags (Fixes:, Signed-off-by:, Acked-by:, etc.)
together with no empty line separators, at the end.

I fixed it up this time.

Applied and queued up for -stable, thanks.
Got it. Will note it down.
Thanks for taking care of it.

Wei
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help