]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: fix raw socket lookup device bind matching with VRFs
authorDuncan Eastoe <deastoe@vyatta.att-mail.com>
Wed, 7 Nov 2018 15:36:06 +0000 (15:36 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 8 Nov 2018 00:12:39 +0000 (16:12 -0800)
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>
include/net/raw.h
net/ipv4/raw.c
net/ipv6/raw.c

index 20ebf0b3dfa8ac6235201399cd3d57866aa4d547..821ff4887f775d8c72dc85251245767a15f3ce42 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _RAW_H
 #define _RAW_H
 
-
+#include <net/inet_sock.h>
 #include <net/protocol.h>
 #include <linux/icmp.h>
 
@@ -75,4 +75,15 @@ static inline struct raw_sock *raw_sk(const struct sock *sk)
        return (struct raw_sock *)sk;
 }
 
+static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
+                                      int dif, int sdif)
+{
+#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
+       return inet_bound_dev_eq(!!net->ipv4.sysctl_raw_l3mdev_accept,
+                                bound_dev_if, dif, sdif);
+#else
+       return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
+#endif
+}
+
 #endif /* _RAW_H */
index 1ebd29abe79cf083946e18610838e2197dc5c44e..fb1f02015a15d2fb26d7b31047a94f6503805f6a 100644 (file)
@@ -131,8 +131,7 @@ struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
                if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
                    !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
                    !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
-                   !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif &&
-                     sk->sk_bound_dev_if != sdif))
+                   raw_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif))
                        goto found; /* gotcha */
        }
        sk = NULL;
index 5e0efd3954e90ade89eb4da17cd5ecef1894a1a3..aed7eb5c212311d0b47946b4e0ea596123958531 100644 (file)
@@ -86,9 +86,8 @@ struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
                            !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr))
                                continue;
 
-                       if (sk->sk_bound_dev_if &&
-                           sk->sk_bound_dev_if != dif &&
-                           sk->sk_bound_dev_if != sdif)
+                       if (!raw_sk_bound_dev_eq(net, sk->sk_bound_dev_if,
+                                                dif, sdif))
                                continue;
 
                        if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {