Skip to contentSkip to conversation

nf_tables: limit maximum number of jumps/gotos per netns

PATCH In review Pablo Neira Ayuso 3 participants 9 messages Oct 27, 2025 – Oct 29, 2025

Subsystems (4)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

v2 cover nf_tables: limit maximum number of jumps/gotos per netns

Hi,

This new series contains v2 to add limit per
-

Pablo Neira Ayuso (2):
netfilter: nf_tables: limit maximum number of jumps/gotos per netns
selftests: netfilter: add test for nf_tables_jumps_max_netns sysctl

 Documentation/networking/netfilter-sysctl.rst |  15 ++
 include/net/netfilter/nf_tables.h             |   7 +
 include/net/netns/netfilter.h                 |   6 +
 net/netfilter/Makefile                        |   2 +-
 net/netfilter/core.c                          |   9 ++
 net/netfilter/nf_tables_api.c                 |  95 +++++++++++-
 net/netfilter/nf_tables_sysctl.c              |  91 +++++++++++
 net/netfilter/nft_immediate.c                 |   4 +
 net/netfilter/nft_lookup.c                    |   9 ++
 .../testing/selftests/net/netfilter/Makefile  |   2 +
 .../net/netfilter/gen_ruleset_many_jumps.c    | 145 ++++++++++++++++++
 .../net/netfilter/nft_ruleset_many_jumps.sh   | 118 ++++++++++++++
 12 files changed, 498 insertions(+), 5 deletions(-)
 create mode 100644 net/netfilter/nf_tables_sysctl.c
 create mode 100644 tools/testing/selftests/net/netfilter/gen_ruleset_many_jumps.c
 create mode 100755 tools/testing/selftests/net/netfilter/nft_ruleset_many_jumps.sh
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH v2 1/2 netfilter: nf_tables: limit maximum number of jumps/gotos per netns

Add a new sysctl:

net.netfilter.nf_tables_jump_max_netns

which is 65535 by default, because iptables-nft rulesets are more likely to have more jumps/gotos compared to native nftables rulesets.

This limit prevents soft lockups on the packet caused by crafted rulesets with too many jumps

