Skip to contentSkip to conversation

Netfilter/IPVS updates for net-next

PATCH In review Pablo Neira Ayuso 3 participants 13 messages Mar 30, 2018 – Apr 3, 2018

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter/IPVS updates for net-next

Hi David,

The following patchset contains Netfilter/IPVS updates for your net-next tree. This batch comes with more input sanitization for xtables to address bug reports from fuzzers, preparation works to the flowtable infrastructure and assorted updates. In no particular order, they are:

1) Make sure userspace provides a valid standard target verdict, from Florian Westphal.

2) Sanitize error target size, also from Florian.

3) Validate that last rule in basechain matches underflow/policy since userspace assumes this when decoding the ruleset blob that comes from the kernel, from Florian.

4) Consolidate hook entry checks through xt_check_table_hooks(), patch from Florian.

5) Cap ruleset allocations at 512 mbytes, 134217728 rules and reject very large compat offset arrays, so we have a reasonable upper limit and fuzzers don't exercise the oom-killer. Patches from Florian.

6) Several WARN_ON checks on xtables mutex helper, from Florian.

7) xt_rateest now has a hashtable per net, from Cong Wang.

8) Consolidate counter allocation in xt_counters_alloc(), from Florian.

9) Earlier xt_table_unlock() call in {ip,ip6,arp,eb}tables, patch from Xin Long.

10) Set FLOW_OFFLOAD_DIR_* to IP_CT_DIR_* definitions, patch from Felix Fietkau.

11) Consolidate code through flow_offload_fill_dir(), also from Felix.

12) Inline ip6_dst_mtu_forward() just like ip_dst_mtu_maybe_forward() to remove a dependency with flowtable and ipv6.ko, from Felix.

13) Cache mtu size in flow_offload_tuple object, this is safe for forwarding as f87c10a8aa1e describes, from Felix.

14) Rename nf_flow_table.c to nf_flow_table_core.o, to simplify too modular infrastructure, from Felix.

15) Add rt0, rt2 and rt4 IPv6 routing extension support, patch from Ahmed Abdelsalam.

16) Remove unused parameter in nf_conncount_count(), from Yi-Hung Wei.

17) Support for counting only to nf_conncount infrastructure, patch from Yi-Hung Wei.

18) Add strict NFT_CT_{SRC_IP,DST_IP,SRC_IP6,DST_IP6} key datatypes to nft_ct.

19) Use boolean as return value from ipt_ah and from IPVS too, patch from Gustavo A. R. Silva.

20) Remove useless parameters in nfnl_acct_overquota() and nf_conntrack_broadcast_help(), from Taehee Yoo.

21) Use ipv6_addr_is_multicast() from xt_cluster, also from Taehee Yoo.

22) Statify nf_tables_obj_lookup_byhandle, patch from Fengguang Wu.

23) Fix typo in xt_limit, from Geert Uytterhoeven.

24) Do no use VLAs in Netfilter code, again from Gustavo.

25) Use ADD_COUNTER from ebtables, from Taehee Yoo.

26) Bitshift support for CONNMARK and MARK targets, from Jack Ma.

27) Use pr_*() and add pr_fmt(), from Arushi Singhal.

28) Add synproxy support to ctnetlink.

29) ICMP type and IGMP matching support for ebtables, patches from Matthias Schiffer.

30) Support for the revision infrastructure to ebtables, from Bernie Harris.

31) String match support for ebtables, also from Bernie.

32) Documentation for the new flowtable infrastructure.

33) Use generic comparison functions in ebt_stp, from Joe Perches.

34) Demodularize filter chains in nftables.

35) Register conntrack hooks in case nftables NAT chain is added.

36) Merge assignments with return in a couple of spots in the Netfilter codebase, also from Arushi.

37) Document that xtables percpu counters are stored in the same memory area, from Ben Hutchings.

38) Revert mark_source_chains() sanity checks that break existing rulesets, from Florian Westphal.

39) Use is_zero_ether_addr() in the ipset codebase, from Joe Perches.

You can pull these changes from:

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

Thanks!

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

The following changes since commit ef3f6c256f0b4711a3ef1489797b95820be5ab01:

Merge branch 'mvpp2-jumbo-frames-support' (2018-03-05 12:55:55 -0500)

are available in the git repository at:

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

for you to fetch changes up to 26c97c5d8dac6bc56d4360561a286f52543ac07e:

netfilter: ipset: Use is_zero_ether_addr instead of static and memcmp (2018-03-30 12:20:44 +0200)

----------------------------------------------------------------
Arushi Singhal (2):
netfilter: Replace printk() with pr_*() and define pr_fmt()
netfilter: Merge assignment with return

Ben Hutchings (1):
netfilter: x_tables: Add note about how to free percpu counters

Bernie Harris (2):
netfilter: ebtables: Add support for specifying match revision
netfilter: ebtables: Add string filter

