Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Ahern and committed by
David S. Miller
8c43bd17 f696a21c

+4 -4
+2 -2
net/ipv4/inet_hashtables.c
··· 243 243 bool dev_match = (sk->sk_bound_dev_if == dif || 244 244 sk->sk_bound_dev_if == sdif); 245 245 246 - if (exact_dif && !dev_match) 246 + if (!dev_match) 247 247 return -1; 248 - if (sk->sk_bound_dev_if && dev_match) 248 + if (sk->sk_bound_dev_if) 249 249 score += 4; 250 250 } 251 251 if (sk->sk_incoming_cpu == raw_smp_processor_id())
+2 -2
net/ipv6/inet6_hashtables.c
··· 113 113 bool dev_match = (sk->sk_bound_dev_if == dif || 114 114 sk->sk_bound_dev_if == sdif); 115 115 116 - if (exact_dif && !dev_match) 116 + if (!dev_match) 117 117 return -1; 118 - if (sk->sk_bound_dev_if && dev_match) 118 + if (sk->sk_bound_dev_if) 119 119 score++; 120 120 } 121 121 if (sk->sk_incoming_cpu == raw_smp_processor_id())