Skip to content

Commit bda6132

Browse files
committed
netfilter: nf_tables: reject duplicate device on updates
JIRA: https://issues.redhat.com/browse/RHEL-115630 Upstream Status: commit cf5fb87 CS9 lacks b9703ed ("netfilter: nf_tables: support for adding new devices to an existing netdev chain"). Associated hunks are discarded. commit cf5fb87 Author: Pablo Neira Ayuso <pablo@netfilter.org> Date: Wed Aug 13 02:38:50 2025 +0200 netfilter: nf_tables: reject duplicate device on updates A chain/flowtable update with duplicated devices in the same batch is possible. Unfortunately, netdev event path only removes the first device that is found, leaving unregistered the hook of the duplicated device. Check if a duplicated device exists in the transaction batch, bail out with EEXIST in such case. WARNING is hit when unregistering the hook: [49042.221275] WARNING: CPU: 4 PID: 8425 at net/netfilter/core.c:340 nf_hook_entry_head+0xaa/0x150 [49042.221375] CPU: 4 UID: 0 PID: 8425 Comm: nft Tainted: G S 6.16.0+ #170 PREEMPT(full) [...] [49042.221382] RIP: 0010:nf_hook_entry_head+0xaa/0x150 Fixes: 78d9f48 ("netfilter: nf_tables: add devices to existing flowtable") Fixes: b9703ed ("netfilter: nf_tables: support for adding new devices to an existing netdev chain") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent 9097580 commit bda6132

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8211,6 +8211,7 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
82118211
{
82128212
const struct nlattr * const *nla = ctx->nla;
82138213
struct nft_flowtable_hook flowtable_hook;
8214+
struct nftables_pernet *nft_net;
82148215
struct nft_hook *hook, *next;
82158216
struct nft_trans *trans;
82168217
bool unregister = false;
@@ -8226,6 +8227,20 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
82268227
if (nft_hook_list_find(&flowtable->hook_list, hook)) {
82278228
list_del(&hook->list);
82288229
kfree(hook);
8230+
continue;
8231+
}
8232+
8233+
nft_net = nft_pernet(ctx->net);
8234+
list_for_each_entry(trans, &nft_net->commit_list, list) {
8235+
if (trans->msg_type != NFT_MSG_NEWFLOWTABLE ||
8236+
trans->ctx.table != ctx->table ||
8237+
!nft_trans_flowtable_update(trans))
8238+
continue;
8239+
8240+
if (nft_hook_list_find(&nft_trans_flowtable_hooks(trans), hook)) {
8241+
err = -EEXIST;
8242+
goto err_flowtable_update_hook;
8243+
}
82298244
}
82308245
}
82318246

0 commit comments

Comments
 (0)