Skip to content

Commit

Permalink
netfilter: nf_tables: reject table flag and netdev basechain updates
Browse files Browse the repository at this point in the history
jira VULN-5118
subsystem-sync netfilter:nf_tables 4.18.0-553.16.1
commit-author Pablo Neira Ayuso <[email protected]>
commit 1e1fb6f
upstream-diff The upstream diff brings in cruft we don't want, and will
be superseded by the next commit but is here to maintain history.

netdev basechain updates are stored in the transaction object hook list.
When setting on the table dormant flag, it iterates over the existing
hooks in the basechain. Thus, skipping the hooks that are being
added/deleted in this transaction, which leaves hook registration in
inconsistent state.

Reject table flag updates in combination with netdev basechain updates
in the same batch:

- Update table flags and add/delete basechain: Check from basechain update
  path if there are pending flag updates for this table.
- add/delete basechain and update table flags: Iterate over the transaction
  list to search for basechain updates from the table update path.

In both cases, the batch is rejected. Based on suggestion from Florian Westphal.

Fixes: b9703ed ("netfilter: nf_tables: support for adding new devices to an existing netdev chain")
Fixes: 7d937b1 ("netfilter: nf_tables: support for deleting devices in an existing netdev chain")
	Signed-off-by: Pablo Neira Ayuso <[email protected]>
(cherry picked from commit 1e1fb6f)
	Signed-off-by: Greg Rose <[email protected]>

Conflicts:
	net/netfilter/nf_tables_api.c
  • Loading branch information
gvrose8192 committed Nov 14, 2024
1 parent 4ac43de commit 9fe6c5a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,24 @@ static void nf_tables_table_disable(struct net *net, struct nft_table *table)
#define __NFT_TABLE_F_UPDATE (__NFT_TABLE_F_WAS_DORMANT | \
__NFT_TABLE_F_WAS_AWAKEN)

static bool nft_table_pending_update(const struct nft_ctx *ctx)
{
struct nft_trans *trans;

if (ctx->table->flags & __NFT_TABLE_F_UPDATE)
return true;

list_for_each_entry(trans, &ctx->net->nft.commit_list, list) {
if ((trans->msg_type == NFT_MSG_NEWCHAIN ||
trans->msg_type == NFT_MSG_DELCHAIN) &&
trans->ctx.table == ctx->table &&
nft_trans_chain_update(trans))
return true;
}

return false;
}

static int nf_tables_updtable(struct nft_ctx *ctx)
{
struct nft_trans *trans;
Expand All @@ -971,7 +989,7 @@ static int nf_tables_updtable(struct nft_ctx *ctx)
return 0;

/* No dormant off/on/off/on games in single transaction */
if (ctx->table->flags & __NFT_TABLE_F_UPDATE)
if (nft_table_pending_update(ctx))
return -EINVAL;

trans = nft_trans_alloc(ctx, NFT_MSG_NEWTABLE,
Expand Down

0 comments on commit 9fe6c5a

Please sign in to comment.