Cong Wang (1):
netfilter: make xt_rateest hash table per net

Florian Westphal (13):
netfilter: x_tables: check standard verdicts in core
netfilter: x_tables: check error target size too
netfilter: x_tables: move hook entry checks into core
netfilter: x_tables: enforce unique and ascending entry points
netfilter: x_tables: cap allocations at 512 mbyte
netfilter: x_tables: limit allocation requests for blob rule heads
netfilter: x_tables: add counters allocation wrapper
netfilter: compat: prepare xt_compat_init_offsets to return errors
netfilter: compat: reject huge allocation requests
netfilter: x_tables: make sure compat af mutex is held
netfilter: x_tables: ensure last rule in base chain matches underflow/policy
netfilter: x_tables: fix build with CONFIG_COMPAT=n
Revert "netfilter: x_tables: ensure last rule in base chain matches underflow/policy"

Geert Uytterhoeven (1):
netfilter: xt_limit: Spelling s/maxmum/maximum/

Gustavo A. R. Silva (5):
netfilter: ipt_ah: return boolean instead of integer
ipvs: use true and false for boolean values
netfilter: cttimeout: remove VLA usage
netfilter: nfnetlink_cthelper: Remove VLA usage
netfilter: nf_tables: remove VLA usage

Jack Ma (1):
netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK targets.

Joe Perches (2):
netfilter: ebt_stp: Use generic functions for comparisons
netfilter: ipset: Use is_zero_ether_addr instead of static and memcmp

Matthias Schiffer (2):
netfilter: ebtables: add support for matching ICMP type and code
netfilter: ebtables: add support for matching IGMP type

Pablo Neira Ayuso (9):
netfilter: nft_ct: add NFT_CT_{SRC,DST}_{IP,IP6}
netfilter: ctnetlink: synproxy support
netfilter: add flowtable documentation
netfilter: nf_tables: rename struct nf_chain_type
netfilter: nf_tables: nft_register_chain_type() returns void
netfilter: nf_tables: build-in filter chain type
netfilter: nf_tables: enable conntrack if NAT chain is registered
netfilter: nf_tables: rename to nft_set_lookup_global()
netfilter: nf_tables: use nft_set_lookup_global from nf_tables_newsetelem()

Taehee Yoo (4):
netfilter: nfnetlink_acct: remove useless parameter
netfilter: xt_cluster: get rid of xt_cluster_ipv6_is_multicast
netfilter: nf_conntrack_broadcast: remove useless parameter
netfilter: ebtables: use ADD_COUNTER macro

Xin Long (1):
netfilter: unlock xt_table earlier in __do_replace

Yi-Hung Wei (2):
netfilter: Refactor nf_conncount
netfilter: conncount: Support count only use case

