From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: [libnftnl PATCH 6/6] expr: Enforce attr_policy compliance in nftnl_expr_set()
Date: Fri, 15 Dec 2023 22:53:50 +0100 [thread overview]
Message-ID: <20231215215350.17691-7-phil@nwl.cc> (raw)
In-Reply-To: <20231215215350.17691-1-phil@nwl.cc>
Every expression type defines an attr_policy array, so deny setting
attributes if not present. Also deny if maxlen field is non-zero and
lower than the given data_len.
Some attributes' max length is not fixed (e.g. NFTNL_EXPR_{TG,MT}_INFO )
or is not sensible to check (e.g. NFTNL_EXPR_DYNSET_EXPR). The zero
maxlen "nop" is also used for deprecated attributes, just to not
silently ignore them.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/expr.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/expr.c b/src/expr.c
index 74d211bcaa123..4e32189c6e8d0 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -74,6 +74,13 @@ int nftnl_expr_set(struct nftnl_expr *expr, uint16_t type,
if (type < NFTNL_EXPR_BASE || type > expr->ops->nftnl_max_attr)
return -1;
+ if (!expr->ops->attr_policy)
+ return -1;
+
+ if (expr->ops->attr_policy[type].maxlen &&
+ expr->ops->attr_policy[type].maxlen < data_len)
+ return -1;
+
if (expr->ops->set(expr, type, data, data_len) < 0)
return -1;
}
--
2.43.0
next prev parent reply other threads:[~2023-12-15 21:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 21:53 [libnftnl PATCH 0/6] Attribute policies for expressions Phil Sutter
2023-12-15 21:53 ` [libnftnl PATCH 1/6] tests: Fix objref test case Phil Sutter
2023-12-15 21:53 ` [libnftnl PATCH 2/6] expr: Repurpose struct expr_ops::max_attr field Phil Sutter
2023-12-15 21:53 ` [libnftnl PATCH 3/6] expr: Call expr_ops::set with legal types only Phil Sutter
2023-12-15 21:53 ` [libnftnl PATCH 4/6] include: Sync nf_log.h with kernel headers Phil Sutter
2023-12-15 21:53 ` [libnftnl PATCH 5/6] expr: Introduce struct expr_ops::attr_policy Phil Sutter
2023-12-15 21:53 ` Phil Sutter [this message]
2024-03-06 14:43 ` [libnftnl PATCH 0/6] Attribute policies for expressions 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=20231215215350.17691-7-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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).