Commit 5afcd3b6 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso Committed by Liu Jian
Browse files

netfilter: nf_tables: discard table flag update with pending basechain deletion

stable inclusion
from stable-v5.10.215
commit b58d0ac35f6d75ec1db8650a29dfd6f292c11362
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9QG9F
CVE: CVE-2024-35897

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b58d0ac35f6d75ec1db8650a29dfd6f292c11362



---------------------------

commit 1bc83a019bbe268be3526406245ec28c2458a518 upstream.

Hook unregistration is deferred to the commit phase, same occurs with
hook updates triggered by the table dormant flag. When both commands are
combined, this results in deleting a basechain while leaving its hook
still registered in the core.

Fixes: 179d9ba5 ("netfilter: nf_tables: fix table flag updates")
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
parent 80a0681e
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -1084,6 +1084,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 nftables_pernet *nft_net = net_generic(ctx->net, nf_tables_net_id);
	struct nft_trans *trans;

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

	list_for_each_entry(trans, &nft_net->commit_list, list) {
		if (trans->ctx.table == ctx->table &&
		    trans->msg_type == NFT_MSG_DELCHAIN &&
		    nft_is_base_chain(trans->ctx.chain))
			return true;
	}

	return false;
}

static int nf_tables_updtable(struct nft_ctx *ctx)
{
	struct nft_trans *trans;
@@ -1101,7 +1119,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,