kbuild test robot (1):
netfilter: nf_tables: nf_tables_obj_lookup_byhandle() can be static

 Documentation/networking/nf_flowtable.txt          | 112 ++++++
 include/linux/netfilter/nfnetlink_acct.h           |   3 +-
 include/linux/netfilter/x_tables.h                 |   5 +-
 include/net/netfilter/nf_conntrack_count.h         |   1 -
 include/net/netfilter/nf_conntrack_helper.h        |   3 +-
 include/net/netfilter/nf_tables.h                  |  33 +-
 include/net/netfilter/xt_rateest.h                 |   4 +-
 include/uapi/linux/netfilter/nf_conntrack_common.h |   1 +
 include/uapi/linux/netfilter/nf_tables.h           |  12 +-
 include/uapi/linux/netfilter/nfnetlink_conntrack.h |  10 +
 include/uapi/linux/netfilter/xt_connmark.h         |  10 +
 include/uapi/linux/netfilter_bridge/ebt_ip.h       |  15 +-
 include/uapi/linux/netfilter_bridge/ebtables.h     |  16 +-
 net/bridge/netfilter/Kconfig                       |   2 +-
 net/bridge/netfilter/Makefile                      |   1 -
 net/bridge/netfilter/ebt_ip.c                      |  58 ++-
 net/bridge/netfilter/ebt_stp.c                     |   6 +-
 net/bridge/netfilter/ebtables.c                    |  74 ++--
 net/bridge/netfilter/nf_tables_bridge.c            |  79 ----
 net/ipv4/netfilter/Kconfig                         |   4 +-
 net/ipv4/netfilter/Makefile                        |   2 -
 net/ipv4/netfilter/arp_tables.c                    |  33 +-
 net/ipv4/netfilter/ip_tables.c                     |  31 +-
 net/ipv4/netfilter/ipt_SYNPROXY.c                  |   8 +-
 net/ipv4/netfilter/ipt_ah.c                        |   2 +-
 net/ipv4/netfilter/nf_tables_arp.c                 |  58 ---
 net/ipv4/netfilter/nf_tables_ipv4.c                |  67 ----
 net/ipv4/netfilter/nft_chain_nat_ipv4.c            |  20 +-
 net/ipv4/netfilter/nft_chain_route_ipv4.c          |   6 +-
 net/ipv6/netfilter/Kconfig                         |   2 +-
 net/ipv6/netfilter/Makefile                        |   1 -
 net/ipv6/netfilter/ip6_tables.c                    |  33 +-
 net/ipv6/netfilter/ip6t_SYNPROXY.c                 |   8 +-
 net/ipv6/netfilter/nf_tables_ipv6.c                |  65 ----
 net/ipv6/netfilter/nft_chain_nat_ipv6.c            |  20 +-
 net/ipv6/netfilter/nft_chain_route_ipv6.c          |   6 +-
 net/netfilter/Kconfig                              |   4 +-
 net/netfilter/Makefile                             |   9 +-
 net/netfilter/ipset/ip_set_hash_mac.c              |   7 +-
 net/netfilter/ipvs/ip_vs_lblc.c                    |   4 +-
 net/netfilter/ipvs/ip_vs_lblcr.c                   |   4 +-
 net/netfilter/nf_conncount.c                       |  14 +-
 net/netfilter/nf_conntrack_acct.c                  |   6 +-
 net/netfilter/nf_conntrack_broadcast.c             |   1 -
 net/netfilter/nf_conntrack_ecache.c                |   6 +-
 net/netfilter/nf_conntrack_netbios_ns.c            |   5 +-
 net/netfilter/nf_conntrack_netlink.c               |  92 ++++-
 net/netfilter/nf_conntrack_snmp.c                  |   5 +-
 net/netfilter/nf_conntrack_timestamp.c             |   6 +-
 net/netfilter/nf_nat_core.c                        |   4 +-
 net/netfilter/nf_nat_ftp.c                         |   7 +-
 net/netfilter/nf_nat_irc.c                         |   7 +-
 net/netfilter/nf_tables_api.c                      | 115 +++---
 net/netfilter/nf_tables_inet.c                     |  75 ----
 net/netfilter/nf_tables_netdev.c                   | 142 --------
 net/netfilter/nfnetlink_acct.c                     |   3 +-
 net/netfilter/nfnetlink_cthelper.c                 |  25 +-
 net/netfilter/nfnetlink_cttimeout.c                |  26 +-
 net/netfilter/nfnetlink_queue.c                    |  14 +-
 net/netfilter/nft_chain_filter.c                   | 398 +++++++++++++++++++++
 net/netfilter/nft_ct.c                             |  38 ++
 net/netfilter/nft_dynset.c                         |   5 +-
 net/netfilter/nft_lookup.c                         |   4 +-
 net/netfilter/nft_objref.c                         |   5 +-
 net/netfilter/x_tables.c                           | 191 +++++++++-
 net/netfilter/xt_RATEEST.c                         |  91 +++--
 net/netfilter/xt_cluster.c                         |  10 +-
 net/netfilter/xt_connlimit.c                       |   4 +-
 net/netfilter/xt_connmark.c                        |  77 +++-
 net/netfilter/xt_hashlimit.c                       |   3 +-
 net/netfilter/xt_limit.c                           |   2 +-
 net/netfilter/xt_nfacct.c                          |   2 +-
 net/netfilter/xt_rateest.c                         |  10 +-
 net/netfilter/xt_string.c                          |   1 +
 net/netfilter/xt_time.c                            |  13 +-
 75 files changed, 1384 insertions(+), 862 deletions(-)
 create mode 100644 Documentation/networking/nf_flowtable.txt
 delete mode 100644 net/bridge/netfilter/nf_tables_bridge.c
 delete mode 100644 net/ipv4/netfilter/nf_tables_arp.c
 delete mode 100644 net/ipv4/netfilter/nf_tables_ipv4.c
 delete mode 100644 net/ipv6/netfilter/nf_tables_ipv6.c
 delete mode 100644 net/netfilter/nf_tables_inet.c
 delete mode 100644 net/netfilter/nf_tables_netdev.c
 create mode 100644 net/netfilter/nft_chain_filter.c
author maintainer
#1 lore raw

PATCH 1/47 netfilter: nf_tables: nf_tables_obj_lookup_byhandle() can be static

From: kbuild test robot <[email protected]>

Fixes 3ecbfd65f50e ("netfilter: nf_tables: allocate handle and delete objects via handle")
---
 net/netfilter/nf_tables_api.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +4 -4
index 8b9fe30de0cd..8cc7fc970f0c 100644
@@ -4328,9 +4328,9 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
 }
 EXPORT_SYMBOL_GPL(nf_tables_obj_lookup);
 
