Skip to contentSkip to conversation

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

PATCH In review Wei Wang 3 participants 3 messages Jun 23, 2017 – Jun 25, 2017

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v3 1/1 net: ipv6: 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.
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

---
 net/ipv6/datagram.c | 8 +++++++-
 net/ipv6/udp.c      | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
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);
net/ipv6/udp.c +2 -1
index 2b33847bf931..d494b2621b11 100644
@@ -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;
Signature · 1 line
2.13.1.611.g7e3b11ae1-goog
maintainer
#1 lore raw

From: Wei Wang <[email protected]>
Date: Fri, 23 Jun 2017 15:25:37 -0700

Quoted 9 lines

From: Wei Wang <[email protected]>

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.

Quoted 7 lines
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

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.

#2 lore raw
Quoted 23 lines · David Miller

From: Wei Wang <[email protected]>
Date: Fri, 23 Jun 2017 15:25:37 -0700

Quoted 9 lines

From: Wei Wang <[email protected]>

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.

Quoted 7 lines
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

Please don't format the tag area like this, if you want to put a change log put it first.

Quoted 6 lines

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