Skip to content

netfilter: nf_tables: fix chain binding transaction logic

Phil Sutter requested to merge psutter1/centos-stream-9:c9s/bz2225459 into main

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2225459 Upstream Status: commit 4bedf9eee0162 CVE: CVE-2023-3610

commit 4bedf9eee016286c835e3d8fa981ddece5338795 Author: Pablo Neira Ayuso pablo@netfilter.org Date: Fri Jun 16 14:45:22 2023 +0200

netfilter: nf_tables: fix chain binding transaction logic

Add bound flag to rule and chain transactions as in 6a0a8d10a366
("netfilter: nf_tables: use-after-free in failing rule with bound set")
to skip them in case that the chain is already bound from the abort
path.

This patch fixes an imbalance in the chain use refcnt that triggers a
WARN_ON on the table and chain destroy path.

This patch also disallows nested chain bindings, which is not
supported from userspace.

The logic to deal with chain binding in nft_data_hold() and
nft_data_release() is not correct. The NFT_TRANS_PREPARE state needs a
special handling in case a chain is bound but next expressions in the
same rule fail to initialize as described by 1240eb93f061 ("netfilter:
nf_tables: incorrect error path handling with NFT_MSG_NEWRULE").

The chain is left bound if rule construction fails, so the objects
stored in this chain (and the chain itself) are released by the
transaction records from the abort path, follow up patch ("netfilter:
nf_tables: add NFT_TRANS_PREPARE_ERROR to deal with bound set/chain")
completes this error handling.

When deleting an existing rule, chain bound flag is set off so the
rule expression .destroy path releases the objects.

Fixes: d0e2c7de92c7 ("netfilter: nf_tables: add NFT_CHAIN_BINDING")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Phil Sutter psutter@redhat.com

Edited by Phil Sutter

Merge request reports