Skip to contentSkip to conversation

Netfilter fixes for net

PATCH In review Pablo Neira Ayuso 2 participants 11 messages Mar 21, 2019

Subsystems (5)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter fixes for net

Hi David,

The following patchset contains Netfilter fixes for your net tree:

1) Remove a direct dependency with IPv6 introduced by the sip_external_media feature, from Alin Nastac.

2) Fix bogus ENOENT when removing interval elements from set.

3) Set transport_header from br_netfilter to mimic the stack behaviour, this partially fixes a checksum validation bug from the SCTP connection tracking, from Xin Long.

4) Fix undefined reference to symbol in xt_TEE, due to missing Kconfig dependencies, from Arnd Bergmann.

5) Check for NULL in skb_header_pointer() calls in ip6t_shr, from Kangjie Lu.

6) Fix bogus EBUSY when removing an existing conntrack helper from a transaction.

7) Fix module autoload of the redirect extension.

8) Remove duplicated transition in flowtable diagram in the existing documentation.

9) Missing .release_ops call from error path in newrule() which results module refcount leak, from Taehee Yoo.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Thanks!

----------------------------------------------------------------

The following changes since commit 4ec850e5dfec092b26cf3b7d5a6c9e444ea4babd:

net: dwmac-sun8i: fix a missing check of of_get_phy_mode (2019-03-12 14:52:00 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD

for you to fetch changes up to b25a31bf0ca091aa8bdb9ab329b0226257568bbe:

netfilter: nf_tables: add missing ->release_ops() in error path of newrule() (2019-03-20 08:32:58 +0100)

----------------------------------------------------------------
Alin Nastac (1):
netfilter: nf_conntrack_sip: remove direct dependency on IPv6

Arnd Bergmann (1):
netfilter: fix NETFILTER_XT_TARGET_TEE dependencies

Kangjie Lu (1):
netfilter: ip6t_srh: fix NULL pointer dereferences

Pablo Neira Ayuso (4):
netfilter: nft_set_rbtree: check for inactive element after flag mismatch
netfilter: nf_tables: bogus EBUSY in helper removal from transaction
netfilter: nft_redir: fix module autoload with ip4
netfilter: nf_flowtable: remove duplicated transition in diagram

Taehee Yoo (1):

      netfilter: nf_tables: add missing ->release_ops() in error path of newrule()

Xin Long (1):
netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING

 Documentation/networking/nf_flowtable.txt |  8 +++----
 net/bridge/br_netfilter_hooks.c           |  1 +
 net/bridge/br_netfilter_ipv6.c            |  2 ++
 net/ipv6/netfilter/ip6t_srh.c             |  6 +++++
 net/netfilter/Kconfig                     |  1 +
 net/netfilter/nf_conntrack_sip.c          | 37 +++++++++++++------------------
 net/netfilter/nf_tables_api.c             |  5 ++++-
 net/netfilter/nft_objref.c                | 19 +++++++++++++---
 net/netfilter/nft_redir.c                 |  2 +-
 net/netfilter/nft_set_rbtree.c            |  7 +++---
 10 files changed, 54 insertions(+), 34 deletions(-)
author maintainer
#1 lore raw

PATCH 1/9 netfilter: nf_conntrack_sip: remove direct dependency on IPv6

From: Alin Nastac <[email protected]>

Previous implementation was not usable with CONFIG_IPV6=m.

Fixes a3419ce3356c ("netfilter: nf_conntrack_sip: add sip_external_media logic")
---
 net/netfilter/nf_conntrack_sip.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)
net/netfilter/nf_conntrack_sip.c +16 -21
index f067c6b50857..39fcc1ed18f3 100644
@@ -20,9 +20,9 @@
 #include <linux/udp.h>
 #include <linux/tcp.h>
 #include <linux/netfilter.h>
+#include <linux/netfilter_ipv4.h>
+#include <linux/netfilter_ipv6.h>
 
