Florian Westphal b04df3da1b netfilter: nf_tables: do not defer rule destruction via call_rcu
nf_tables_chain_destroy can sleep, it can't be used from call_rcu
callbacks.

Moreover, nf_tables_rule_release() is only safe for error unwinding,
while transaction mutex is held and the to-be-desroyed rule was not
exposed to either dataplane or dumps, as it deactives+frees without
the required synchronize_rcu() in-between.

nft_rule_expr_deactivate() callbacks will change ->use counters
of other chains/sets, see e.g. nft_lookup .deactivate callback, these
must be serialized via transaction mutex.

Also add a few lockdep asserts to make this more explicit.

Calling synchronize_rcu() isn't ideal, but fixing this without is hard
and way more intrusive.  As-is, we can get:

WARNING: .. net/netfilter/nf_tables_api.c:5515 nft_set_destroy+0x..
Workqueue: events nf_tables_trans_destroy_work
RIP: 0010:nft_set_destroy+0x3fe/0x5c0
Call Trace:
 <TASK>
 nf_tables_trans_destroy_work+0x6b7/0xad0
 process_one_work+0x64a/0xce0
 worker_thread+0x613/0x10d0

In case the synchronize_rcu becomes an issue, we can explore alternatives.

One way would be to allocate nft_trans_rule objects + one nft_trans_chain
object, deactivate the rules + the chain and then defer the freeing to the
nft destroy workqueue.  We'd still need to keep the synchronize_rcu path as
a fallback to handle -ENOMEM corner cases though.

Reported-by: syzbot+b26935466701e56cfdc2@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/67478d92.050a0220.253251.0062.GAE@google.com/T/
Fixes: c03d278fdf35 ("netfilter: nf_tables: wait for rcu grace period on net_device removal")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-12-11 23:27:50 +01:00
..
2024-10-08 15:33:49 -07:00
2024-08-26 09:37:23 -07:00
2024-01-02 12:41:16 +00:00
2024-08-26 09:37:23 -07:00
2024-06-25 11:10:18 +02:00
2022-08-09 22:14:02 -07:00
2024-05-08 10:35:09 +01:00
2024-08-26 09:37:23 -07:00
2024-08-26 09:37:23 -07:00
2024-11-13 18:49:50 -08:00
2024-08-26 09:37:23 -07:00
2023-11-02 09:31:02 +01:00
2024-05-07 01:35:55 +02:00
2024-08-26 09:37:23 -07:00
2021-10-15 11:33:08 +01:00
2024-02-28 11:19:41 +00:00
2023-04-22 01:39:41 +02:00
2024-08-26 09:37:22 -07:00
2021-10-13 09:40:46 -07:00
2024-08-26 09:37:23 -07:00
2024-08-12 17:23:57 -07:00
2024-11-21 08:28:08 -08:00
2024-09-11 20:44:31 -07:00
2024-08-12 17:50:34 -07:00
2024-04-01 10:49:28 +01:00
2023-07-14 20:39:30 -07:00
2024-08-26 09:37:23 -07:00
2024-08-26 09:37:23 -07:00
2024-05-30 18:29:38 -07:00
2024-05-30 18:29:38 -07:00
2019-10-05 16:29:00 -07:00
2023-10-04 11:49:20 -07:00
2024-07-08 14:07:31 -07:00
2024-05-09 20:25:55 -07:00
2023-07-28 14:07:59 -07:00
2022-12-12 15:04:39 -08:00
2023-09-14 16:16:36 +02:00
2024-08-26 09:37:23 -07:00
2023-12-14 16:38:59 +01:00