lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 27 Dec 2018 15:38:07 +0800
From:   wenxu@...oud.cn
To:     netdev@...r.kernel.org
Subject: [PATCH net-next] vrf: Add VRF_F_BYPASS_RCV_NF flag to vrf device

From: wenxu <wenxu@...oud.cn>

In the ip_rcv the skb go through the PREROUTING hook first,
Then jump in vrf device go through the same hook again.
When conntrack work with vrf, there will be some conflict for rules.
Because the package go through the hook twice with different nf status

ip link add user1 type vrf table 1
ip link add user2 type vrf table 2
ip l set dev tun1 master user1
ip l set dev tun2 master user2

nft add table firewall
nft add chain firewall zones { type filter hook prerouting  priority - 300 \; }
nft add rule firewall zones counter ct zone set iif map { "tun1" : 1, "tun2" : 2 }
nft add chain firewall rule-1000-ingress
nft add rule firewall rule-1000-ingress ct zone 1 tcp dport 22 ct state new counter accept
nft add rule firewall rule-1000-ingress counter drop
nft add chain firewall rule-1000-egress
nft add rule firewall rule-1000-egress tcp dport 22 ct state new counter drop
nft add rule firewall rule-1000-egress counter accept

nft add chain firewall rules-all { type filter hook prerouting priority - 150 \; }
nft add rule firewall rules-all ip daddr vmap { "2.2.2.11" : jump rule-1000-ingress }
nft add rule firewall rules-all ct zone vmap { 1 : jump rule-1000-egress }

nft add rule firewall dnat-all ct zone vmap { 1 : jump dnat-1000 }
nft add rule firewall dnat-1000 ip daddr 2.2.2.11 counter dnat to 10.0.0.7

For a package with ip daddr 2.2.2.11 and tcp dport 22, first time accept in the 
rule-1000-ingress and dnat to 10.0.0.7. Then second time the packet goto the wrong 
chain rule-1000-egress which leads the packet drop

So it proived a flag to control the vrf-device bypass go through hook for 
the second time.

Signed-off-by: wenxu <wenxu@...oud.cn>
---
 drivers/net/vrf.c            | 20 ++++++++++++++++++--
 include/uapi/linux/if_link.h |  3 +++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 95909e2..f378fa19 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -52,6 +52,7 @@ struct net_vrf {
 	struct fib6_table	*fib6_table;
 #endif
 	u32                     tb_id;
+	u8                      flags;
 };
 
 struct pcpu_dstats {
@@ -898,6 +899,10 @@ static struct sk_buff *vrf_rcv_nfhook(u8 pf, unsigned int hook,
 				      struct net_device *dev)
 {
 	struct net *net = dev_net(dev);
+	struct net_vrf *vrf = netdev_priv(dev);
+
+	if (vrf->flags & VRF_F_BYPASS_RCV_NF)
+		return skb;
 
 	if (nf_hook(pf, hook, net, NULL, skb, dev, NULL, vrf_rcv_finish) != 1)
 		skb = NULL;    /* kfree_skb(skb) handled by nf code */
@@ -1323,6 +1328,9 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev,
 		return -EINVAL;
 	}
 
+	if (data[IFLA_VRF_FLAGS])
+		vrf->flags = nla_get_u8(data[IFLA_VRF_FLAGS]);
+
 	dev->priv_flags |= IFF_L3MDEV_MASTER;
 
 	err = register_netdevice(dev);
@@ -1346,7 +1354,8 @@ static int vrf_newlink(struct net *src_net, struct net_device *dev,
 
 static size_t vrf_nl_getsize(const struct net_device *dev)
 {
-	return nla_total_size(sizeof(u32));  /* IFLA_VRF_TABLE */
+	return nla_total_size(sizeof(u32)) +  /* IFLA_VRF_TABLE */
+		nla_total_size(sizeof(u8));   /* IFLA_VRF_FLAGS */
 }
 
 static int vrf_fillinfo(struct sk_buff *skb,
@@ -1354,7 +1363,13 @@ static int vrf_fillinfo(struct sk_buff *skb,
 {
 	struct net_vrf *vrf = netdev_priv(dev);
 
-	return nla_put_u32(skb, IFLA_VRF_TABLE, vrf->tb_id);
+	if (nla_put_u32(skb, IFLA_VRF_TABLE, vrf->tb_id))
+		return -EMSGSIZE;
+
+	if (nla_put_u8(skb, IFLA_VRF_FLAGS, vrf->flags))
+		return -EMSGSIZE;
+
+	return 0;
 }
 
 static size_t vrf_get_slave_size(const struct net_device *bond_dev,
@@ -1377,6 +1392,7 @@ static int vrf_fill_slave_info(struct sk_buff *skb,
 
 static const struct nla_policy vrf_nl_policy[IFLA_VRF_MAX + 1] = {
 	[IFLA_VRF_TABLE] = { .type = NLA_U32 },
+	[IFLA_VRF_FLAGS] = { .type = NLA_U8 },
 };
 
 static struct rtnl_link_ops vrf_link_ops __read_mostly = {
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index d653382..23c489d 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -430,11 +430,14 @@ enum macvlan_macaddr_mode {
 enum {
 	IFLA_VRF_UNSPEC,
 	IFLA_VRF_TABLE,
+	IFLA_VRF_FLAGS,
 	__IFLA_VRF_MAX
 };
 
 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
 
+#define VRF_F_BYPASS_RCV_NF     0x01
+
 enum {
 	IFLA_VRF_PORT_UNSPEC,
 	IFLA_VRF_PORT_TABLE,
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