From: Jakub Kicinski <kuba@kernel.org>
To: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Donald Hunter <donald.hunter@gmail.com>,
Simon Horman <horms@kernel.org>,
Jacob Keller <jacob.e.keller@intel.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
wireguard@lists.zx2c4.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 06/11] tools: ynl-gen: don't validate nested array attribute types
Date: Sat, 6 Sep 2025 12:29:38 -0700 [thread overview]
Message-ID: <20250906122938.30566de3@kernel.org> (raw)
In-Reply-To: <0a9a7c41-7deb-4078-8cc9-aee8f8784443@fiberby.net>
On Sat, 6 Sep 2025 13:22:01 +0000 Asbjørn Sloth Tønnesen wrote:
> > I don't understand, please provide more details.
> > This is an ArrayNest, right?
> >
> > [ARRAY-ATTR]
> > [ENTRY]
> > [MEMBER1]
> > [MEMBER2]
> > [ENTRY]
> > [MEMBER1]
> > [MEMBER2]
> >
> > Which level are you saying doesn't matter?
> > If entry is a nest it must be a valid nest.
> > What the comment you're quoting is saying is that the nla_type of ENTRY
> > doesn't matter.
>
> I will expand this in v2, but the gist of it is that this is part of the
> "split attribute counting, and later allocating an array to hold them" code.
>
> The check that I remove for nested arrays, is an early exit during the
> counting phase. Later in the allocation and parse phase it validates the
> nested payload.
>
> In include/uapi/linux/wireguard.h:
> > WGDEVICE_A_PEERS: NLA_NESTED
> > 0: NLA_NESTED
> > WGPEER_A_PUBLIC_KEY: NLA_EXACT_LEN, len WG_KEY_LEN
> > [..]
> > 0: NLA_NESTED
> > ...
> > ...
>
> The current check requires that the nested type is valid in the nested
> attribute set, which in this case resolves to WGDEVICE_A_UNSPEC, which is
> YNL_PT_REJECT, and it takes the early exit and returns YNL_PARSE_CB_ERROR.
I see your point now. We're validating ENTRY as an attribute in the
parent attribute set, but it's just a meaningless id.
I think we need more fixing here. The real parsing loop will only
validate what's _inside_ the [MEMBER]. Which doesn't matter all
that much to nests, but look at what happens if subtype is a scalar.
We'll just call ynl_attr_get_u32(), type is never really validate.
I think we need this, and make the codegen feed in the ARRAY-ATTR type
to validate ENTRY?
diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c
index 2a169c3c0797..e43167398c69 100644
--- a/tools/net/ynl/lib/ynl.c
+++ b/tools/net/ynl/lib/ynl.c
@@ -360,15 +360,15 @@ static int ynl_cb_done(const struct nlmsghdr *nlh, struct ynl_parse_arg *yarg)
/* Attribute validation */
-int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
+int __ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr,
+ unsigned int type)
{
const struct ynl_policy_attr *policy;
- unsigned int type, len;
unsigned char *data;
+ unsigned int len;
data = ynl_attr_data(attr);
len = ynl_attr_data_len(attr);
- type = ynl_attr_type(attr);
if (type > yarg->rsp_policy->max_attr) {
yerr(yarg->ys, YNL_ERROR_INTERNAL,
"Internal error, validating unknown attribute");
@@ -450,6 +450,11 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
return 0;
}
+int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
+{
+ return __ynl_attr_validate(yarg, attr, ynl_attr_type(attr));
+}
+
int ynl_submsg_failed(struct ynl_parse_arg *yarg, const char *field_name,
const char *sel_name)
{
next prev parent reply other threads:[~2025-09-06 19:29 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 22:01 [PATCH net-next 00/11] tools: ynl: prepare for wireguard Asbjørn Sloth Tønnesen
2025-09-04 22:01 ` [PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants Asbjørn Sloth Tønnesen
2025-09-05 10:36 ` Donald Hunter
2025-09-06 0:07 ` Jakub Kicinski
2025-09-06 0:15 ` Jacob Keller
2025-09-04 22:01 ` [PATCH net-next 02/11] tools: ynl-gen: generate nested array policies Asbjørn Sloth Tønnesen
2025-09-05 10:37 ` Donald Hunter
2025-09-06 0:09 ` Jakub Kicinski
2025-09-06 0:19 ` Jacob Keller
2025-09-06 14:13 ` Asbjørn Sloth Tønnesen
2025-09-08 7:54 ` Johannes Berg
2025-09-08 9:08 ` Asbjørn Sloth Tønnesen
2025-09-08 13:22 ` Johannes Berg
2025-09-09 23:02 ` Jacob Keller
2025-09-04 22:01 ` [PATCH net-next 03/11] tools: ynl-gen: add sub-type check Asbjørn Sloth Tønnesen
2025-09-05 10:37 ` Donald Hunter
2025-09-06 0:12 ` Jakub Kicinski
2025-09-06 0:20 ` Jacob Keller
2025-09-04 22:01 ` [PATCH net-next 04/11] tools: ynl-gen: define count iterator in print_dump() Asbjørn Sloth Tønnesen
2025-09-05 10:37 ` Donald Hunter
2025-09-06 0:13 ` Jakub Kicinski
2025-09-06 0:20 ` Jacob Keller
2025-09-04 22:01 ` [PATCH net-next 05/11] tools: ynl-gen: define nlattr *array in a block scope Asbjørn Sloth Tønnesen
2025-09-05 10:44 ` Donald Hunter
2025-09-06 0:18 ` Jakub Kicinski
2025-09-06 13:13 ` Asbjørn Sloth Tønnesen
2025-09-06 19:07 ` Jakub Kicinski
2025-09-11 0:01 ` Asbjørn Sloth Tønnesen
2025-09-11 0:27 ` Jakub Kicinski
2025-09-04 22:01 ` [PATCH net-next 06/11] tools: ynl-gen: don't validate nested array attribute types Asbjørn Sloth Tønnesen
2025-09-06 0:23 ` Jakub Kicinski
2025-09-06 13:22 ` Asbjørn Sloth Tønnesen
2025-09-06 19:29 ` Jakub Kicinski [this message]
2025-09-06 0:24 ` Jacob Keller
2025-09-06 15:10 ` Asbjørn Sloth Tønnesen
2025-09-08 7:55 ` Johannes Berg
2025-09-10 16:58 ` Jacob Keller
2025-09-04 22:01 ` [PATCH net-next 07/11] tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray Asbjørn Sloth Tønnesen
2025-09-05 10:44 ` Donald Hunter
2025-09-06 0:25 ` Jakub Kicinski
2025-09-04 22:01 ` [PATCH net-next 08/11] tools: ynl: move nest packing to a helper function Asbjørn Sloth Tønnesen
2025-09-05 10:45 ` Donald Hunter
2025-09-04 22:01 ` [PATCH net-next 09/11] tools: ynl: encode indexed-array Asbjørn Sloth Tønnesen
2025-09-05 10:49 ` Donald Hunter
2025-09-05 15:34 ` Asbjørn Sloth Tønnesen
2025-09-04 22:01 ` [PATCH net-next 10/11] tools: ynl: decode hex input Asbjørn Sloth Tønnesen
2025-09-05 10:51 ` Donald Hunter
2025-09-06 0:27 ` Jacob Keller
2025-09-06 14:31 ` Asbjørn Sloth Tønnesen
2025-09-08 8:28 ` Donald Hunter
2025-09-09 18:10 ` Sabrina Dubroca
2025-09-09 20:18 ` Asbjørn Sloth Tønnesen
2025-09-04 22:01 ` [PATCH net-next 11/11] tools: ynl: add ipv4-or-v6 display hint Asbjørn Sloth Tønnesen
2025-09-05 10:53 ` Donald Hunter
2025-09-06 15:59 ` Asbjørn Sloth Tønnesen
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=20250906122938.30566de3@kernel.org \
--to=kuba@kernel.org \
--cc=Jason@zx2c4.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@fiberby.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wireguard@lists.zx2c4.com \
/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).