The default limit (in Shaun Brady's words) was chosen to account for any normal use case, and when this value (and associated stressing loop table) was tested against a 1CPU/256MB machine, the system remained functional.

This jump/goto limit is global for all tables that are defined in the netns, regardless the family type.

Note that verdict maps count as a single jump/goto because a map lookup provides a single exact match, therefore, this is equivalent to an immediate jump.

This limit is not the net count of jumps in your ruleset, but the number of jumps can be visited traversing the acyclic directed graph with depth-first search. This is done from control plane where the evaluation of the selectors is not possible, therefore, this represents the hypothetical worst case.

This patch adds a jump_count[2] field per table which stores the current number of jumps/gotos in the present [0] and the future [1]. During the preparation phase, jump_count[1] is updated to store the number of jumps after the last table validation while processing the batch.

If this batch does not update the number of jumps in this table, then jump_count[0] provides the current number of jumps and jump_count[1] is set to -1. When checking if the number of jumps go over the limit, check if jump_count[1] is >= 0, meaning the number of jumps for this table has been modified by this batch, otherwise use jump_count[0], meaning this table has not been modified in terms of new jumps.

After the commit phase, jump_count[0] is set to jump_count[1] if it is

Quoted 1 line

= 0. Otherwise, in case of abort, jump_count[1] is reset to -1 to

prepare for handling the next batch.

---
v2: - set table's validate_state to NFT_VALIDATE_DO when jump count check fails
otherwise validation loops forever if tables already exists
- disallow user_ns to update nf_tables_jumps_max_netns sysctl
- move sysctl initialization to core instead of nf_tables module (it should be easy to take this back so nf_tables_jumps_max_netns sysctl becomes available only when nf_tables module is loaded)
- move sysctl code to nf_tables_sysctl.c
- update Documentation
- remove WARN_ON_ONCE when changing validate_state from SKIP -> DO needed when jump_count check fails.

Note: Given soft lockup has been always possible, nf-next tree is also good
target tree for this series.

 Documentation/networking/netfilter-sysctl.rst | 15 +++
 include/net/netfilter/nf_tables.h             |  7 ++
 include/net/netns/netfilter.h                 |  6 ++
 net/netfilter/Makefile                        |  2 +-
 net/netfilter/core.c                          |  9 ++
 net/netfilter/nf_tables_api.c                 | 95 ++++++++++++++++++-
 net/netfilter/nf_tables_sysctl.c              | 91 ++++++++++++++++++
 net/netfilter/nft_immediate.c                 |  4 +
 net/netfilter/nft_lookup.c                    |  9 ++
 9 files changed, 233 insertions(+), 5 deletions(-)
 create mode 100644 net/netfilter/nf_tables_sysctl.c
Documentation/networking/netfilter-sysctl.rst +15 -0
index beb6d7b275d4..f0e6312a8814 100644
@@ -15,3 +15,18 @@ nf_log_all_netns - BOOLEAN
 	with LOG target; this aims to prevent containers from flooding host
 	kernel log. If enabled, this target also works in other network
 	namespaces. This variable is only accessible from init_net.
+
+nf_tables_jumps_max_netns - INTEGER (count)
+	default 65536
+
+	This is the maximum number of jumps/gotos that a netns can have across
+	its tables. This limit does not represent the net count of jumps in
+	your ruleset; rather, it represents the number of jumps that can be
+	reached when traversing the ruleset via a depth-first search (DFS).
+	This limit is determined in the control plane, where evaluating the
+	rule selectors is not possible; therefore, it represents the
+	hypothetical worst case. This limit prevents packet path soft lockups
+	caused by rulesets with too many jumps. This limit only applies to
+	non-init_net namespaces and can be read for non-init_user_ns
+	namespaces. Meeting or exceeding this value will prevent additional
+	rules from being added and will return an EMLINK error to the user.
include/net/netfilter/nf_tables.h +7 -0
index fab7dc73f738..c50528a77901 100644
@@ -209,6 +209,7 @@ static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
  *	@family: protocol family
  *	@level: depth of the chains
  *	@report: notify via unicast netlink message
+ * 	@jump_count: jump to chain counter
  *	@reg_inited: bitmap of initialised registers
  */
 struct nft_ctx {
@@ -222,6 +223,7 @@ struct nft_ctx {
 	u8				family;
 	u8				level;
 	bool				report;
+	int				jump_count;
 	DECLARE_BITMAP(reg_inited, NFT_REG32_NUM);
 };
 
@@ -1279,6 +1281,7 @@ static inline void nft_use_inc_restore(u32 *use)
  *	@family:address family
  *	@flags: table flag (see enum nft_table_flags)
  *	@genmask: generation mask
+ * 	@jump_count: current [0] and next [1] jump to chain counter
  *	@nlpid: netlink port ID
  *	@name: name of the table
  *	@udlen: length of the user data
@@ -1298,6 +1301,7 @@ struct nft_table {
 	u16				family:6,
 					flags:8,
 					genmask:2;
+	int				jump_count[2];
 	u32				nlpid;
 	char				*name;
 	u16				udlen;
@@ -1903,6 +1907,9 @@ __printf(2, 3) int nft_request_module(struct net *net, const char *fmt, ...);
 static inline int nft_request_module(struct net *net, const char *fmt, ...) { return -ENOENT; }
 #endif
 
+int netfilter_nf_tables_sysctl_init(void);
+void netfilter_nf_tables_sysctl_fini(void);
+
 struct nftables_pernet {
 	struct list_head	tables;
 	struct list_head	commit_list;
include/net/netns/netfilter.h +6 -0
index a6a0bf4a247e..6199f00fa2cb 100644
@@ -18,6 +18,9 @@ struct netns_nf {
 #ifdef CONFIG_LWTUNNEL
 	struct ctl_table_header *nf_lwtnl_dir_header;
 #endif
+#if IS_ENABLED(CONFIG_NF_TABLES)
+	struct ctl_table_header *nf_tables_dir_header;
+#endif
 #endif
 	struct nf_hook_entries __rcu *hooks_ipv4[NF_INET_NUMHOOKS];
 	struct nf_hook_entries __rcu *hooks_ipv6[NF_INET_NUMHOOKS];
@@ -33,5 +36,8 @@ struct netns_nf {
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
 	unsigned int defrag_ipv6_users;
 #endif
+#if IS_ENABLED(CONFIG_NF_TABLES)
+	unsigned int nf_tables_jumps_max_netns;
+#endif
 };
 #endif
net/netfilter/Makefile +1 -1
index 6bfc250e474f..cdd9cadbd76c 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-netfilter-objs := core.o nf_log.o nf_queue.o nf_sockopt.o utils.o
+netfilter-objs := core.o nf_log.o nf_tables_sysctl.o nf_queue.o nf_sockopt.o utils.o
 
 nf_conntrack-y	:= nf_conntrack_core.o nf_conntrack_standalone.o nf_conntrack_expect.o nf_conntrack_helper.o \
 		   nf_conntrack_proto.o nf_conntrack_proto_generic.o nf_conntrack_proto_tcp.o nf_conntrack_proto_udp.o \
net/netfilter/core.c +9 -0
index 11a702065bab..2753e8aa3f1f 100644
@@ -24,6 +24,7 @@
 #include <linux/rcupdate.h>
 #include <net/net_namespace.h>
 #include <net/netfilter/nf_queue.h>
+#include <net/netfilter/nf_tables.h>
 #include <net/sock.h>
 
 #include "nf_internals.h"
@@ -814,13 +815,21 @@ int __init netfilter_init(void)
 	ret = netfilter_lwtunnel_init();
 	if (ret < 0)
 		goto err_lwtunnel_pernet;
+#endif
+#if IS_ENABLED(CONFIG_NF_TABLES)
+	ret = netfilter_nf_tables_sysctl_init();
+	if (ret < 0)
+		goto err_nft_pernet;
 #endif
 	ret = netfilter_log_init();
 	if (ret < 0)
 		goto err_log_pernet;
 
 	return 0;
+
 err_log_pernet:
+	netfilter_nf_tables_sysctl_fini();
+err_nft_pernet:
 #ifdef CONFIG_LWTUNNEL
 	netfilter_lwtunnel_fini();
 err_lwtunnel_pernet:
net/netfilter/nf_tables_api.c +91 -4

169 lines not on this page · raw message

net/netfilter/nf_tables_sysctl.c new file +91 -0

91 lines not on this page · raw message

net/netfilter/nft_immediate.c +4 -0
index 02ee5fb69871..43f81c81d179 100644
@@ -259,6 +259,10 @@ static int nft_immediate_validate(const struct nft_ctx *ctx,
 	switch (data->verdict.code) {
 	case NFT_JUMP:
 	case NFT_GOTO:
+		if (pctx->jump_count >= INT_MAX)
+			return -EMLINK;
+
+		pctx->jump_count++;
 		pctx->level++;
 		err = nft_chain_validate(ctx, data->verdict.chain);
 		if (err < 0)
net/netfilter/nft_lookup.c +9 -0
index 58c5b14889c4..0051aa5574e6 100644
@@ -246,12 +246,16 @@ static int nft_lookup_validate(const struct nft_ctx *ctx,
 			       const struct nft_expr *expr)
 {
 	const struct nft_lookup *priv = nft_expr_priv(expr);
+	struct nft_ctx *pctx = (struct nft_ctx *)ctx;
 	struct nft_set_iter iter;
 
 	if (!(priv->set->flags & NFT_SET_MAP) ||
 	    priv->set->dtype != NFT_DATA_VERDICT)
 		return 0;
 
+	if (pctx->jump_count >= INT_MAX)
+		return -EMLINK;
+
 	iter.genmask	= nft_genmask_next(ctx->net);
 	iter.type	= NFT_ITER_UPDATE;
 	iter.skip	= 0;
@@ -266,6 +270,11 @@ static int nft_lookup_validate(const struct nft_ctx *ctx,
 	if (iter.err < 0)
 		return iter.err;
 
+	/* Verdict maps always have one exact match per lookup at least, count
+	 * only one jump per set reference.
+	 */
+	pctx->jump_count++;
+
 	return 0;
 }
 
Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

Quoted 6 lines · Pablo Neira Ayuso

Add a new sysctl:

net.netfilter.nf_tables_jump_max_netns

which is 65535 by default, because iptables-nft rulesets are more likely to have more jumps/gotos compared to native nftables rulesets.

I have existing / real-world iptables dumps that exceed 64k :-/ I'll forward you one of them.

Seems this patch misses a reset somewhere to deal with chains/tables being deleted:

sysctl net.netfilter.nf_tables_jumps_max_netns=256000 net.netfilter.nf_tables_jumps_max_netns = 256000
iptables-nft-restore < kubernetes-huge-may-2018.txt; echo $?
0
iptables-nft-restore < kubernetes-huge-may-2018.txt
iptables-nft-restore v1.8.11 (nf_tables):
line 52222: RULE_APPEND failed (Too many links): rule in chain KUBE-SVC-FCXG7AJXWMSO3TT5

works after 'nft flush ruleset'.

I also have a hunch that a followup patch that sepearates ip and ip6 families (since they are mutually exclusive) will be needed sooner than later.

If even a random old iptables-dump exceeds the 64k limit I would expect combined ip+ip6tables rulesets to be even more brittle.

author maintainer
#3 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

Quoted 7 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso

Add a new sysctl:

net.netfilter.nf_tables_jump_max_netns

which is 65535 by default, because iptables-nft rulesets are more likely to have more jumps/gotos compared to native nftables rulesets.

iptables needs higher value, while nftables with vmaps could set a much lower value, because vmap counts as a single immediate jump.

Quoted 1 line

I have existing / real-world iptables dumps that exceed 64k :-/

OK, so k8s can load this ruleset inside userns (because netns can still rise this value). But your concern is the default value, right?

I can extract from that iptables k8 ruleset a good default value.

Quoted 1 line

I'll forward you one of them.

Yes, you passed me this huge ruleset.

Quoted 10 lines

Seems this patch misses a reset somewhere to deal with chains/tables being deleted:

sysctl net.netfilter.nf_tables_jumps_max_netns=256000 net.netfilter.nf_tables_jumps_max_netns = 256000
iptables-nft-restore < kubernetes-huge-may-2018.txt; echo $?
0
iptables-nft-restore < kubernetes-huge-may-2018.txt
iptables-nft-restore v1.8.11 (nf_tables):
line 52222: RULE_APPEND failed (Too many links): rule in chain KUBE-SVC-FCXG7AJXWMSO3TT5

Ah I see, let me have a look, it is missing deleted tables, yes.

Quoted 5 lines

works after 'nft flush ruleset'.

I also have a hunch that a followup patch that sepearates ip and ip6 families (since they are mutually exclusive) will be needed sooner than later.

I can take look, you mean:

- IPv4 count => count jumps in all table except ipv6.
- IPv6 count => count jumps in all table except ipv4.

Here, IIRC, I needed ~8 million jumps (_not_ net jump counts in the rule, I mean number of jumps according to nft_jump_count_check()) in the input chain to see softlockup with KASAN+KMEMLEAK.

256k is still far from 8 million.

Quoted 2 lines

If even a random old iptables-dump exceeds the 64k limit I would expect combined ip+ip6tables rulesets to be even more brittle.

Yes, the problem here to set this default value is iptables, nftables can set it very small, but iptables needs a large one.

I guess native nftables users can safely shrink the default value we are going to set here.

maintainer
#4 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

Quoted 2 lines · Pablo Neira Ayuso

iptables needs higher value, while nftables with vmaps could set a much lower value, because vmap counts as a single immediate jump.

Agreed. nftables can use something like 100 :-)

Quoted 4 lines
Quoted 1 line

I have existing / real-world iptables dumps that exceed 64k :-/

OK, so k8s can load this ruleset inside userns (because netns can still rise this value). But your concern is the default value, right?

Yes, exactly. If you have a system that runs iptables-restore on startup then after kernel update that might fail.

I see that init_net is exempted from any limits and thats a good choice. I'm concerned about containers here.

Quoted 4 lines

I can take look, you mean:

- IPv4 count => count jumps in all table except ipv6.
- IPv6 count => count jumps in all table except ipv4.

Yes, exactly. That should remove a bit of pressure to use a super-large default value.

Quoted 5 lines

Here, IIRC, I needed ~8 million jumps (_not_ net jump counts in the rule, I mean number of jumps according to nft_jump_count_check()) in the input chain to see softlockup with KASAN+KMEMLEAK.

256k is still far from 8 million.

Agreed.

Quoted 5 lines
Quoted 2 lines

If even a random old iptables-dump exceeds the 64k limit I would expect combined ip+ip6tables rulesets to be even more brittle.

Yes, the problem here to set this default value is iptables, nftables can set it very small, but iptables needs a large one.

Right.

Quoted 2 lines

I guess native nftables users can safely shrink the default value we are going to set here.

Yes, absolutely. nft --omptimize could eventually yell at users when it sees too many jumps :)

#5 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

In reply to Pablo Neira Ayuso
kernel test robot noticed the following build errors:

Hi Pablo,

kernel test robot noticed the following build errors:

[auto build test ERROR on netfilter-nf/main]
[also build test ERROR on linus/master v6.18-rc3 next-20251028] [cannot apply to nf-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-limit-maximum-number-of-jumps-gotos-per-netns/20251028-062221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git main
patch link:    https://lore.kernel.org/r/20251027221722.183398-2-pablo%40netfilter.org
patch subject: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns
config: arm-aspeed_g5_defconfig (https://download.01.org/0day-ci/archive/20251028/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251028/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

net/netfilter/core.c: In function 'netfilter_init':

>> net/netfilter/core.c:832:1: warning: label 'err_nft_pernet' defined but not used [-Wunused-label]
     832 | err_nft_pernet:
         | ^~~~~~~~~~~~~~
--
>> net/netfilter/nf_tables_sysctl.c:15:47: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      15 |                 .data           = &init_net.nf.nf_tables_jumps_max_netns,
         |                                               ^
   net/netfilter/nf_tables_sysctl.c:16:53: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      16 |                 .maxlen         = sizeof(init_net.nf.nf_tables_jumps_max_netns),
         |                                                     ^
   net/netfilter/nf_tables_sysctl.c: In function 'nf_tables_sysctl_init':
   net/netfilter/nf_tables_sysctl.c:33:24: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      33 |                 net->nf.nf_tables_jumps_max_netns = NFT_TABLE_DEFAULT_JUMPS_MAX;
         |                        ^
   net/netfilter/nf_tables_sysctl.c:40:24: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      40 |                 net->nf.nf_tables_jumps_max_netns =
         |                        ^
   net/netfilter/nf_tables_sysctl.c:41:36: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      41 |                         init_net.nf.nf_tables_jumps_max_netns;
         |                                    ^
   net/netfilter/nf_tables_sysctl.c:43:33: error: 'struct netns_nf' has no member named 'nf_tables_jumps_max_netns'
      43 |                         &net->nf.nf_tables_jumps_max_netns;
         |                                 ^
>> net/netfilter/nf_tables_sysctl.c:49:17: error: 'struct netns_nf' has no member named 'nf_tables_dir_header'; did you mean 'nf_log_dir_header'?
      49 |         net->nf.nf_tables_dir_header =
         |                 ^~~~~~~~~~~~~~~~~~~~
         |                 nf_log_dir_header
   net/netfilter/nf_tables_sysctl.c:52:22: error: 'struct netns_nf' has no member named 'nf_tables_dir_header'; did you mean 'nf_log_dir_header'?
      52 |         if (!net->nf.nf_tables_dir_header)
         |                      ^~~~~~~~~~~~~~~~~~~~
         |                      nf_log_dir_header
   net/netfilter/nf_tables_sysctl.c: In function 'nf_tables_sysctl_exit':
   net/netfilter/nf_tables_sysctl.c:68:45: error: 'struct netns_nf' has no member named 'nf_tables_dir_header'; did you mean 'nf_log_dir_header'?
      68 |         unregister_net_sysctl_table(net->nf.nf_tables_dir_header);
         |                                             ^~~~~~~~~~~~~~~~~~~~
         |                                             nf_log_dir_header
   net/netfilter/nf_tables_sysctl.c:69:25: error: 'struct netns_nf' has no member named 'nf_tables_dir_header'; did you mean 'nf_log_dir_header'?
      69 |         table = net->nf.nf_tables_dir_header->ctl_table_arg;
         |                         ^~~~~~~~~~~~~~~~~~~~
         |                         nf_log_dir_header

vim +15 net/netfilter/nf_tables_sysctl.c

    11	
    12	static struct ctl_table nf_tables_sysctl_table[] = {
    13		[NF_SYSCTL_NFT_JUMPS_MAX] = {
    14			.procname       = "nf_tables_jumps_max_netns",
  > 15			.data           = &init_net.nf.nf_tables_jumps_max_netns,
    16			.maxlen         = sizeof(init_net.nf.nf_tables_jumps_max_netns),
    17			.mode           = 0644,
    18			.proc_handler   = proc_dointvec,
    19			.extra1		= SYSCTL_ONE,
    20			.extra2		= SYSCTL_INT_MAX,
    21		},
    22	};
    23	
    24	#define NFT_TABLE_DEFAULT_JUMPS_MAX 65535
    25	
    26	static int __net_init nf_tables_sysctl_init(struct net *net)
    27	{
    28		struct ctl_table *table = nf_tables_sysctl_table;
    29	
    30		BUILD_BUG_ON(ARRAY_SIZE(nf_tables_sysctl_table) != NF_SYSCTL_NFT_LAST_SYSCTL);
    31	
    32		if (net_eq(net, &init_net)) {
    33			net->nf.nf_tables_jumps_max_netns = NFT_TABLE_DEFAULT_JUMPS_MAX;
    34		} else {
    35			table = kmemdup(nf_tables_sysctl_table,
    36					sizeof(nf_tables_sysctl_table), GFP_KERNEL);
    37			if (!table)
    38				return -ENOMEM;
    39	
    40			net->nf.nf_tables_jumps_max_netns =
    41				init_net.nf.nf_tables_jumps_max_netns;
    42			table[NF_SYSCTL_NFT_JUMPS_MAX].data =
    43				&net->nf.nf_tables_jumps_max_netns;
    44	
    45			if (net->user_ns != &init_user_ns)
    46				table[NF_SYSCTL_NFT_JUMPS_MAX].mode &= ~0222;
    47		}
    48	
  > 49		net->nf.nf_tables_dir_header =
    50			register_net_sysctl_sz(net, "net/netfilter", table,
    51					       ARRAY_SIZE(nf_tables_sysctl_table));
    52		if (!net->nf.nf_tables_dir_header)
    53			goto err_tbl_free;
    54	
    55		return 0;
    56	
    57	err_tbl_free:
    58		if (table != nf_tables_sysctl_table)
    59			kfree(table);
    60	
    61		return -ENOMEM;
    62	}
    63	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

In reply to Pablo Neira Ayuso
kernel test robot noticed the following build errors:

Hi Pablo,

kernel test robot noticed the following build errors:

[auto build test ERROR on netfilter-nf/main]
[also build test ERROR on linus/master v6.18-rc3 next-20251028] [cannot apply to nf-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-limit-maximum-number-of-jumps-gotos-per-netns/20251028-062221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git main
patch link:    https://lore.kernel.org/r/20251027221722.183398-2-pablo%40netfilter.org
patch subject: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns
config: i386-defconfig (https://download.01.org/0day-ci/archive/20251028/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251028/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/netfilter/nf_tables_sysctl.c:15:34: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      15 |                 .data           = &init_net.nf.nf_tables_jumps_max_netns,
         |                                    ~~~~~~~~~~~ ^
   net/netfilter/nf_tables_sysctl.c:16:40: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      16 |                 .maxlen         = sizeof(init_net.nf.nf_tables_jumps_max_netns),
         |                                          ~~~~~~~~~~~ ^
   net/netfilter/nf_tables_sysctl.c:33:11: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      33 |                 net->nf.nf_tables_jumps_max_netns = NFT_TABLE_DEFAULT_JUMPS_MAX;
         |                 ~~~~~~~ ^
   net/netfilter/nf_tables_sysctl.c:40:11: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      40 |                 net->nf.nf_tables_jumps_max_netns =
         |                 ~~~~~~~ ^
   net/netfilter/nf_tables_sysctl.c:41:16: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      41 |                         init_net.nf.nf_tables_jumps_max_netns;
         |                         ~~~~~~~~~~~ ^
   net/netfilter/nf_tables_sysctl.c:43:13: error: no member named 'nf_tables_jumps_max_netns' in 'struct netns_nf'
      43 |                         &net->nf.nf_tables_jumps_max_netns;
         |                          ~~~~~~~ ^
>> net/netfilter/nf_tables_sysctl.c:49:10: error: no member named 'nf_tables_dir_header' in 'struct netns_nf'; did you mean 'nf_log_dir_header'?
      49 |         net->nf.nf_tables_dir_header =
         |                 ^~~~~~~~~~~~~~~~~~~~
         |                 nf_log_dir_header
   include/net/netns/netfilter.h:17:27: note: 'nf_log_dir_header' declared here
      17 |         struct ctl_table_header *nf_log_dir_header;
         |                                  ^
   net/netfilter/nf_tables_sysctl.c:52:15: error: no member named 'nf_tables_dir_header' in 'struct netns_nf'; did you mean 'nf_log_dir_header'?
      52 |         if (!net->nf.nf_tables_dir_header)
         |                      ^~~~~~~~~~~~~~~~~~~~
         |                      nf_log_dir_header
   include/net/netns/netfilter.h:17:27: note: 'nf_log_dir_header' declared here
      17 |         struct ctl_table_header *nf_log_dir_header;
         |                                  ^
   net/netfilter/nf_tables_sysctl.c:68:38: error: no member named 'nf_tables_dir_header' in 'struct netns_nf'; did you mean 'nf_log_dir_header'?
      68 |         unregister_net_sysctl_table(net->nf.nf_tables_dir_header);
         |                                             ^~~~~~~~~~~~~~~~~~~~
         |                                             nf_log_dir_header
   include/net/netns/netfilter.h:17:27: note: 'nf_log_dir_header' declared here
      17 |         struct ctl_table_header *nf_log_dir_header;
         |                                  ^
   net/netfilter/nf_tables_sysctl.c:69:18: error: no member named 'nf_tables_dir_header' in 'struct netns_nf'; did you mean 'nf_log_dir_header'?
      69 |         table = net->nf.nf_tables_dir_header->ctl_table_arg;
         |                         ^~~~~~~~~~~~~~~~~~~~
         |                         nf_log_dir_header
   include/net/netns/netfilter.h:17:27: note: 'nf_log_dir_header' declared here
      17 |         struct ctl_table_header *nf_log_dir_header;
         |                                  ^

10 errors generated.

vim +15 net/netfilter/nf_tables_sysctl.c

    11	
    12	static struct ctl_table nf_tables_sysctl_table[] = {
    13		[NF_SYSCTL_NFT_JUMPS_MAX] = {
    14			.procname       = "nf_tables_jumps_max_netns",
  > 15			.data           = &init_net.nf.nf_tables_jumps_max_netns,
    16			.maxlen         = sizeof(init_net.nf.nf_tables_jumps_max_netns),
    17			.mode           = 0644,
    18			.proc_handler   = proc_dointvec,
    19			.extra1		= SYSCTL_ONE,
    20			.extra2		= SYSCTL_INT_MAX,
    21		},
    22	};
    23	
    24	#define NFT_TABLE_DEFAULT_JUMPS_MAX 65535
    25	
    26	static int __net_init nf_tables_sysctl_init(struct net *net)
    27	{
    28		struct ctl_table *table = nf_tables_sysctl_table;
    29	
    30		BUILD_BUG_ON(ARRAY_SIZE(nf_tables_sysctl_table) != NF_SYSCTL_NFT_LAST_SYSCTL);
    31	
    32		if (net_eq(net, &init_net)) {
    33			net->nf.nf_tables_jumps_max_netns = NFT_TABLE_DEFAULT_JUMPS_MAX;
    34		} else {
    35			table = kmemdup(nf_tables_sysctl_table,
    36					sizeof(nf_tables_sysctl_table), GFP_KERNEL);
    37			if (!table)
    38				return -ENOMEM;
    39	
    40			net->nf.nf_tables_jumps_max_netns =
    41				init_net.nf.nf_tables_jumps_max_netns;
    42			table[NF_SYSCTL_NFT_JUMPS_MAX].data =
    43				&net->nf.nf_tables_jumps_max_netns;
    44	
    45			if (net->user_ns != &init_user_ns)
    46				table[NF_SYSCTL_NFT_JUMPS_MAX].mode &= ~0222;
    47		}
    48	
  > 49		net->nf.nf_tables_dir_header =
    50			register_net_sysctl_sz(net, "net/netfilter", table,
    51					       ARRAY_SIZE(nf_tables_sysctl_table));
    52		if (!net->nf.nf_tables_dir_header)
    53			goto err_tbl_free;
    54	
    55		return 0;
    56	
    57	err_tbl_free:
    58		if (table != nf_tables_sysctl_table)
    59			kfree(table);
    60	
    61		return -ENOMEM;
    62	}
    63	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns

In reply to Pablo Neira Ayuso
kernel test robot noticed the following build warnings:

Hi Pablo,

kernel test robot noticed the following build warnings:

[auto build test WARNING on netfilter-nf/main]
[also build test WARNING on linus/master v6.18-rc3 next-20251029] [cannot apply to nf-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-limit-maximum-number-of-jumps-gotos-per-netns/20251028-062221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git main
patch link:    https://lore.kernel.org/r/20251027221722.183398-2-pablo%40netfilter.org
patch subject: [PATCH nf 1/2] netfilter: nf_tables: limit maximum number of jumps/gotos per netns
config: arm-randconfig-003-20251028 (https://download.01.org/0day-ci/archive/20251029/[email protected]/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d1c086e82af239b245fe8d7832f2753436634990)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251029/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from net/netfilter/core.c:27:
In file included from include/net/netfilter/nf_tables.h:13:
In file included from include/net/netfilter/nf_flow_table.h:13:
In file included from include/linux/if_pppox.h:17:
include/uapi/linux/if_pppox.h:71:4: warning: field sa_addr within 'struct sockaddr_pppox' is less aligned than 'union (unnamed union at include/uapi/linux/if_pppox.h:68:2)' and is usually due to 'struct sockaddr_pppox' being packed, which can lead to unaligned accesses [-Wunaligned-access]

      71 |         } sa_addr;
         |           ^
>> net/netfilter/core.c:832:1: warning: unused label 'err_nft_pernet' [-Wunused-label]
     832 | err_nft_pernet:
         | ^~~~~~~~~~~~~~~

2 warnings generated.

vim +/err_nft_pernet +832 net/netfilter/core.c

805
806 int __init netfilter_init(void)
807 {
808 int ret;
809
810 ret = register_pernet_subsys(&netfilter_net_ops);
811 if (ret < 0)
812 goto err;
813
814 #ifdef CONFIG_LWTUNNEL
815 ret = netfilter_lwtunnel_init();
816 if (ret < 0)
817 goto err_lwtunnel_pernet;
818 #endif
819 #if IS_ENABLED(CONFIG_NF_TABLES)
820 ret = netfilter_nf_tables_sysctl_init();
821 if (ret < 0)
822 goto err_nft_pernet;
823 #endif
824 ret = netfilter_log_init();
825 if (ret < 0)
826 goto err_log_pernet;
827
828 return 0;
829
830 err_log_pernet:
831 netfilter_nf_tables_sysctl_fini();

 > 832	err_nft_pernet:
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#8 lore raw

PATCH v2 2/2 selftests: netfilter: add test for nf_tables_jumps_max_netns sysctl

In reply to Pablo Neira Ayuso

This patch adds gen_ruleset_many_jumps.c which is a program that generates a random ruleset with many jumps and it estimates the number of jumps that results from its evaluation.

nft_ruleset_many_jumps.sh creates the ruleset and tests if it loads or fail as expected according to the estimated number of jumps.

---
v2: new in this series, in gen_ruleset_many_jumps.c:
- create_ruleset() represents jump rules per chain at different levels in an array.
- count_jumps() provides an estimation of the number of jumps in the worst case scenario which is similar to the DFS-based count that the kernel performs. This code can be generalised later on to make a tool for tuning nf_tables_jumps_max_netns, if user really ever needs to.

 .../testing/selftests/net/netfilter/Makefile  |   2 +
 .../net/netfilter/gen_ruleset_many_jumps.c    | 145 ++++++++++++++++++
 .../net/netfilter/nft_ruleset_many_jumps.sh   | 118 ++++++++++++++
 3 files changed, 265 insertions(+)
 create mode 100644 tools/testing/selftests/net/netfilter/gen_ruleset_many_jumps.c
 create mode 100755 tools/testing/selftests/net/netfilter/nft_ruleset_many_jumps.sh
tools/testing/selftests/net/netfilter/Makefile +2 -0
index ee2d1a5254f8..dc1b328be31d 100644
@@ -31,6 +31,7 @@ TEST_PROGS := \
 	nft_meta.sh \
 	nft_nat.sh \
 	nft_nat_zones.sh \
+	nft_ruleset_many_jumps.sh \
 	nft_queue.sh \
 	nft_synproxy.sh \
 	nft_tproxy_tcp.sh \
@@ -48,6 +49,7 @@ TEST_GEN_FILES = \
 	connect_close \
 	conntrack_dump_flush \
 	conntrack_reverse_clash \
+	gen_ruleset_many_jumps \
 	nf_queue \
 	sctp_collision \
 	udpclash \
tools/testing/selftests/net/netfilter/gen_ruleset_many_jumps.c new file +145 -0

145 lines not on this page · raw message

tools/testing/selftests/net/netfilter/nft_ruleset_many_jumps.sh new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.30.2