UPSTREAM: netfilter: nf_tables: disallow rule removal from chain binding
[ Upstream commit f15f29fd4779be8a418b66e9d52979bb6d6c2325 ] 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 62e1e94b246e ("netfilter: nf_tables: reject unbound chain set before commit phase"). Bug: 302085977 Fixes:d0e2c7de92
("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: Sasha Levin <sashal@kernel.org> (cherry picked from commit5a03b42ae1
) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I8b05dc37062824db4c2901000fdf701b38605d32
This commit is contained in:
parent
6cd0cd3893
commit
cd7744312f
@ -1252,7 +1252,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
|
||||
if (!nft_is_active_next(ctx->net, chain))
|
||||
continue;
|
||||
|
||||
if (nft_chain_is_bound(chain))
|
||||
if (nft_chain_binding(chain))
|
||||
continue;
|
||||
|
||||
ctx->chain = chain;
|
||||
@ -1297,7 +1297,7 @@ static int nft_flush_table(struct nft_ctx *ctx)
|
||||
if (!nft_is_active_next(ctx->net, chain))
|
||||
continue;
|
||||
|
||||
if (nft_chain_is_bound(chain))
|
||||
if (nft_chain_binding(chain))
|
||||
continue;
|
||||
|
||||
ctx->chain = chain;
|
||||
@ -2584,6 +2584,9 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk,
|
||||
return PTR_ERR(chain);
|
||||
}
|
||||
|
||||
if (nft_chain_binding(chain))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (nlh->nlmsg_flags & NLM_F_NONREC &&
|
||||
chain->use > 0)
|
||||
return -EBUSY;
|
||||
@ -3483,6 +3486,11 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
|
||||
}
|
||||
|
||||
if (nlh->nlmsg_flags & NLM_F_REPLACE) {
|
||||
if (nft_chain_binding(chain)) {
|
||||
err = -EOPNOTSUPP;
|
||||
goto err_destroy_flow_rule;
|
||||
}
|
||||
|
||||
trans = nft_trans_rule_add(&ctx, NFT_MSG_NEWRULE, rule);
|
||||
if (trans == NULL) {
|
||||
err = -ENOMEM;
|
||||
@ -3591,7 +3599,7 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk,
|
||||
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
|
||||
return PTR_ERR(chain);
|
||||
}
|
||||
if (nft_chain_is_bound(chain))
|
||||
if (nft_chain_binding(chain))
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
@ -3621,7 +3629,7 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk,
|
||||
list_for_each_entry(chain, &table->chains, list) {
|
||||
if (!nft_is_active_next(net, chain))
|
||||
continue;
|
||||
if (nft_chain_is_bound(chain))
|
||||
if (nft_chain_binding(chain))
|
||||
continue;
|
||||
|
||||
ctx.chain = chain;
|
||||
@ -9227,7 +9235,7 @@ static void __nft_release_table(struct net *net, struct nft_table *table)
|
||||
ctx.family = table->family;
|
||||
ctx.table = table;
|
||||
list_for_each_entry(chain, &table->chains, list) {
|
||||
if (nft_chain_is_bound(chain))
|
||||
if (nft_chain_binding(chain))
|
||||
continue;
|
||||
|
||||
ctx.chain = chain;
|
||||
|
Loading…
Reference in New Issue
Block a user