Skip to content

Commit 3811d70

Browse files
committed
Merge: netfilter: nf_tables: do not defer rule destruction via call_rcu
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/117 JIRA: https://issues.redhat.com/browse/RHEL-68691 Fix a 6.12 regression, we cannot defer this via call_rcu as some of the needed helpers must be called with transaction mutex held. Also causes scheduling-while-atomic splats as reported by syzbot upstream. Signed-off-by: Florian Westphal <fwestpha@redhat.com> Approved-by: Phil Sutter <psutter@redhat.com> Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Jan Stancek <jstancek@redhat.com>
2 parents 1c4dc29 + 723bfd6 commit 3811d70

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ struct nft_rule_blob {
11031103
* @name: name of the chain
11041104
* @udlen: user data length
11051105
* @udata: user data in the chain
1106-
* @rcu_head: rcu head for deferred release
11071106
* @blob_next: rule blob pointer to the next in the chain
11081107
*/
11091108
struct nft_chain {
@@ -1121,7 +1120,6 @@ struct nft_chain {
11211120
char *name;
11221121
u16 udlen;
11231122
u8 *udata;
1124-
struct rcu_head rcu_head;
11251123

11261124
/* Only used during control plane commit phase: */
11271125
struct nft_rule_blob *blob_next;
@@ -1265,7 +1263,6 @@ static inline void nft_use_inc_restore(u32 *use)
12651263
* @sets: sets in the table
12661264
* @objects: stateful objects in the table
12671265
* @flowtables: flow tables in the table
1268-
* @net: netnamespace this table belongs to
12691266
* @hgenerator: handle generator state
12701267
* @handle: table handle
12711268
* @use: number of chain references to this table
@@ -1285,7 +1282,6 @@ struct nft_table {
12851282
struct list_head sets;
12861283
struct list_head objects;
12871284
struct list_head flowtables;
1288-
possible_net_t net;
12891285
u64 hgenerator;
12901286
u64 handle;
12911287
u32 use;

net/netfilter/nf_tables_api.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,6 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,
14951495
INIT_LIST_HEAD(&table->sets);
14961496
INIT_LIST_HEAD(&table->objects);
14971497
INIT_LIST_HEAD(&table->flowtables);
1498-
write_pnet(&table->net, net);
14991498
table->family = family;
15001499
table->flags = flags;
15011500
table->handle = ++nft_net->table_handle;
@@ -3869,8 +3868,11 @@ void nf_tables_rule_destroy(const struct nft_ctx *ctx, struct nft_rule *rule)
38693868
kfree(rule);
38703869
}
38713870

3871+
/* can only be used if rule is no longer visible to dumps */
38723872
static void nf_tables_rule_release(const struct nft_ctx *ctx, struct nft_rule *rule)
38733873
{
3874+
lockdep_commit_lock_is_held(ctx->net);
3875+
38743876
nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_RELEASE);
38753877
nf_tables_rule_destroy(ctx, rule);
38763878
}
@@ -5635,6 +5637,8 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
56355637
struct nft_set_binding *binding,
56365638
enum nft_trans_phase phase)
56375639
{
5640+
lockdep_commit_lock_is_held(ctx->net);
5641+
56385642
switch (phase) {
56395643
case NFT_TRANS_PREPARE_ERROR:
56405644
nft_set_trans_unbind(ctx, set);
@@ -11442,19 +11446,6 @@ static void __nft_release_basechain_now(struct nft_ctx *ctx)
1144211446
nf_tables_chain_destroy(ctx->chain);
1144311447
}
1144411448

11445-
static void nft_release_basechain_rcu(struct rcu_head *head)
11446-
{
11447-
struct nft_chain *chain = container_of(head, struct nft_chain, rcu_head);
11448-
struct nft_ctx ctx = {
11449-
.family = chain->table->family,
11450-
.chain = chain,
11451-
.net = read_pnet(&chain->table->net),
11452-
};
11453-
11454-
__nft_release_basechain_now(&ctx);
11455-
put_net(ctx.net);
11456-
}
11457-
1145811449
int __nft_release_basechain(struct nft_ctx *ctx)
1145911450
{
1146011451
struct nft_rule *rule;
@@ -11469,11 +11460,18 @@ int __nft_release_basechain(struct nft_ctx *ctx)
1146911460
nft_chain_del(ctx->chain);
1147011461
nft_use_dec(&ctx->table->use);
1147111462

11472-
if (maybe_get_net(ctx->net))
11473-
call_rcu(&ctx->chain->rcu_head, nft_release_basechain_rcu);
11474-
else
11463+
if (!maybe_get_net(ctx->net)) {
1147511464
__nft_release_basechain_now(ctx);
11465+
return 0;
11466+
}
11467+
11468+
/* wait for ruleset dumps to complete. Owning chain is no longer in
11469+
* lists, so new dumps can't find any of these rules anymore.
11470+
*/
11471+
synchronize_rcu();
1147611472

11473+
__nft_release_basechain_now(ctx);
11474+
put_net(ctx->net);
1147711475
return 0;
1147811476
}
1147911477
EXPORT_SYMBOL_GPL(__nft_release_basechain);

0 commit comments

Comments
 (0)