Skip to content

Commit f15f29f

Browse files
committed
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>
1 parent 1b36955 commit f15f29f

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
@@ -1432,7 +1432,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
14321432
if (!nft_is_active_next(ctx->net, chain))
14331433
continue;
14341434

1435-
if (nft_chain_is_bound(chain))
1435+
if (nft_chain_binding(chain))
14361436
continue;
14371437

14381438
ctx->chain = chain;
@@ -1477,7 +1477,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
14771477
if (!nft_is_active_next(ctx->net, chain))
14781478
continue;
14791479

1480-
if (nft_chain_is_bound(chain))
1480+
if (nft_chain_binding(chain))
14811481
continue;
14821482

14831483
ctx->chain = chain;
@@ -2910,6 +2910,9 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
29102910
return PTR_ERR(chain);
29112911
}
29122912

2913+
if (nft_chain_binding(chain))
2914+
return -EOPNOTSUPP;
2915+
29132916
nft_ctx_init(&ctx, net, skb, info->nlh, family, table, chain, nla);
29142917

29152918
if (nla[NFTA_CHAIN_HOOK]) {
@@ -3971,6 +3974,11 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
39713974
}
39723975

39733976
if (info->nlh->nlmsg_flags & NLM_F_REPLACE) {
3977+
if (nft_chain_binding(chain)) {
3978+
err = -EOPNOTSUPP;
3979+
goto err_destroy_flow_rule;
3980+
}
3981+
39743982
err = nft_delrule(&ctx, old_rule);
39753983
if (err < 0)
39763984
goto err_destroy_flow_rule;
@@ -4078,7 +4086,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
40784086
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
40794087
return PTR_ERR(chain);
40804088
}
4081-
if (nft_chain_is_bound(chain))
4089+
if (nft_chain_binding(chain))
40824090
return -EOPNOTSUPP;
40834091
}
40844092

@@ -4112,7 +4120,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
41124120
list_for_each_entry(chain, &table->chains, list) {
41134121
if (!nft_is_active_next(net, chain))
41144122
continue;
4115-
if (nft_chain_is_bound(chain))
4123+
if (nft_chain_binding(chain))
41164124
continue;
41174125

41184126
ctx.chain = chain;
@@ -11054,7 +11062,7 @@ static void __nft_release_table(struct net *net, struct nft_table *table)
1105411062
ctx.family = table->family;
1105511063
ctx.table = table;
1105611064
list_for_each_entry(chain, &table->chains, list) {
11057-
if (nft_chain_is_bound(chain))
11065+
if (nft_chain_binding(chain))
1105811066
continue;
1105911067

1106011068
ctx.chain = chain;

0 commit comments

Comments
 (0)