* [PATCH net 0/5] Netfilter fixes for net:
@ 2023-07-20 16:51 Florian Westphal
2023-07-20 16:51 ` [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel
The following patchset contains Netfilter fixes for net:
1. Fix spurious -EEXIST error from userspace due to
padding holes, this was broken since 4.9 days
when 'ignore duplicate entries on insert' feature was
added.
2. Fix a sched-while-atomic bug, present since 5.19.
3. Properly remove elements if they lack an "end range".
nft userspace always sets an end range attribute, even
when its the same as the start, but the abi doesn't
have such a restriction. Always broken since it was
added in 5.6, all three from myself.
4 + 5: Bound chain needs to be skipped in netns release
and on rule flush paths, from Pablo Neira.
The following changes since commit ac528649f7c63bc233cc0d33cff11f767cc666e3:
Merge branch 'net-support-stp-on-bridge-in-non-root-netns' (2023-07-20 10:46:33 +0200)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-23-07-20
for you to fetch changes up to 6eaf41e87a223ae6f8e7a28d6e78384ad7e407f8:
netfilter: nf_tables: skip bound chain on rule flush (2023-07-20 17:21:11 +0200)
----------------------------------------------------------------
netfilter pull request 2023-07-20
----------------------------------------------------------------
Florian Westphal (3):
netfilter: nf_tables: fix spurious set element insertion failure
netfilter: nf_tables: can't schedule in nft_chain_validate
netfilter: nft_set_pipapo: fix improper element removal
Pablo Neira Ayuso (2):
netfilter: nf_tables: skip bound chain in netns release path
netfilter: nf_tables: skip bound chain on rule flush
net/netfilter/nf_tables_api.c | 12 ++++++++++--
net/netfilter/nft_set_pipapo.c | 6 +++++-
2 files changed, 15 insertions(+), 3 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
@ 2023-07-20 16:51 ` Florian Westphal
2023-07-20 20:00 ` patchwork-bot+netdevbpf
2023-07-20 16:51 ` [PATCH net 2/5] netfilter: nf_tables: can't schedule in nft_chain_validate Florian Westphal
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel
On some platforms there is a padding hole in the nft_verdict
structure, between the verdict code and the chain pointer.
On element insertion, if the new element clashes with an existing one and
NLM_F_EXCL flag isn't set, we want to ignore the -EEXIST error as long as
the data associated with duplicated element is the same as the existing
one. The data equality check uses memcmp.
For normal data (NFT_DATA_VALUE) this works fine, but for NFT_DATA_VERDICT
padding area leads to spurious failure even if the verdict data is the
same.
This then makes the insertion fail with 'already exists' error, even
though the new "key : data" matches an existing entry and userspace
told the kernel that it doesn't want to receive an error indication.
Fixes: c016c7e45ddf ("netfilter: nf_tables: honor NLM_F_EXCL flag in set element insertion")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 237f739da3ca..79c7eee33dcd 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -10517,6 +10517,9 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
if (!tb[NFTA_VERDICT_CODE])
return -EINVAL;
+
+ /* zero padding hole for memcmp */
+ memset(data, 0, sizeof(*data));
data->verdict.code = ntohl(nla_get_be32(tb[NFTA_VERDICT_CODE]));
switch (data->verdict.code) {
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 2/5] netfilter: nf_tables: can't schedule in nft_chain_validate
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
2023-07-20 16:51 ` [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
@ 2023-07-20 16:51 ` Florian Westphal
2023-07-20 16:51 ` [PATCH net 3/5] netfilter: nft_set_pipapo: fix improper element removal Florian Westphal
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel
Can be called via nft set element list iteration, which may acquire
rcu and/or bh read lock (depends on set type).
BUG: sleeping function called from invalid context at net/netfilter/nf_tables_api.c:3353
in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1232, name: nft
preempt_count: 0, expected: 0
RCU nest depth: 1, expected: 0
2 locks held by nft/1232:
#0: ffff8881180e3ea8 (&nft_net->commit_mutex){+.+.}-{3:3}, at: nf_tables_valid_genid
#1: ffffffff83f5f540 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire
Call Trace:
nft_chain_validate
nft_lookup_validate_setelem
nft_pipapo_walk
nft_lookup_validate
nft_chain_validate
nft_immediate_validate
nft_chain_validate
nf_tables_validate
nf_tables_abort
No choice but to move it to nf_tables_validate().
Fixes: 81ea01066741 ("netfilter: nf_tables: add rescheduling points during loop detection walks")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 79c7eee33dcd..41e7d21d4429 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -3685,8 +3685,6 @@ int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain)
if (err < 0)
return err;
}
-
- cond_resched();
}
return 0;
@@ -3710,6 +3708,8 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)
err = nft_chain_validate(&ctx, chain);
if (err < 0)
return err;
+
+ cond_resched();
}
return 0;
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 3/5] netfilter: nft_set_pipapo: fix improper element removal
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
2023-07-20 16:51 ` [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
2023-07-20 16:51 ` [PATCH net 2/5] netfilter: nf_tables: can't schedule in nft_chain_validate Florian Westphal
@ 2023-07-20 16:51 ` Florian Westphal
2023-07-20 16:51 ` [PATCH net 4/5] netfilter: nf_tables: skip bound chain in netns release path Florian Westphal
2023-07-20 16:51 ` [PATCH net 5/5] netfilter: nf_tables: skip bound chain on rule flush Florian Westphal
4 siblings, 0 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel, lonial con, Stefano Brivio
end key should be equal to start unless NFT_SET_EXT_KEY_END is present.
Its possible to add elements that only have a start key
("{ 1.0.0.0 . 2.0.0.0 }") without an internval end.
Insertion treats this via:
if (nft_set_ext_exists(ext, NFT_SET_EXT_KEY_END))
end = (const u8 *)nft_set_ext_key_end(ext)->data;
else
end = start;
but removal side always uses nft_set_ext_key_end().
This is wrong and leads to garbage remaining in the set after removal
next lookup/insert attempt will give:
BUG: KASAN: slab-use-after-free in pipapo_get+0x8eb/0xb90
Read of size 1 at addr ffff888100d50586 by task nft-pipapo_uaf_/1399
Call Trace:
kasan_report+0x105/0x140
pipapo_get+0x8eb/0xb90
nft_pipapo_insert+0x1dc/0x1710
nf_tables_newsetelem+0x31f5/0x4e00
..
Fixes: 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges")
Reported-by: lonial con <kongln9170@gmail.com>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nft_set_pipapo.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
index db526cb7a485..49915a2a58eb 100644
--- a/net/netfilter/nft_set_pipapo.c
+++ b/net/netfilter/nft_set_pipapo.c
@@ -1929,7 +1929,11 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set,
int i, start, rules_fx;
match_start = data;
- match_end = (const u8 *)nft_set_ext_key_end(&e->ext)->data;
+
+ if (nft_set_ext_exists(&e->ext, NFT_SET_EXT_KEY_END))
+ match_end = (const u8 *)nft_set_ext_key_end(&e->ext)->data;
+ else
+ match_end = data;
start = first_rule;
rules_fx = rules_f0;
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 4/5] netfilter: nf_tables: skip bound chain in netns release path
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
` (2 preceding siblings ...)
2023-07-20 16:51 ` [PATCH net 3/5] netfilter: nft_set_pipapo: fix improper element removal Florian Westphal
@ 2023-07-20 16:51 ` Florian Westphal
2023-07-20 16:51 ` [PATCH net 5/5] netfilter: nf_tables: skip bound chain on rule flush Florian Westphal
4 siblings, 0 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel, Pablo Neira Ayuso
From: Pablo Neira Ayuso <pablo@netfilter.org>
Skip bound chain from netns release path, the rule that owns this chain
releases these objects.
Fixes: d0e2c7de92c7 ("netfilter: nf_tables: add NFT_CHAIN_BINDING")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 41e7d21d4429..40bff6e2ea5d 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -10802,6 +10802,9 @@ static void __nft_release_table(struct net *net, struct nft_table *table)
ctx.family = table->family;
ctx.table = table;
list_for_each_entry(chain, &table->chains, list) {
+ if (nft_chain_is_bound(chain))
+ continue;
+
ctx.chain = chain;
list_for_each_entry_safe(rule, nr, &chain->rules, list) {
list_del(&rule->list);
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 5/5] netfilter: nf_tables: skip bound chain on rule flush
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
` (3 preceding siblings ...)
2023-07-20 16:51 ` [PATCH net 4/5] netfilter: nf_tables: skip bound chain in netns release path Florian Westphal
@ 2023-07-20 16:51 ` Florian Westphal
4 siblings, 0 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 16:51 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
netfilter-devel, Pablo Neira Ayuso, Kevin Rich
From: Pablo Neira Ayuso <pablo@netfilter.org>
Skip bound chain when flushing table rules, the rule that owns this
chain releases these objects.
Otherwise, the following warning is triggered:
WARNING: CPU: 2 PID: 1217 at net/netfilter/nf_tables_api.c:2013 nf_tables_chain_destroy+0x1f7/0x210 [nf_tables]
CPU: 2 PID: 1217 Comm: chain-flush Not tainted 6.1.39 #1
RIP: 0010:nf_tables_chain_destroy+0x1f7/0x210 [nf_tables]
Fixes: d0e2c7de92c7 ("netfilter: nf_tables: add NFT_CHAIN_BINDING")
Reported-by: Kevin Rich <kevinrich1337@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 40bff6e2ea5d..b9a4d3fd1d34 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4087,6 +4087,8 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
list_for_each_entry(chain, &table->chains, list) {
if (!nft_is_active_next(net, chain))
continue;
+ if (nft_chain_is_bound(chain))
+ continue;
ctx.chain = chain;
err = nft_delrule_by_chain(&ctx);
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure
@ 2023-07-20 19:29 Florian Westphal
0 siblings, 0 replies; 8+ messages in thread
From: Florian Westphal @ 2023-07-20 19:29 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
On some platforms there is a padding hole in the nft_verdict
structure, between the verdict code and the chain pointer.
On element insertion, if the new element clashes with an existing one and
NLM_F_EXCL flag isn't set, we want to ignore the -EEXIST error as long as
the data associated with duplicated element is the same as the existing
one. The data equality check uses memcmp.
For normal data (NFT_DATA_VALUE) this works fine, but for NFT_DATA_VERDICT
padding area leads to spurious failure even if the verdict data is the
same.
This then makes the insertion fail with 'already exists' error, even
though the new "key : data" matches an existing entry and userspace
told the kernel that it doesn't want to receive an error indication.
Fixes: c016c7e45ddf ("netfilter: nf_tables: honor NLM_F_EXCL flag in set element insertion")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 237f739da3ca..79c7eee33dcd 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -10517,6 +10517,9 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
if (!tb[NFTA_VERDICT_CODE])
return -EINVAL;
+
+ /* zero padding hole for memcmp */
+ memset(data, 0, sizeof(*data));
data->verdict.code = ntohl(nla_get_be32(tb[NFTA_VERDICT_CODE]));
switch (data->verdict.code) {
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure
2023-07-20 16:51 ` [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
@ 2023-07-20 20:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-20 20:00 UTC (permalink / raw)
To: Florian Westphal; +Cc: netdev, pabeni, davem, edumazet, kuba, netfilter-devel
Hello:
This series was applied to netdev/net.git (main)
by Florian Westphal <fw@strlen.de>:
On Thu, 20 Jul 2023 18:51:33 +0200 you wrote:
> On some platforms there is a padding hole in the nft_verdict
> structure, between the verdict code and the chain pointer.
>
> On element insertion, if the new element clashes with an existing one and
> NLM_F_EXCL flag isn't set, we want to ignore the -EEXIST error as long as
> the data associated with duplicated element is the same as the existing
> one. The data equality check uses memcmp.
>
> [...]
Here is the summary with links:
- [net,1/5] netfilter: nf_tables: fix spurious set element insertion failure
https://git.kernel.org/netdev/net/c/ddbd8be68941
- [net,2/5] netfilter: nf_tables: can't schedule in nft_chain_validate
https://git.kernel.org/netdev/net/c/314c82841602
- [net,3/5] netfilter: nft_set_pipapo: fix improper element removal
https://git.kernel.org/netdev/net/c/87b5a5c20940
- [net,4/5] netfilter: nf_tables: skip bound chain in netns release path
https://git.kernel.org/netdev/net/c/751d460ccff3
- [net,5/5] netfilter: nf_tables: skip bound chain on rule flush
https://git.kernel.org/netdev/net/c/6eaf41e87a22
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-07-20 20:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 16:51 [PATCH net 0/5] Netfilter fixes for net: Florian Westphal
2023-07-20 16:51 ` [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
2023-07-20 20:00 ` patchwork-bot+netdevbpf
2023-07-20 16:51 ` [PATCH net 2/5] netfilter: nf_tables: can't schedule in nft_chain_validate Florian Westphal
2023-07-20 16:51 ` [PATCH net 3/5] netfilter: nft_set_pipapo: fix improper element removal Florian Westphal
2023-07-20 16:51 ` [PATCH net 4/5] netfilter: nf_tables: skip bound chain in netns release path Florian Westphal
2023-07-20 16:51 ` [PATCH net 5/5] netfilter: nf_tables: skip bound chain on rule flush Florian Westphal
-- strict thread matches above, loose matches on Subject: below --
2023-07-20 19:29 [PATCH net 1/5] netfilter: nf_tables: fix spurious set element insertion failure Florian Westphal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).