Skip to content

Commit cf5fb87

Browse files
ummakynesFlorian Westphal
authored andcommitted
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+ kernel-patches#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 <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent c0a23bb commit cf5fb87

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
28032803
struct nft_chain *chain = ctx->chain;
28042804
struct nft_chain_hook hook = {};
28052805
struct nft_stats __percpu *stats = NULL;
2806+
struct nftables_pernet *nft_net;
28062807
struct nft_hook *h, *next;
28072808
struct nf_hook_ops *ops;
28082809
struct nft_trans *trans;
@@ -2845,6 +2846,20 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
28452846
if (nft_hook_list_find(&basechain->hook_list, h)) {
28462847
list_del(&h->list);
28472848
nft_netdev_hook_free(h);
2849+
continue;
2850+
}
2851+
2852+
nft_net = nft_pernet(ctx->net);
2853+
list_for_each_entry(trans, &nft_net->commit_list, list) {
2854+
if (trans->msg_type != NFT_MSG_NEWCHAIN ||
2855+
trans->table != ctx->table ||
2856+
!nft_trans_chain_update(trans))
2857+
continue;
2858+
2859+
if (nft_hook_list_find(&nft_trans_chain_hooks(trans), h)) {
2860+
nft_chain_release_hook(&hook);
2861+
return -EEXIST;
2862+
}
28482863
}
28492864
}
28502865
} else {
@@ -9060,6 +9075,7 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
90609075
{
90619076
const struct nlattr * const *nla = ctx->nla;
90629077
struct nft_flowtable_hook flowtable_hook;
9078+
struct nftables_pernet *nft_net;
90639079
struct nft_hook *hook, *next;
90649080
struct nf_hook_ops *ops;
90659081
struct nft_trans *trans;
@@ -9076,6 +9092,20 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
90769092
if (nft_hook_list_find(&flowtable->hook_list, hook)) {
90779093
list_del(&hook->list);
90789094
nft_netdev_hook_free(hook);
9095+
continue;
9096+
}
9097+
9098+
nft_net = nft_pernet(ctx->net);
9099+
list_for_each_entry(trans, &nft_net->commit_list, list) {
9100+
if (trans->msg_type != NFT_MSG_NEWFLOWTABLE ||
9101+
trans->table != ctx->table ||
9102+
!nft_trans_flowtable_update(trans))
9103+
continue;
9104+
9105+
if (nft_hook_list_find(&nft_trans_flowtable_hooks(trans), hook)) {
9106+
err = -EEXIST;
9107+
goto err_flowtable_update_hook;
9108+
}
90799109
}
90809110
}
90819111

0 commit comments

Comments
 (0)