From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: phil@nwl.cc, fw@strlen.de
Subject: [PATCH] netfilter: nf_tables: restrict expression reduction to first expression
Date: Wed, 18 May 2022 12:08:42 +0200 [thread overview]
Message-ID: <20220518100842.1950-1-pablo@netfilter.org> (raw)
Either userspace or kernelspace need to pre-fetch keys inconditionally
before comparisons for this to work. Otherwise, register tracking data
is misleading and it might result in reducing expressions which are not
yet registers.
First expression is guaranteed to be evaluated always, therefore, keep
tracking registers and restrict reduction to first expression.
Fixes: b2d306542ff9 ("netfilter: nf_tables: do not reduce read-only expressions")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
@Phil, you mentioned about a way to simplify this patch, I don't see how,
just let me know.
net/netfilter/nf_tables_api.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 16c3a39689f4..2c82fecc4094 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -8362,6 +8362,7 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
void *data, *data_boundary;
struct nft_rule_dp *prule;
struct nft_rule *rule;
+ bool reduce;
/* already handled or inactive chain? */
if (chain->blob_next || !nft_is_active_next(net, chain))
@@ -8398,12 +8399,18 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
size = 0;
track.last = nft_expr_last(rule);
+ reduce = true;
nft_rule_for_each_expr(expr, last, rule) {
track.cur = expr;
if (nft_expr_reduce(&track, expr)) {
- expr = track.cur;
- continue;
+ if (reduce) {
+ reduce = false;
+ expr = track.cur;
+ continue;
+ }
+ } else if (reduce) {
+ reduce = false;
}
if (WARN_ON_ONCE(data + expr->ops->size > data_boundary))
--
2.30.2
next reply other threads:[~2022-05-18 10:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 10:08 Pablo Neira Ayuso [this message]
2022-05-18 10:51 ` [PATCH] netfilter: nf_tables: restrict expression reduction to first expression Phil Sutter
2022-05-18 11:01 ` Pablo Neira Ayuso
2022-05-18 11:40 ` Phil Sutter
2022-05-18 11:48 ` Florian Westphal
2022-05-18 12:26 ` Pablo Neira Ayuso
2022-05-18 12:38 ` Florian Westphal
2022-05-18 12:49 ` Pablo Neira Ayuso
2022-05-18 12:21 ` Pablo Neira Ayuso
2022-05-18 12:33 ` Pablo Neira Ayuso
2022-05-18 12:43 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220518100842.1950-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).