-struct nft_object *nf_tables_obj_lookup_byhandle(const struct nft_table *table,
-						 const struct nlattr *nla,
-						 u32 objtype, u8 genmask)
+static struct nft_object *nf_tables_obj_lookup_byhandle(const struct nft_table *table,
+							const struct nlattr *nla,
+							u32 objtype, u8 genmask)
 {
 	struct nft_object *obj;
 
@@ -4850,7 +4850,7 @@ struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table,
 }
 EXPORT_SYMBOL_GPL(nf_tables_flowtable_lookup);
 
-struct nft_flowtable *
+static struct nft_flowtable *
 nf_tables_flowtable_lookup_byhandle(const struct nft_table *table,
 				    const struct nlattr *nla, u8 genmask)
 {
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/47 netfilter: nfnetlink_acct: remove useless parameter

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

parameter skb in nfnl_acct_overquota is not used anywhere.

---
 include/linux/netfilter/nfnetlink_acct.h | 3 +--
 net/netfilter/nfnetlink_acct.c           | 3 +--
 net/netfilter/xt_nfacct.c                | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)
include/linux/netfilter/nfnetlink_acct.h +1 -2
index b4d741195c28..beee8bffe49e 100644
@@ -16,6 +16,5 @@ struct nf_acct;
 struct nf_acct *nfnl_acct_find_get(struct net *net, const char *filter_name);
 void nfnl_acct_put(struct nf_acct *acct);
 void nfnl_acct_update(const struct sk_buff *skb, struct nf_acct *nfacct);
-int nfnl_acct_overquota(struct net *net, const struct sk_buff *skb,
-			struct nf_acct *nfacct);
+int nfnl_acct_overquota(struct net *net, struct nf_acct *nfacct);
 #endif /* _NFNL_ACCT_H */
net/netfilter/nfnetlink_acct.c +1 -2
index 88d427f9f9e6..b9505bcd3827 100644
@@ -467,8 +467,7 @@ static void nfnl_overquota_report(struct net *net, struct nf_acct *nfacct)
 			  GFP_ATOMIC);
 }
 
-int nfnl_acct_overquota(struct net *net, const struct sk_buff *skb,
-			struct nf_acct *nfacct)
+int nfnl_acct_overquota(struct net *net, struct nf_acct *nfacct)
 {
 	u64 now;
 	u64 *quota;
net/netfilter/xt_nfacct.c +1 -1
index c8674deed4eb..6b56f4170860 100644
@@ -28,7 +28,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
 
 	nfnl_acct_update(skb, info->nfacct);
 
-	overquota = nfnl_acct_overquota(xt_net(par), skb, info->nfacct);
+	overquota = nfnl_acct_overquota(xt_net(par), info->nfacct);
 
 	return overquota == NFACCT_UNDERQUOTA ? false : true;
 }
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/47 netfilter: xt_cluster: get rid of xt_cluster_ipv6_is_multicast

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

If use the ipv6_addr_is_multicast instead of xt_cluster_ipv6_is_multicast, then we can reduce code size.

---
 net/netfilter/xt_cluster.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
net/netfilter/xt_cluster.c +1 -9
index 0068688995c8..dfbdbb2fc0ed 100644
@@ -60,13 +60,6 @@ xt_cluster_hash(const struct nf_conn *ct,
 }
 
 static inline bool
-xt_cluster_ipv6_is_multicast(const struct in6_addr *addr)
-{
-	__be32 st = addr->s6_addr32[0];
-	return ((st & htonl(0xFF000000)) == htonl(0xFF000000));
-}
-
-static inline bool
 xt_cluster_is_multicast_addr(const struct sk_buff *skb, u_int8_t family)
 {
 	bool is_multicast = false;
@@ -76,8 +69,7 @@ xt_cluster_is_multicast_addr(const struct sk_buff *skb, u_int8_t family)
 		is_multicast = ipv4_is_multicast(ip_hdr(skb)->daddr);
 		break;
 	case NFPROTO_IPV6:
-		is_multicast =
-			xt_cluster_ipv6_is_multicast(&ipv6_hdr(skb)->daddr);
+		is_multicast = ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr);
 		break;
 	default:
 		WARN_ON(1);
Signature · 1 line
2.11.0
author maintainer
#4 lore raw

PATCH 4/47 netfilter: nf_conntrack_broadcast: remove useless parameter

In reply to Pablo Neira Ayuso

From: Taehee Yoo <[email protected]>

parameter protoff in nf_conntrack_broadcast_help is not used anywhere.

---
 include/net/netfilter/nf_conntrack_helper.h | 3 +--
 net/netfilter/nf_conntrack_broadcast.c      | 1 -
 net/netfilter/nf_conntrack_netbios_ns.c     | 5 +++--
 net/netfilter/nf_conntrack_snmp.c           | 5 +++--
 4 files changed, 7 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +1 -2
index fc39bbaf107c..32c2a94a219d 100644
@@ -132,8 +132,7 @@ void nf_conntrack_helper_pernet_fini(struct net *net);
 int nf_conntrack_helper_init(void);
 void nf_conntrack_helper_fini(void);
 
