aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan Eastoe <deastoe@vyatta.att-mail.com>2018-11-07 10:36:06 -0500
committerDavid S. Miller <davem@davemloft.net>2018-11-07 19:12:39 -0500
commit7055420fb6a1cb754a64be99ddcabd45bd902d99 (patch)
tree469b838c4b00ccfc04f3583805eb5ebbf52ab14f
parent6897445fb194c8ad046df4a13e1ee9f080a5a21e (diff)
net: fix raw socket lookup device bind matching with VRFs
When there exist a pair of raw sockets one unbound and one bound to a VRF but equal in all other respects, when a packet is received in the VRF context, __raw_v4_lookup() matches on both sockets. This results in the packet being delivered over both sockets, instead of only the raw socket bound to the VRF. The bound device checks in __raw_v4_lookup() are replaced with a call to raw_sk_bound_dev_eq() which correctly handles whether the packet should be delivered over the unbound socket in such cases. In __raw_v6_lookup() the match on the device binding of the socket is similarly updated to use raw_sk_bound_dev_eq() which matches the handling in __raw_v4_lookup(). Importantly raw_sk_bound_dev_eq() takes the raw_l3mdev_accept sysctl into account. Signed-off-by: Duncan Eastoe <deastoe@vyatta.att-mail.com> Signed-off-by: Mike Manning <mmanning@vyatta.att-mail.com> Reviewed-by: David Ahern <dsahern@gmail.com> Tested-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/raw.h13
-rw-r--r--net/ipv4/raw.c3
-rw-r--r--net/ipv6/raw.c5
3 files changed, 15 insertions, 6 deletions
diff --git a/include/net/raw.h b/include/net/raw.h
index 20ebf0b3dfa8..821ff4887f77 100644
--- a/include/net/raw.h
+++ b/include/net/raw.h
@@ -17,7 +17,7 @@
17#ifndef _RAW_H 17#ifndef _RAW_H
18#define _RAW_H 18#define _RAW_H
19 19
20 20#include <net/inet_sock.h>
21#include <net/protocol.h> 21#include <net/protocol.h>
22#include <linux/icmp.h> 22#include <linux/icmp.h>
23 23
@@ -75,4 +75,15 @@ static inline struct raw_sock *raw_sk(const struct sock *sk)
75 return (struct raw_sock *)sk; 75 return (struct raw_sock *)sk;
76} 76}
77 77
78static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
79 int dif, int sdif)
80{
81#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
82 return inet_bound_dev_eq(!!net->ipv4.sysctl_raw_l3mdev_accept,
83 bound_dev_if, dif, sdif);
84#else
85 return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
86#endif
87}
88
78#endif /* _RAW_H */ 89#endif /* _RAW_H */
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 1ebd29abe79c..fb1f02015a15 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -131,8 +131,7 @@ struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
131 if (net_eq(sock_net(sk), net) && inet->inet_num == num && 131 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
132 !(inet->inet_daddr && inet->inet_daddr != raddr) && 132 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
133 !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) && 133 !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
134 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif && 134 raw_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif))
135 sk->sk_bound_dev_if != sdif))
136 goto found; /* gotcha */ 135 goto found; /* gotcha */
137 } 136 }
138 sk = NULL; 137 sk = NULL;
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 5e0efd3954e9..aed7eb5c2123 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -86,9 +86,8 @@ struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
86 !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr)) 86 !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr))
87 continue; 87 continue;
88 88
89 if (sk->sk_bound_dev_if && 89 if (!raw_sk_bound_dev_eq(net, sk->sk_bound_dev_if,
90 sk->sk_bound_dev_if != dif && 90 dif, sdif))
91 sk->sk_bound_dev_if != sdif)
92 continue; 91 continue;
93 92
94 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) { 93 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {