Skip to content

Commit

Permalink
netfilter: nf_tables: disallow rule removal from chain binding
Browse files Browse the repository at this point in the history
[ Upstream commit f15f29f ]

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: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ummakynes authored and gregkh committed Oct 6, 2023
1 parent 980663f commit 9af8bb2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,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;
Expand Down Expand Up @@ -1471,7 +1471,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;
Expand Down Expand Up @@ -2792,6 +2792,9 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
return PTR_ERR(chain);
}

if (nft_chain_binding(chain))
return -EOPNOTSUPP;

if (info->nlh->nlmsg_flags & NLM_F_NONREC &&
chain->use > 0)
return -EBUSY;
Expand Down Expand Up @@ -3771,6 +3774,11 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
}

if (info->nlh->nlmsg_flags & NLM_F_REPLACE) {
if (nft_chain_binding(chain)) {
err = -EOPNOTSUPP;
goto err_destroy_flow_rule;
}

err = nft_delrule(&ctx, old_rule);
if (err < 0)
goto err_destroy_flow_rule;
Expand Down Expand Up @@ -3874,7 +3882,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
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;
}

Expand Down Expand Up @@ -3904,7 +3912,7 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
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;
Expand Down Expand Up @@ -10664,7 +10672,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;
Expand Down

0 comments on commit 9af8bb2

Please sign in to comment.