-int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff,
-				struct nf_conn *ct,
+int nf_conntrack_broadcast_help(struct sk_buff *skb, struct nf_conn *ct,
 				enum ip_conntrack_info ctinfo,
 				unsigned int timeout);
 
net/netfilter/nf_conntrack_broadcast.c +0 -1
index ecc3ab784633..a1086bdec242 100644
@@ -20,7 +20,6 @@
 #include <net/netfilter/nf_conntrack_expect.h>
 
 int nf_conntrack_broadcast_help(struct sk_buff *skb,
-				unsigned int protoff,
 				struct nf_conn *ct,
 				enum ip_conntrack_info ctinfo,
 				unsigned int timeout)
net/netfilter/nf_conntrack_netbios_ns.c +3 -2
index 496ce173f0c1..a4a59dc7cf17 100644
@@ -41,9 +41,10 @@ static struct nf_conntrack_expect_policy exp_policy = {
 };
 
 static int netbios_ns_help(struct sk_buff *skb, unsigned int protoff,
-		   struct nf_conn *ct, enum ip_conntrack_info ctinfo)
+			   struct nf_conn *ct,
+			   enum ip_conntrack_info ctinfo)
 {
-	return nf_conntrack_broadcast_help(skb, protoff, ct, ctinfo, timeout);
+	return nf_conntrack_broadcast_help(skb, ct, ctinfo, timeout);
 }
 
 static struct nf_conntrack_helper helper __read_mostly = {
net/netfilter/nf_conntrack_snmp.c +3 -2
index 87b95a2c270c..2d0f8e010821 100644
@@ -36,11 +36,12 @@ int (*nf_nat_snmp_hook)(struct sk_buff *skb,
 EXPORT_SYMBOL_GPL(nf_nat_snmp_hook);
 
 static int snmp_conntrack_help(struct sk_buff *skb, unsigned int protoff,
-		struct nf_conn *ct, enum ip_conntrack_info ctinfo)
+			       struct nf_conn *ct,
+			       enum ip_conntrack_info ctinfo)
 {
 	typeof(nf_nat_snmp_hook) nf_nat_snmp;
 
-	nf_conntrack_broadcast_help(skb, protoff, ct, ctinfo, timeout);
+	nf_conntrack_broadcast_help(skb, ct, ctinfo, timeout);
 
 	nf_nat_snmp = rcu_dereference(nf_nat_snmp_hook);
 	if (nf_nat_snmp && ct->status & IPS_NAT_MASK)
Signature · 1 line
2.11.0
author maintainer
#5 lore raw

PATCH 5/47 netfilter: ipt_ah: return boolean instead of integer

In reply to Pablo Neira Ayuso

From: "Gustavo A. R. Silva" <[email protected]>

Return statements in functions returning bool should use true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

---
 net/ipv4/netfilter/ipt_ah.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/ipt_ah.c +1 -1
index a787d07f6cb7..7c6c20eaf4db 100644
@@ -47,7 +47,7 @@ static bool ah_mt(const struct sk_buff *skb, struct xt_action_param *par)
 		 */
 		pr_debug("Dropping evil AH tinygram.\n");
 		par->hotdrop = true;
-		return 0;
+		return false;
 	}
 
 	return spi_match(ahinfo->spis[0], ahinfo->spis[1],
Signature · 1 line
2.11.0
author maintainer
#6 lore raw

PATCH 6/47 netfilter: unlock xt_table earlier in __do_replace

In reply to Pablo Neira Ayuso

From: Xin Long <[email protected]>

Now it's doing cleanup_entry for oldinfo under the xt_table lock, but it's not really necessary. After the replacement job is done in xt_replace_table, oldinfo is not used elsewhere any more, and it can be freed without xt_table lock safely.

The important thing is that rtnl_lock is called in some xt_target destroy, which means rtnl_lock, a big lock is used in xt_table lock, a smaller one. It usually could be the reason why a dead lock may happen.

Besides, all xt_target/match checkentry is called out of xt_table lock. It's better also to move all cleanup_entry calling out of xt_table lock, just as do_replace_finish does for ebtables.

---
 net/ipv4/netfilter/arp_tables.c | 3 ++-
 net/ipv4/netfilter/ip_tables.c  | 3 ++-
 net/ipv6/netfilter/ip6_tables.c | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
net/ipv4/netfilter/arp_tables.c +2 -1
index c36ffce3c812..a0c7ce76879c 100644
@@ -925,6 +925,8 @@ static int __do_replace(struct net *net, const char *name,
 	    (newinfo->number <= oldinfo->initial_entries))
 		module_put(t->me);
 
+	xt_table_unlock(t);
+
 	get_old_counters(oldinfo, counters);
 
 	/* Decrease module usage counts and free resource */
@@ -939,7 +941,6 @@ static int __do_replace(struct net *net, const char *name,
 		net_warn_ratelimited("arptables: counters copy to user failed while replacing table\n");
 	}
 	vfree(counters);
-	xt_table_unlock(t);
 	return ret;
 
  put_module:
net/ipv4/netfilter/ip_tables.c +2 -1
index d4f7584d2dbe..4f7153e25e0b 100644
@@ -1087,6 +1087,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
 	    (newinfo->number <= oldinfo->initial_entries))
 		module_put(t->me);
 
+	xt_table_unlock(t);
+
 	get_old_counters(oldinfo, counters);
 
 	/* Decrease module usage counts and free resource */
@@ -1100,7 +1102,6 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
 		net_warn_ratelimited("iptables: counters copy to user failed while replacing table\n");
 	}
 	vfree(counters);
