Skip to content

Commit

Permalink
netfilter: nft_set_pipapo: call nft_trans_gc_queue_sync() in catchall GC
Browse files Browse the repository at this point in the history
commit 4a9e12e upstream.

pipapo needs to enqueue GC transactions for catchall elements through
nft_trans_gc_queue_sync(). Add nft_trans_gc_catchall_sync() and
nft_trans_gc_catchall_async() to handle GC transaction queueing
accordingly.

Fixes: 5f68718 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
Fixes: f6c383b ("netfilter: nf_tables: adapt set backend to use GC transaction API")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ummakynes authored and gregkh committed Oct 6, 2023
1 parent 92b4b4b commit 8c643a8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
5 changes: 3 additions & 2 deletions include/net/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -1675,8 +1675,9 @@ void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans);

void nft_trans_gc_elem_add(struct nft_trans_gc *gc, void *priv);

struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,
unsigned int gc_seq);
struct nft_trans_gc *nft_trans_gc_catchall_async(struct nft_trans_gc *gc,
unsigned int gc_seq);
struct nft_trans_gc *nft_trans_gc_catchall_sync(struct nft_trans_gc *gc);

void nft_setelem_data_deactivate(const struct net *net,
const struct nft_set *set,
Expand Down
22 changes: 19 additions & 3 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -9233,8 +9233,9 @@ void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans)
call_rcu(&trans->rcu, nft_trans_gc_trans_free);
}

struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,
unsigned int gc_seq)
static struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,
unsigned int gc_seq,
bool sync)
{
struct nft_set_elem_catchall *catchall;
const struct nft_set *set = gc->set;
Expand All @@ -9250,7 +9251,11 @@ struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,

nft_set_elem_dead(ext);
dead_elem:
gc = nft_trans_gc_queue_async(gc, gc_seq, GFP_ATOMIC);
if (sync)
gc = nft_trans_gc_queue_sync(gc, GFP_ATOMIC);
else
gc = nft_trans_gc_queue_async(gc, gc_seq, GFP_ATOMIC);

if (!gc)
return NULL;

Expand All @@ -9260,6 +9265,17 @@ struct nft_trans_gc *nft_trans_gc_catchall(struct nft_trans_gc *gc,
return gc;
}

struct nft_trans_gc *nft_trans_gc_catchall_async(struct nft_trans_gc *gc,
unsigned int gc_seq)
{
return nft_trans_gc_catchall(gc, gc_seq, false);
}

struct nft_trans_gc *nft_trans_gc_catchall_sync(struct nft_trans_gc *gc)
{
return nft_trans_gc_catchall(gc, 0, true);
}

static void nf_tables_module_autoload_cleanup(struct net *net)
{
struct nftables_pernet *nft_net = nft_pernet(net);
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nft_set_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ static void nft_rhash_gc(struct work_struct *work)
nft_trans_gc_elem_add(gc, he);
}

gc = nft_trans_gc_catchall(gc, gc_seq);
gc = nft_trans_gc_catchall_async(gc, gc_seq);

try_later:
/* catchall list iteration requires rcu read side lock. */
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nft_set_pipapo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ static void pipapo_gc(const struct nft_set *_set, struct nft_pipapo_match *m)
}
}

gc = nft_trans_gc_catchall(gc, 0);
gc = nft_trans_gc_catchall_sync(gc);
if (gc) {
nft_trans_gc_queue_sync_done(gc);
priv->last_gc = jiffies;
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nft_set_rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ static void nft_rbtree_gc(struct work_struct *work)
nft_trans_gc_elem_add(gc, rbe);
}

gc = nft_trans_gc_catchall(gc, gc_seq);
gc = nft_trans_gc_catchall_async(gc, gc_seq);

try_later:
read_unlock_bh(&priv->lock);
Expand Down

0 comments on commit 8c643a8

Please sign in to comment.