aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2018-06-18 15:30:37 -0400
committerDavid S. Miller <davem@davemloft.net>2018-06-19 19:03:06 -0400
commit8c43bd1706885ba1acfa88da02bc60a2ec16f68c (patch)
treeeb62f5e69eaf9c60c5a18c2427cf9ed9804c7e7b
parentf696a21c229ac3e85bc239efc52f4530b43002c5 (diff)
net/tcp: Fix socket lookups with SO_BINDTODEVICE
Similar to 69678bcd4d2d ("udp: fix SO_BINDTODEVICE"), TCP socket lookups need to fail if dev_match is not true. Currently, a packet to a given port can match a socket bound to device when it should not. In the VRF case, this causes the lookup to hit a VRF socket and not a global socket resulting in a response trying to go through the VRF when it should not. Fixes: 3fa6f616a7a4d ("net: ipv4: add second dif to inet socket lookups") Fixes: 4297a0ef08572 ("net: ipv6: add second dif to inet6 socket lookups") Reported-by: Lou Berger <lberger@labn.net> Diagnosed-by: Renato Westphal <renato@opensourcerouting.org> Tested-by: Renato Westphal <renato@opensourcerouting.org> Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/inet_hashtables.c4
-rw-r--r--net/ipv6/inet6_hashtables.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 31ff46daae97..3647167c8fa3 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -243,9 +243,9 @@ static inline int compute_score(struct sock *sk, struct net *net,
243 bool dev_match = (sk->sk_bound_dev_if == dif || 243 bool dev_match = (sk->sk_bound_dev_if == dif ||
244 sk->sk_bound_dev_if == sdif); 244 sk->sk_bound_dev_if == sdif);
245 245
246 if (exact_dif && !dev_match) 246 if (!dev_match)
247 return -1; 247 return -1;
248 if (sk->sk_bound_dev_if && dev_match) 248 if (sk->sk_bound_dev_if)
249 score += 4; 249 score += 4;
250 } 250 }
251 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 251 if (sk->sk_incoming_cpu == raw_smp_processor_id())
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 2febe26de6a1..595ad408dba0 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -113,9 +113,9 @@ static inline int compute_score(struct sock *sk, struct net *net,
113 bool dev_match = (sk->sk_bound_dev_if == dif || 113 bool dev_match = (sk->sk_bound_dev_if == dif ||
114 sk->sk_bound_dev_if == sdif); 114 sk->sk_bound_dev_if == sdif);
115 115
116 if (exact_dif && !dev_match) 116 if (!dev_match)
117 return -1; 117 return -1;
118 if (sk->sk_bound_dev_if && dev_match) 118 if (sk->sk_bound_dev_if)
119 score++; 119 score++;
120 } 120 }
121 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 121 if (sk->sk_incoming_cpu == raw_smp_processor_id())