-	xt_table_unlock(t);
 	return ret;
 
  put_module:
net/ipv6/netfilter/ip6_tables.c +2 -1
index 4de8ac1e5af4..6c44033decab 100644
@@ -1105,6 +1105,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
 	    (newinfo->number <= oldinfo->initial_entries))
 		module_put(t->me);
 
+	xt_table_unlock(t);
+
 	get_old_counters(oldinfo, counters);
 
 	/* Decrease module usage counts and free resource */
@@ -1118,7 +1120,6 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
 		net_warn_ratelimited("ip6tables: counters copy to user failed while replacing table\n");
 	}
 	vfree(counters);
-	xt_table_unlock(t);
 	return ret;
 
  put_module:
Signature · 1 line
2.11.0
author maintainer
#7 lore raw

PATCH 7/47 netfilter: x_tables: check standard verdicts in core

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Userspace must provide a valid verdict to the standard target.

The verdict can be either a jump (signed int > 0), or a return code.

Allowed return codes are either RETURN (pop from stack), NF_ACCEPT, DROP and QUEUE (latter is allowed for legacy reasons).

Jump offsets (verdict > 0) are checked in more detail later on when loop-detection is performed.

---
 net/ipv4/netfilter/arp_tables.c |  5 -----
 net/ipv4/netfilter/ip_tables.c  |  5 -----
 net/ipv6/netfilter/ip6_tables.c |  5 -----
 net/netfilter/x_tables.c        | 49 ++++++++++++++++++++++++++++++++++++-----
 4 files changed, 43 insertions(+), 21 deletions(-)
