Skip to content

Commit 29530d2

Browse files
committed
netfilter: nf_tables: disallow rule removal from chain binding
JIRA: https://issues.redhat.com/browse/RHEL-1720 JIRA: https://issues.redhat.com/browse/RHEL-1721 Upstream Status: commit f15f29f Conflicts: cs9 lacks commit 7d937b1 ("netfilter: nf_tables: support for deleting devices in an existing netdev chain"), adjust context. commit f15f29f Author: Pablo Neira Ayuso <pablo@netfilter.org> Date: Thu Sep 7 08:22:33 2023 +0200 netfilter: nf_tables: disallow rule removal from chain binding Chain binding only requires the rule addition/insertion command within the same transaction. Removal of rules from chain bindings within the same transaction makes no sense, userspace does not utilize this feature. Replace nft_chain_is_bound() check to nft_chain_binding() in rule deletion commands. Replace command implies a rule deletion, reject this command too. Rule flush command can also safely rely on this nft_chain_binding() check because unbound chains are not allowed since 62e1e94 ("netfilter: nf_tables: reject unbound chain set before commit phase"). Fixes: d0e2c7d ("netfilter: nf_tables: add NFT_CHAIN_BINDING") Reported-by: Kevin Rich <kevinrich1337@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent e33bf66 commit 29530d2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
13441344
if (!nft_is_active_next(ctx->net, chain))
13451345
continue;
13461346

1347-
if (nft_chain_is_bound(chain))
1347+
if (nft_chain_binding(chain))
13481348
continue;
13491349

13501350
ctx->chain = chain;
@@ -1389,7 +1389,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
13891389
if (!nft_is_active_next(ctx->net, chain))
13901390
continue;
13911391

1392-
if (nft_chain_is_bound(chain))
1392+
if (nft_chain_binding(chain))
13931393
continue;
13941394

13951395
ctx->chain = chain;
@@ -2706,6 +2706,9 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
27062706
return PTR_ERR(chain);
27072707
}
27082708

2709+
if (nft_chain_binding(chain))
2710+
return -EOPNOTSUPP;
2711+
27092712
if (info->nlh->nlmsg_flags & NLM_F_NONREC &&
27102713
chain->use > 0)
27112714
return -EBUSY;
@@ -3696,6 +3699,11 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
36963699
}
36973700

36983701
if (info->nlh->nlmsg_flags & NLM_F_REPLACE) {
3702+
if (nft_chain_binding(chain)) {
3703+
err = -EOPNOTSUPP;
3704+
goto err_destroy_flow_rule;
3705+
}
3706+
36993707
err = nft_delrule(&ctx, old_rule);
37003708
if (err < 0)
37013709
goto err_destroy_flow_rule;
@@ -3803,7 +3811,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
38033811
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
38043812
return PTR_ERR(chain);
38053813
}
3806-
if (nft_chain_is_bound(chain))
3814+
if (nft_chain_binding(chain))
38073815
return -EOPNOTSUPP;
38083816
}
38093817

@@ -3837,7 +3845,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
38373845
list_for_each_entry(chain, &table->chains, list) {
38383846
if (!nft_is_active_next(net, chain))
38393847
continue;
3840-
if (nft_chain_is_bound(chain))
3848+
if (nft_chain_binding(chain))
38413849
continue;
38423850

38433851
ctx.chain = chain;
@@ -10640,7 +10648,7 @@ static void __nft_release_table(struct net *net, struct nft_table *table)
1064010648
ctx.family = table->family;
1064110649
ctx.table = table;
1064210650
list_for_each_entry(chain, &table->chains, list) {
10643-
if (nft_chain_is_bound(chain))
10651+
if (nft_chain_binding(chain))
1064410652
continue;
1064510653

1064610654
ctx.chain = chain;

0 commit comments

Comments
 (0)