netfilter updates for net
Subsystems (3)
Florian Westphal
maintainercover netfilter updates for net
Hello,
The following contains patches for your *net* tree.
Patch 1, from Pablo Neira Ayuso, fixes a performance regression (since 6.4) when a large pending set update has to be canceled towards the end of the transaction.
Patch 2 from myself, silences an incorrect compiler warning reported with a few (older) compiler toolchains.
Patch 3, from Kees Cook, adds __counted_by annotation to nft_pipapo set backend type. I took this for net instead of -next given infra is already in place and no actual code change is made.
Patch 4, from Pablo Neira Ayso, disables timeout resets on stateful element reset. The rest should only affect internal object state, e.g. reset a quota or counter, but not affect a pending timeout.
Patches 5 and 6 fix NULL dereferences in 'inner header' match, control plane doesn't test for netlink attribute presence before accessing them. Broken since feature was added in 6.2, fixes from Xingyuan Mo.
Last patch, from myself, fixes a bogus rule match when skb has a 0-length mac header, in this case we'd fetch data from network header instead of canceling rule evaluation. This is a day 0 bug, present since nftables was merged in 3.13.
The following changes since commit 50e492143374c17ad89c865a1a44837b3f5c8226:
octeontx2-pf: Fix page pool frag allocation warning (2023-10-12 09:48:51 +0200)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-23-10-12
for you to fetch changes up to d351c1ea2de3e36e608fc355d8ae7d0cc80e6cd6:
netfilter: nft_payload: fix wrong mac header matching (2023-10-12 10:28:45 +0200)
----------------------------------------------------------------
nf pull request 2023-10-12
----------------------------------------------------------------
Florian Westphal (2):
netfilter: nfnetlink_log: silence bogus compiler warning
netfilter: nft_payload: fix wrong mac header matching
Kees Cook (1):
netfilter: nf_tables: Annotate struct nft_pipapo_match with __counted_by
Pablo Neira Ayuso (2):
netfilter: nf_tables: do not remove elements if set backend implements .abort
netfilter: nf_tables: do not refresh timeout when resetting element
Xingyuan Mo (2):
nf_tables: fix NULL pointer dereference in nft_inner_init()
nf_tables: fix NULL pointer dereference in nft_expr_inner_parse()
net/netfilter/nf_tables_api.c | 25 ++++++++++--------------- net/netfilter/nfnetlink_log.c | 2 +- net/netfilter/nft_inner.c | 1 + net/netfilter/nft_payload.c | 2 +- net/netfilter/nft_set_pipapo.h | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-)
Florian Westphal
maintainerPATCH 1/7 netfilter: nf_tables: do not remove elements if set backend implements .abort
From: Pablo Neira Ayuso <[email protected]>
pipapo set backend maintains two copies of the datastructure, removing the elements from the copy that is going to be discarded slows down the abort path significantly, from several minutes to few seconds after this patch.
--- net/netfilter/nf_tables_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +4 -1
@@ -10347,7 +10347,10 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)break ; } te = (struct nft_trans_elem *)trans->data; -nft_setelem_remove (net, te->set, &te->elem); +if (!te->set->ops->abort || +nft_setelem_is_catchall (te->set, &te->elem)) +nft_setelem_remove (net, te->set, &te->elem); +if (!nft_setelem_is_catchall (te->set, &te->elem))atomic_dec (&te->set->nelems);
Signature · 1 line
2.41.0
Re: [PATCH net 1/7] netfilter: nf_tables: do not remove elements if set backend implements .abort
This series was applied to netdev/net.git (main) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Florian Westphal <[email protected]>:
Quoted 8 lines · On Thu, 12 Oct 2023 10:57:04 +0200 you wrote:
From: Pablo Neira Ayuso <[email protected]>
pipapo set backend maintains two copies of the datastructure, removing the elements from the copy that is going to be discarded slows down the abort path significantly, from several minutes to few seconds after this patch.
[...]
Here is the summary with links:
- [net,1/7] netfilter: nf_tables: do not remove elements if set backend implements .abort
https://git.kernel.org/netdev/net/c/ebd032fa8818 - [net,2/7] netfilter: nfnetlink_log: silence bogus compiler warning https://git.kernel.org/netdev/net/c/2e1d17541097 - [net,3/7] netfilter: nf_tables: Annotate struct nft_pipapo_match with __counted_by https://git.kernel.org/netdev/net/c/d51c42cdef5f - [net,4/7] netfilter: nf_tables: do not refresh timeout when resetting element https://git.kernel.org/netdev/net/c/4c90bba60c26 - [net,5/7] nf_tables: fix NULL pointer dereference in nft_inner_init() https://git.kernel.org/netdev/net/c/52177bbf19e6 - [net,6/7] nf_tables: fix NULL pointer dereference in nft_expr_inner_parse() https://git.kernel.org/netdev/net/c/505ce0630ad5 - [net,7/7] netfilter: nft_payload: fix wrong mac header matching https://git.kernel.org/netdev/net/c/d351c1ea2de3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/7 netfilter: nfnetlink_log: silence bogus compiler warning
In reply to Florian Westphalnet/netfilter/nfnetlink_log.c:800:18: warning: variable 'ctinfo' is uninitialized
The warning is bogus, the variable is only used if ct is non-NULL and always initialised in that case. Init to 0 too to silence this.
--- net/netfilter/nfnetlink_log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_log.c +1 -1
@@ -698,8 +698,8 @@ nfulnl_log_packet(struct net *net,unsigned int plen =0 ;struct nfnl_log_net *log =nfnl_log_pernet (net);const struct nfnl_ct_hook *nfnl_ct =NULL ; +enum ip_conntrack_info ctinfo =0 ;struct nf_conn *ct =NULL ; -enum ip_conntrack_info ctinfo;if (li_user && li_user->type ==NF_LOG_TYPE_ULOG ) li = li_user;
Signature · 1 line
2.41.0
Florian Westphal
maintainerPATCH 3/7 netfilter: nf_tables: Annotate struct nft_pipapo_match with __counted_by
In reply to Florian WestphalFrom: Kees Cook <[email protected]>
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct nft_pipapo_match.
--- net/netfilter/nft_set_pipapo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_set_pipapo.h +1 -1
@@ -147,7 +147,7 @@ struct nft_pipapo_match {unsigned long *__percpu *scratch;size_t bsize_max;struct rcu_head rcu; -struct nft_pipapo_field f[]; + struct nft_pipapo_field f[] __counted_by(field_count); };/**
Signature · 1 line
2.41.0
Florian Westphal
maintainerPATCH 4/7 netfilter: nf_tables: do not refresh timeout when resetting element
In reply to Florian WestphalFrom: Pablo Neira Ayuso <[email protected]>
The dump and reset command should not refresh the timeout, this command is intended to allow users to list existing stateful objects and reset them, element expiration should be refresh via transaction instead with a specific command to achieve this, otherwise this is entering combo semantics that will be hard to be undone later (eg. a user asking to retrieve counters but _not_ requiring to refresh expiration).
--- net/netfilter/nf_tables_api.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
net/netfilter/nf_tables_api.c +5 -13
@@ -5556,7 +5556,6 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,const struct nft_set_ext *ext =nft_set_elem_ext (set, elem->priv);unsigned char *b =skb_tail_pointer (skb);struct nlattr *nest; -u64 timeout =0 ; nest =nla_nest_start_noflag (skb,NFTA_LIST_ELEM );if (nest ==NULL )
@@ -5592,15 +5591,11 @@ static int nf_tables_fill_setelem(struct sk_buff *skb, htonl(*nft_set_ext_flags(ext)))) goto nla_put_failure; -if (nft_set_ext_exists (ext,NFT_SET_EXT_TIMEOUT )) { - timeout = *nft_set_ext_timeout (ext); -if (nla_put_be64 (skb,NFTA_SET_ELEM_TIMEOUT , -nf_jiffies64_to_msecs (timeout), -NFTA_SET_ELEM_PAD )) - goto nla_put_failure; - }else if (set->flags &NFT_SET_TIMEOUT ) { - timeout =READ_ONCE (set->timeout); - } +if (nft_set_ext_exists (ext,NFT_SET_EXT_TIMEOUT ) && +nla_put_be64 (skb,NFTA_SET_ELEM_TIMEOUT , +nf_jiffies64_to_msecs (*nft_set_ext_timeout (ext)), +NFTA_SET_ELEM_PAD )) + goto nla_put_failure;if (nft_set_ext_exists (ext,NFT_SET_EXT_EXPIRATION )) {u64 expires, now =get_jiffies_64 ();
@@ -5615,9 +5610,6 @@ static int nf_tables_fill_setelem(struct sk_buff *skb, nf_jiffies64_to_msecs(expires), NFTA_SET_ELEM_PAD)) goto nla_put_failure; - -if (reset) - *nft_set_ext_expiration (ext) = now + timeout; }if (nft_set_ext_exists (ext,NFT_SET_EXT_USERDATA )) {
Signature · 1 line
2.41.0
Florian Westphal
maintainerPATCH 5/7 nf_tables: fix NULL pointer dereference in nft_inner_init()
In reply to Florian WestphalFrom: Xingyuan Mo <[email protected]>
We should check whether the NFTA_INNER_NUM netlink attribute is present before accessing it, otherwise a null pointer deference error will occur.
Call Trace: dump_stack_lvl+0x4f/0x90 print_report+0x3f0/0x620 kasan_report+0xcd/0x110 __asan_load4+0x84/0xa0 nft_inner_init+0x128/0x2e0 nf_tables_newrule+0x813/0x1230 nfnetlink_rcv_batch+0xec3/0x1170 nfnetlink_rcv+0x1e4/0x220 netlink_unicast+0x34e/0x4b0 netlink_sendmsg+0x45c/0x7e0 __sys_sendto+0x355/0x370 __x64_sys_sendto+0x84/0xa0 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
--- net/netfilter/nft_inner.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_inner.c +1 -0
@@ -298,6 +298,7 @@ static int nft_inner_init(const struct nft_ctx *ctx,int err;if (!tb[NFTA_INNER_FLAGS ] || + !tb[NFTA_INNER_NUM ] || !tb[NFTA_INNER_HDRSIZE ] || !tb[NFTA_INNER_TYPE ] || !tb[NFTA_INNER_EXPR ])
Signature · 1 line
2.41.0
Florian Westphal
maintainerPATCH 6/7 nf_tables: fix NULL pointer dereference in nft_expr_inner_parse()
In reply to Florian WestphalFrom: Xingyuan Mo <[email protected]>
We should check whether the NFTA_EXPR_NAME netlink attribute is present before accessing it, otherwise a null pointer deference error will occur.
Call Trace: <TASK> dump_stack_lvl+0x4f/0x90 print_report+0x3f0/0x620 kasan_report+0xcd/0x110 __asan_load2+0x7d/0xa0 nla_strcmp+0x2f/0x90 __nft_expr_type_get+0x41/0xb0 nft_expr_inner_parse+0xe3/0x200 nft_inner_init+0x1be/0x2e0 nf_tables_newrule+0x813/0x1230 nfnetlink_rcv_batch+0xec3/0x1170 nfnetlink_rcv+0x1e4/0x220 netlink_unicast+0x34e/0x4b0 netlink_sendmsg+0x45c/0x7e0 __sys_sendto+0x355/0x370 __x64_sys_sendto+0x84/0xa0 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -3166,7 +3166,7 @@ int nft_expr_inner_parse(const struct nft_ctx *ctx, const struct nlattr *nla,if (err <0 )return err; -if (!tb[NFTA_EXPR_DATA ]) +if (!tb[NFTA_EXPR_DATA ] || !tb[NFTA_EXPR_NAME ])return -EINVAL ; type =__nft_expr_type_get (ctx->family, tb[NFTA_EXPR_NAME ]);
Signature · 1 line
2.41.0
Florian Westphal
maintainerPATCH 7/7 netfilter: nft_payload: fix wrong mac header matching
In reply to Florian Westphalmcast packets get looped back to the local machine. Such packets have a 0-length mac header, we should treat this like "mac header not set" and abort rule evaluation.
As-is, we just copy data from the network header instead.
--- net/netfilter/nft_payload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_payload.c +1 -1
@@ -179,7 +179,7 @@ void nft_payload_eval(const struct nft_expr *expr,switch (priv->base) {case NFT_PAYLOAD_LL_HEADER : -if (!skb_mac_header_was_set (skb)) +if (!skb_mac_header_was_set (skb) ||skb_mac_header_len (skb) ==0 ) goto err; if (skb_vlan_tag_present(skb) &&
Signature · 1 line
2.41.0