net/ipv4/netfilter/arp_tables.c +0 -5
index a0c7ce76879c..c9ffa884a4ee 100644
@@ -334,11 +334,6 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
 			     t->verdict < 0) || visited) {
 				unsigned int oldpos, size;
 
-				if ((strcmp(t->target.u.user.name,
-					    XT_STANDARD_TARGET) == 0) &&
-				    t->verdict < -NF_MAX_VERDICT - 1)
-					return 0;
-
 				/* Return: backtrack through the last
 				 * big jump.
 				 */
net/ipv4/netfilter/ip_tables.c +0 -5
index 4f7153e25e0b..c9b57a6bf96a 100644
@@ -402,11 +402,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
 			     t->verdict < 0) || visited) {
 				unsigned int oldpos, size;
 
-				if ((strcmp(t->target.u.user.name,
-					    XT_STANDARD_TARGET) == 0) &&
-				    t->verdict < -NF_MAX_VERDICT - 1)
-					return 0;
-
 				/* Return: backtrack through the last
 				   big jump. */
 				do {
net/ipv6/netfilter/ip6_tables.c +0 -5
index 6c44033decab..f46954221933 100644
@@ -420,11 +420,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
 			     t->verdict < 0) || visited) {
 				unsigned int oldpos, size;
 
-				if ((strcmp(t->target.u.user.name,
-					    XT_STANDARD_TARGET) == 0) &&
-				    t->verdict < -NF_MAX_VERDICT - 1)
-					return 0;
-
 				/* Return: backtrack through the last
 				   big jump. */
 				do {
net/netfilter/x_tables.c +43 -6

67 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH 8/47 netfilter: x_tables: check error target size too

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Check that userspace ERROR target (custom user-defined chains) match expected format, and the chain name is null terminated.

This is irrelevant for kernel, but iptables itself relies on sane input when it dumps rules from kernel.

---
 net/netfilter/x_tables.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
net/netfilter/x_tables.c +23 -0
index 2e4d423e58e6..f045bb4f7063 100644
@@ -654,6 +654,11 @@ struct compat_xt_standard_target {
 	compat_uint_t verdict;
 };
 
+struct compat_xt_error_target {
+	struct compat_xt_entry_target t;
+	char errorname[XT_FUNCTION_MAXNAMELEN];
+};
+
 static bool verdict_ok(int verdict)
 {
 	if (verdict > 0)
@@ -679,6 +684,12 @@ static bool verdict_ok(int verdict)
 	return false;
 }
 
+static bool error_tg_ok(unsigned int usersize, unsigned int kernsize,
+			const char *msg, unsigned int msglen)
+{
+	return usersize == kernsize && strnlen(msg, msglen) < msglen;
+}
+
 int xt_compat_check_entry_offsets(const void *base, const char *elems,
 				  unsigned int target_offset,
 				  unsigned int next_offset)
@@ -708,6 +719,12 @@ int xt_compat_check_entry_offsets(const void *base, const char *elems,
 
 		if (!verdict_ok(st->verdict))
 			return -EINVAL;
+	} else if (strcmp(t->u.user.name, XT_ERROR_TARGET) == 0) {
+		const struct compat_xt_error_target *et = (const void *)t;
+
+		if (!error_tg_ok(t->u.target_size, sizeof(*et),
+				 et->errorname, sizeof(et->errorname)))
+			return -EINVAL;
 	}
 
 	/* compat_xt_entry match has less strict alignment requirements,
@@ -796,6 +813,12 @@ int xt_check_entry_offsets(const void *base,
 
 		if (!verdict_ok(st->verdict))
 			return -EINVAL;
+	} else if (strcmp(t->u.user.name, XT_ERROR_TARGET) == 0) {
+		const struct xt_error_target *et = (const void *)t;
+
+		if (!error_tg_ok(t->u.target_size, sizeof(*et),
+				 et->errorname, sizeof(et->errorname)))
+			return -EINVAL;
 	}
 
 	return xt_check_entry_match(elems, base + target_offset,
Signature · 1 line
2.11.0
author maintainer
#9 lore raw

PATCH 9/47 netfilter: x_tables: move hook entry checks into core

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Allow followup patch to change on location instead of three.

---
 include/linux/netfilter/x_tables.h |  2 ++
 net/ipv4/netfilter/arp_tables.c    | 13 +++----------
 net/ipv4/netfilter/ip_tables.c     | 13 +++----------
 net/ipv6/netfilter/ip6_tables.c    | 13 +++----------
 net/netfilter/x_tables.c           | 29 +++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+), 30 deletions(-)
include/linux/netfilter/x_tables.h +2 -0
index 1313b35c3ab7..fa0c19c328f1 100644
@@ -281,6 +281,8 @@ int xt_check_entry_offsets(const void *base, const char *elems,
 			   unsigned int target_offset,
 			   unsigned int next_offset);
 
+int xt_check_table_hooks(const struct xt_table_info *info, unsigned int valid_hooks);
+
 unsigned int *xt_alloc_entry_offsets(unsigned int size);
 bool xt_find_jump_offset(const unsigned int *offsets,
 			 unsigned int target, unsigned int size);
net/ipv4/netfilter/arp_tables.c +3 -10
index c9ffa884a4ee..be5821215ea0 100644
@@ -555,16 +555,9 @@ static int translate_table(struct xt_table_info *newinfo, void *entry0,
 	if (i != repl->num_entries)
 		goto out_free;
 
-	/* Check hooks all assigned */
-	for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
-		/* Only hooks which are valid */
-		if (!(repl->valid_hooks & (1 << i)))
-			continue;
-		if (newinfo->hook_entry[i] == 0xFFFFFFFF)
-			goto out_free;
-		if (newinfo->underflow[i] == 0xFFFFFFFF)
-			goto out_free;
-	}
+	ret = xt_check_table_hooks(newinfo, repl->valid_hooks);
+	if (ret)
+		goto out_free;
 
 	if (!mark_source_chains(newinfo, repl->valid_hooks, entry0, offsets)) {
 		ret = -ELOOP;
net/ipv4/netfilter/ip_tables.c +3 -10
index c9b57a6bf96a..29bda9484a33 100644
@@ -702,16 +702,9 @@ translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
 	if (i != repl->num_entries)
 		goto out_free;
 
-	/* Check hooks all assigned */
-	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
-		/* Only hooks which are valid */
-		if (!(repl->valid_hooks & (1 << i)))
-			continue;
-		if (newinfo->hook_entry[i] == 0xFFFFFFFF)
-			goto out_free;
-		if (newinfo->underflow[i] == 0xFFFFFFFF)
-			goto out_free;
-	}
+	ret = xt_check_table_hooks(newinfo, repl->valid_hooks);
+	if (ret)
+		goto out_free;
 
 	if (!mark_source_chains(newinfo, repl->valid_hooks, entry0, offsets)) {
 		ret = -ELOOP;
net/ipv6/netfilter/ip6_tables.c +3 -10
index f46954221933..ba3776a4d305 100644
@@ -720,16 +720,9 @@ translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
 	if (i != repl->num_entries)
 		goto out_free;
 
-	/* Check hooks all assigned */
-	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
-		/* Only hooks which are valid */
-		if (!(repl->valid_hooks & (1 << i)))
-			continue;
-		if (newinfo->hook_entry[i] == 0xFFFFFFFF)
-			goto out_free;
-		if (newinfo->underflow[i] == 0xFFFFFFFF)
-			goto out_free;
-	}
+	ret = xt_check_table_hooks(newinfo, repl->valid_hooks);
+	if (ret)
+		goto out_free;
 
 	if (!mark_source_chains(newinfo, repl->valid_hooks, entry0, offsets)) {
 		ret = -ELOOP;
net/netfilter/x_tables.c +29 -0
index f045bb4f7063..5d8ba89a8da8 100644
@@ -518,6 +518,35 @@ static int xt_check_entry_match(const char *match, const char *target,
 	return 0;
 }
 
+/** xt_check_table_hooks - check hook entry points are sane
+ *
+ * @info xt_table_info to check
+ * @valid_hooks - hook entry points that we can enter from
+ *
+ * Validates that the hook entry and underflows points are set up.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int xt_check_table_hooks(const struct xt_table_info *info, unsigned int valid_hooks)
+{
+	unsigned int i;
+
+	BUILD_BUG_ON(ARRAY_SIZE(info->hook_entry) != ARRAY_SIZE(info->underflow));
+
+	for (i = 0; i < ARRAY_SIZE(info->hook_entry); i++) {
+		if (!(valid_hooks & (1 << i)))
+			continue;
+
+		if (info->hook_entry[i] == 0xFFFFFFFF)
+			return -EINVAL;
+		if (info->underflow[i] == 0xFFFFFFFF)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(xt_check_table_hooks);
+
 #ifdef CONFIG_COMPAT
 int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta)
 {
Signature · 1 line
2.11.0
maintainer
#10 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 30 Mar 2018 13:36:42 +0200

Quoted 4 lines

The following patchset contains Netfilter/IPVS updates for your net-next tree. This batch comes with more input sanitization for xtables to address bug reports from fuzzers, preparation works to the flowtable infrastructure and assorted updates. In no particular order, they are:

Pulled, but I have to ask you not to handle things this way next time.

The other week when I pushed back on your pull request, I asked for some explanations about the flow table situation.

When I was satisfied with the explanation I explicitly asked you to resend _exactly_ the original pull request.

I asked you to do this because I didn't want to see a huge pull request like this one show up later.

And this is exactly what happend. :-/

Please, next time I ask you to resend a pull request I have a very good reason for doing so, so please do it.

Thanks.

#11 lore raw
In reply to Pablo Neira Ayuso

Hi Pablo,

Quoted 35 lines

The following patchset contains Netfilter/IPVS updates for your net-next tree. This batch comes with more input sanitization for xtables to address bug reports from fuzzers, preparation works to the flowtable infrastructure and assorted updates. In no particular order, they are:

1) Make sure userspace provides a valid standard target verdict, from Florian Westphal.

2) Sanitize error target size, also from Florian.

3) Validate that last rule in basechain matches underflow/policy since userspace assumes this when decoding the ruleset blob that comes from the kernel, from Florian.

4) Consolidate hook entry checks through xt_check_table_hooks(), patch from Florian.

5) Cap ruleset allocations at 512 mbytes, 134217728 rules and reject very large compat offset arrays, so we have a reasonable upper limit and fuzzers don't exercise the oom-killer. Patches from Florian.

6) Several WARN_ON checks on xtables mutex helper, from Florian.

7) xt_rateest now has a hashtable per net, from Cong Wang.

8) Consolidate counter allocation in xt_counters_alloc(), from Florian.

9) Earlier xt_table_unlock() call in {ip,ip6,arp,eb}tables, patch from Xin Long.

10) Set FLOW_OFFLOAD_DIR_* to IP_CT_DIR_* definitions, patch from Felix Fietkau.

11) Consolidate code through flow_offload_fill_dir(), also from Felix.

Quoted 8 lines

12) Inline ip6_dst_mtu_forward() just like ip_dst_mtu_maybe_forward() to remove a dependency with flowtable and ipv6.ko, from Felix.

13) Cache mtu size in flow_offload_tuple object, this is safe for forwarding as f87c10a8aa1e describes, from Felix.

14) Rename nf_flow_table.c to nf_flow_table_core.o, to simplify too modular infrastructure, from Felix.

I see you mentioned changes from Felix in the pull request but:
1) I don't see any commits from Felix listed below
2) I don't think you sent any of these patches

Can you take a look at what has happened to them, please?

author maintainer
#12 lore raw

Hi Rafal,

Quoted 2 lines · Rafał Miłecki

Hi Pablo,

[...]

Quoted 5 lines

I see you mentioned changes from Felix in the pull request but:
1) I don't see any commits from Felix listed below
2) I don't think you sent any of these patches

Can you take a look at what has happened to them, please?

I will include them in my next pull request once net-next opens up again.

Thanks.