-#include <net/route.h>
-#include <net/ip6_route.h>
 #include <net/netfilter/nf_conntrack.h>
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_expect.h>
@@ -871,38 +871,33 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,
 	} else if (sip_external_media) {
 		struct net_device *dev = skb_dst(skb)->dev;
 		struct net *net = dev_net(dev);
-		struct rtable *rt;
-		struct flowi4 fl4 = {};
-#if IS_ENABLED(CONFIG_IPV6)
-		struct flowi6 fl6 = {};
-#endif
+		struct flowi fl;
 		struct dst_entry *dst = NULL;
 
+		memset(&fl, 0, sizeof(fl));
+
 		switch (nf_ct_l3num(ct)) {
 			case NFPROTO_IPV4:
-				fl4.daddr = daddr->ip;
-				rt = ip_route_output_key(net, &fl4);
-				if (!IS_ERR(rt))
-					dst = &rt->dst;
+				fl.u.ip4.daddr = daddr->ip;
+				nf_ip_route(net, &dst, &fl, false);
 				break;
 
-#if IS_ENABLED(CONFIG_IPV6)
 			case NFPROTO_IPV6:
-				fl6.daddr = daddr->in6;
-				dst = ip6_route_output(net, NULL, &fl6);
-				if (dst->error) {
-					dst_release(dst);
-					dst = NULL;
-				}
+				fl.u.ip6.daddr = daddr->in6;
+				nf_ip6_route(net, &dst, &fl, false);
 				break;
-#endif
 		}
 
 		/* Don't predict any conntracks when media endpoint is reachable
 		 * through the same interface as the signalling peer.
 		 */
-		if (dst && dst->dev == dev)
-			return NF_ACCEPT;
+		if (dst) {
+			bool external_media = (dst->dev == dev);
+
+			dst_release(dst);
+			if (external_media)
+				return NF_ACCEPT;
+		}
 	}
 
 	/* We need to check whether the registration exists before attempting
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/9 netfilter: nft_set_rbtree: check for inactive element after flag mismatch

In reply to Pablo Neira Ayuso

Otherwise, we hit bogus ENOENT when removing elements.

Fixes e701001e7cbe ("netfilter: nft_rbtree: allow adjacent intervals with dynamic updates")
---
 net/netfilter/nft_set_rbtree.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/netfilter/nft_set_rbtree.c +3 -4
index fa61208371f8..321a0036fdf5 100644
@@ -308,10 +308,6 @@ static void *nft_rbtree_deactivate(const struct net *net,
 		else if (d > 0)
 			parent = parent->rb_right;
 		else {
-			if (!nft_set_elem_active(&rbe->ext, genmask)) {
-				parent = parent->rb_left;
-				continue;
-			}
 			if (nft_rbtree_interval_end(rbe) &&
 			    !nft_rbtree_interval_end(this)) {
 				parent = parent->rb_left;
@@ -320,6 +316,9 @@ static void *nft_rbtree_deactivate(const struct net *net,
 				   nft_rbtree_interval_end(this)) {
 				parent = parent->rb_right;
 				continue;
+			} else if (!nft_set_elem_active(&rbe->ext, genmask)) {
+				parent = parent->rb_left;
+				continue;
 			}
 			nft_rbtree_flush(net, set, rbe);
 			return rbe;
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/9 netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING

In reply to Pablo Neira Ayuso

From: Xin Long <[email protected]>

Since Commit 21d1196a35f5 ("ipv4: set transport header earlier"), skb->transport_header has been always set before entering INET netfilter. This patch is to set skb->transport_header for bridge before entering INET netfilter by bridge-nf-call-iptables.

It also fixes an issue that sctp_error() couldn't compute a right csum due to unset skb->transport_header.

Fixes e6d8b64b34aa ("net: sctp: fix and consolidate SCTP checksumming code")
---
 net/bridge/br_netfilter_hooks.c | 1 +
 net/bridge/br_netfilter_ipv6.c  | 2 ++
 2 files changed, 3 insertions(+)
net/bridge/br_netfilter_hooks.c +1 -0
index 9d34de68571b..22afa566cbce 100644
@@ -502,6 +502,7 @@ static unsigned int br_nf_pre_routing(void *priv,
 	nf_bridge->ipv4_daddr = ip_hdr(skb)->daddr;
 
 	skb->protocol = htons(ETH_P_IP);
+	skb->transport_header = skb->network_header + ip_hdr(skb)->ihl * 4;
 
 	NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->net, state->sk, skb,
 		skb->dev, NULL,
net/bridge/br_netfilter_ipv6.c +2 -0
index 564710f88f93..e88d6641647b 100644
@@ -235,6 +235,8 @@ unsigned int br_nf_pre_routing_ipv6(void *priv,
 	nf_bridge->ipv6_daddr = ipv6_hdr(skb)->daddr;
 
 	skb->protocol = htons(ETH_P_IPV6);
+	skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
+
 	NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, state->net, state->sk, skb,
 		skb->dev, NULL,
 		br_nf_pre_routing_finish_ipv6);
Signature · 1 line
2.11.0
author maintainer
#4 lore raw

PATCH 4/9 netfilter: fix NETFILTER_XT_TARGET_TEE dependencies

In reply to Pablo Neira Ayuso

From: Arnd Bergmann <[email protected]>

With NETFILTER_XT_TARGET_TEE=y and IP6_NF_IPTABLES=m, we get a link error when referencing the NF_DUP_IPV6 module:

net/netfilter/xt_TEE.o: In function `tee_tg6':
xt_TEE.c:(.text+0x14): undefined reference to `nf_dup_ipv6'

The problem here is the 'select NF_DUP_IPV6 if IP6_NF_IPTABLES' that forces NF_DUP_IPV6 to be =m as well rather than setting it to =y as was intended here. Adding a soft dependency on IP6_NF_IPTABLES avoids that broken configuration.

---
 net/netfilter/Kconfig | 1 +
 1 file changed, 1 insertion(+)
net/netfilter/Kconfig +1 -0
index d43ffb09939b..6548271209a0 100644
@@ -1007,6 +1007,7 @@ config NETFILTER_XT_TARGET_TEE
 	depends on NETFILTER_ADVANCED
 	depends on IPV6 || IPV6=n
 	depends on !NF_CONNTRACK || NF_CONNTRACK
+	depends on IP6_NF_IPTABLES || !IP6_NF_IPTABLES
 	select NF_DUP_IPV4
 	select NF_DUP_IPV6 if IP6_NF_IPTABLES
 	---help---
Signature · 1 line
2.11.0
author maintainer
#5 lore raw

PATCH 5/9 netfilter: ip6t_srh: fix NULL pointer dereferences

In reply to Pablo Neira Ayuso

From: Kangjie Lu <[email protected]>

skb_header_pointer may return NULL. The current code dereference its return values without a NULL check.

The fix inserts the checks to avoid NULL pointer dereferences.

Fixes 202a8ff545cc ("netfilter: add IPv6 segment routing header 'srh' match")
---
 net/ipv6/netfilter/ip6t_srh.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/ipv6/netfilter/ip6t_srh.c +6 -0
index 1059894a6f4c..4cb83fb69844 100644
@@ -210,6 +210,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 		psidoff = srhoff + sizeof(struct ipv6_sr_hdr) +
 			  ((srh->segments_left + 1) * sizeof(struct in6_addr));
 		psid = skb_header_pointer(skb, psidoff, sizeof(_psid), &_psid);
+		if (!psid)
+			return false;
 		if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_PSID,
 				ipv6_masked_addr_cmp(psid, &srhinfo->psid_msk,
 						     &srhinfo->psid_addr)))
@@ -223,6 +225,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 		nsidoff = srhoff + sizeof(struct ipv6_sr_hdr) +
 			  ((srh->segments_left - 1) * sizeof(struct in6_addr));
 		nsid = skb_header_pointer(skb, nsidoff, sizeof(_nsid), &_nsid);
+		if (!nsid)
+			return false;
 		if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_NSID,
 				ipv6_masked_addr_cmp(nsid, &srhinfo->nsid_msk,
 						     &srhinfo->nsid_addr)))
@@ -233,6 +237,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	if (srhinfo->mt_flags & IP6T_SRH_LSID) {
 		lsidoff = srhoff + sizeof(struct ipv6_sr_hdr);
 		lsid = skb_header_pointer(skb, lsidoff, sizeof(_lsid), &_lsid);
+		if (!lsid)
+			return false;
 		if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_LSID,
 				ipv6_masked_addr_cmp(lsid, &srhinfo->lsid_msk,
 						     &srhinfo->lsid_addr)))
Signature · 1 line
2.11.0
author maintainer
#6 lore raw

PATCH 6/9 netfilter: nf_tables: bogus EBUSY in helper removal from transaction

In reply to Pablo Neira Ayuso

Proper use counter updates when activating and deactivating the object, otherwise, this hits bogus EBUSY error.

Fixes cd5125d8f518 ("netfilter: nf_tables: split set destruction in deactivate and destroy phase")
---
 net/netfilter/nft_objref.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
net/netfilter/nft_objref.c +16 -3
index 457a9ceb46af..8dfa798ea683 100644
@@ -65,21 +65,34 @@ static int nft_objref_dump(struct sk_buff *skb, const struct nft_expr *expr)
 	return -1;
 }
 
-static void nft_objref_destroy(const struct nft_ctx *ctx,
-			       const struct nft_expr *expr)
+static void nft_objref_deactivate(const struct nft_ctx *ctx,
+				  const struct nft_expr *expr,
+				  enum nft_trans_phase phase)
 {
 	struct nft_object *obj = nft_objref_priv(expr);
 
+	if (phase == NFT_TRANS_COMMIT)
+		return;
+
 	obj->use--;
 }
 
+static void nft_objref_activate(const struct nft_ctx *ctx,
+				const struct nft_expr *expr)
+{
+	struct nft_object *obj = nft_objref_priv(expr);
+
+	obj->use++;
+}
+
 static struct nft_expr_type nft_objref_type;
 static const struct nft_expr_ops nft_objref_ops = {
 	.type		= &nft_objref_type,
 	.size		= NFT_EXPR_SIZE(sizeof(struct nft_object *)),
 	.eval		= nft_objref_eval,
 	.init		= nft_objref_init,
-	.destroy	= nft_objref_destroy,
+	.activate	= nft_objref_activate,
+	.deactivate	= nft_objref_deactivate,
 	.dump		= nft_objref_dump,
 };
 
Signature · 1 line
2.11.0
author maintainer
#7 lore raw

PATCH 7/9 netfilter: nft_redir: fix module autoload with ip4

In reply to Pablo Neira Ayuso

AF_INET4 does not exist.

Fixes c78efc99c750 ("netfilter: nf_tables: nat: merge nft_redir protocol specific modules)"
---
 net/netfilter/nft_redir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_redir.c +1 -1
index f8092926f704..a340cd8a751b 100644
@@ -233,5 +233,5 @@ module_exit(nft_redir_module_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Arturo Borrero Gonzalez <[email protected]>");
-MODULE_ALIAS_NFT_AF_EXPR(AF_INET4, "redir");
+MODULE_ALIAS_NFT_AF_EXPR(AF_INET, "redir");
 MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "redir");
Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH 8/9 netfilter: nf_flowtable: remove duplicated transition in diagram

In reply to Pablo Neira Ayuso

No direct transition from prerouting to forward hook, routing lookup needs to happen first.

Fixes 19b351f16fd9 ("netfilter: add flowtable documentation")
---
 Documentation/networking/nf_flowtable.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/networking/nf_flowtable.txt +4 -4
index 54128c50d508..ca2136c76042 100644
@@ -44,10 +44,10 @@ including the Netfilter hooks and the flowtable fastpath bypass.
      /         \    /          \     |Routing |   /            \
   -->  ingress  ---> prerouting ---> |decision|   | postrouting |--> neigh_xmit
      \_________/    \__________/     ----------   \____________/          ^
-       |      ^          |               |               ^                |
-   flowtable  |          |          ____\/___            |                |
-       |      |          |         /         \           |                |
-    __\/___   |          --------->| forward |------------                |
+       |      ^                          |               ^                |
+   flowtable  |                     ____\/___            |                |
+       |      |                    /         \           |                |
+    __\/___   |                    | forward |------------                |
     |-----|   |                    \_________/                            |
     |-----|   |                 'flow offload' rule                       |
     |-----|   |                   adds entry to                           |
Signature · 1 line
2.11.0
author maintainer
#9 lore raw

PATCH 9/9 netfilter: nf_tables: add missing ->release_ops() in error path of newrule()

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

->release_ops() callback releases resources and this is used in error path. If nf_tables_newrule() fails after ->select_ops(), it should release resources. but it can not call ->destroy() because that should be called after ->init().
At this point, ->release_ops() should be used for releasing resources.

Test commands:
modprobe -rv xt_tcpudp
iptables-nft -I INPUT -m tcp <-- error command
lsmod

Result:
Module Size Used by
xt_tcpudp 20480 2 <-- it should be 0

Fixes b8e204006340 ("netfilter: nft_compat: use .release_ops and remove list of extension")
---
 net/netfilter/nf_tables_api.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +4 -1
index 513f93118604..ef7772e976cc 100644
@@ -2806,8 +2806,11 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
 	nf_tables_rule_release(&ctx, rule);
 err1:
 	for (i = 0; i < n; i++) {
-		if (info[i].ops != NULL)
+		if (info[i].ops) {
 			module_put(info[i].ops->type->owner);
+			if (info[i].ops->type->release_ops)
+				info[i].ops->type->release_ops(info[i].ops);
+		}
 	}
 	kvfree(info);
 	return err;
Signature · 1 line
2.11.0
maintainer
#10 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 21 Mar 2019 12:28:36 +0100

Quoted 25 lines

The following patchset contains Netfilter fixes for your net tree:

1) Remove a direct dependency with IPv6 introduced by the sip_external_media feature, from Alin Nastac.

2) Fix bogus ENOENT when removing interval elements from set.

3) Set transport_header from br_netfilter to mimic the stack behaviour, this partially fixes a checksum validation bug from the SCTP connection tracking, from Xin Long.

4) Fix undefined reference to symbol in xt_TEE, due to missing Kconfig dependencies, from Arnd Bergmann.

5) Check for NULL in skb_header_pointer() calls in ip6t_shr, from Kangjie Lu.

6) Fix bogus EBUSY when removing an existing conntrack helper from a transaction.

7) Fix module autoload of the redirect extension.

8) Remove duplicated transition in flowtable diagram in the existing documentation.

Quoted 6 lines

9) Missing .release_ops call from error path in newrule() which results module refcount leak, from Taehee Yoo.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Pulled, thanks.