From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: David Ahern <dsahern@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH 5/7] netlink: prepare validate extack setting for recursion
Date: Wed, 19 Sep 2018 16:08:51 -0300 [thread overview]
Message-ID: <20180919190851.GM4590@localhost.localdomain> (raw)
In-Reply-To: <50773483-5732-8874-c5bf-99fa09d7e94a@gmail.com>
On Wed, Sep 19, 2018 at 09:44:37AM -0700, David Ahern wrote:
> On 9/19/18 9:36 AM, Johannes Berg wrote:
> > On Wed, 2018-09-19 at 09:28 -0700, David Ahern wrote:
> >> On 9/19/18 5:08 AM, Johannes Berg wrote:
> >>> diff --git a/lib/nlattr.c b/lib/nlattr.c
> >>> index 966cd3dcf31b..2b015e43b725 100644
> >>> --- a/lib/nlattr.c
> >>> +++ b/lib/nlattr.c
> >>> @@ -69,7 +69,7 @@ static int validate_nla_bitfield32(const struct nlattr *nla,
> >>>
> >>> static int validate_nla(const struct nlattr *nla, int maxtype,
> >>> const struct nla_policy *policy,
> >>> - const char **error_msg)
> >>> + struct netlink_ext_ack *extack, bool *extack_set)
> >>
> >> extack_set arg is not needed if you handle the "Attribute failed policy
> >> validation" message and NL_SET_BAD_ATTR here as well.
> >
> > I'm not sure that's true, but perhaps you have a better idea than me?
> >
> > My thought would be to introduce an "error" label in validate_nla(),
> > that sets up the extack data.
> >
> > Then we could skip over that if we have a separate message to report,
> > making the NLA_REJECT case easier.
> >
> > However, if we do nested validation, I'm not sure it really is that much
> > easier? We still need to figure out if the nested validation was setting
> > the message (and bad attr), rather than it having been set before we
> > even get into this function.
> >
> > So let's say we have
> >
> > case NLA_NESTED:
> > /* a nested attributes is allowed to be empty; if its not,
> > * it must have a size of at least NLA_HDRLEN.
> > */
> > if (attrlen == 0)
> > break;
> > if (attrlen < NLA_HDRLEN)
> > return -ERANGE;
> > if (pt->validation_data) {
> > int err;
> >
> > err = nla_validate_parse(nla_data(nla), nla_len(nla),
> > pt->len, pt->validation_data,
> > extack, extack_set, NULL);
> > if (err < 0)
> > return err;
> > }
> > break;
> >
> > right now after all the patches.
> >
> > The "return -ERANGE;" would become "{ err = -ERANGE; goto error; }", but
> > I'm not really sure we can cleanly handle the other case?
> >
> > Hmm. Maybe it works if we ensure that nla_validate_parse() has no other
> > return points that can fail outside of validate_nla(), or we set up the
> > extack data there as well, so that once we have a nested
> > nla_validate_parse() we know that it's been set.
> >
> > Actually, we need to do that anyway so that we can move the setting into
> > validate_nla(), and then it should work.
> >
> > Mechanics aside - I'll take a look later tonight or tomorrow - do you
> > think the goal/external interface of this makes sense?
>
> If it fails and returns (nested and all) on the first failure it should
> be fine. I was thinking something like this (whitespace damaged on paste):
This will avoid the situation that we were discussing in the older
thread, btw.
Marcelo
next prev parent reply other threads:[~2018-09-20 0:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-19 12:08 [PATCH 0/7] netlink recursive policy validation Johannes Berg
2018-09-19 12:08 ` [PATCH 1/7] netlink: remove NLA_NESTED_COMPAT Johannes Berg
2018-09-19 12:08 ` [PATCH 2/7] netlink: make validation_data const Johannes Berg
2018-09-19 16:21 ` David Ahern
2018-09-19 12:08 ` [PATCH 3/7] netlink: set extack error message in nla_validate() Johannes Berg
2018-09-19 16:20 ` David Ahern
2018-09-19 16:31 ` Johannes Berg
2018-09-19 12:08 ` [PATCH 4/7] netlink: combine validate/parse functions Johannes Berg
2018-09-19 12:08 ` [PATCH 5/7] netlink: prepare validate extack setting for recursion Johannes Berg
2018-09-19 16:28 ` David Ahern
2018-09-19 16:36 ` Johannes Berg
[not found] ` <1537374995.10305.47.camel-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>
2018-09-19 16:44 ` David Ahern
2018-09-19 19:08 ` Marcelo Ricardo Leitner [this message]
2018-09-19 19:09 ` Johannes Berg
2018-09-19 12:08 ` [PATCH 6/7] netlink: allow NLA_NESTED to specify nested policy to validate Johannes Berg
2018-09-19 12:09 ` [PATCH 7/7] netlink: add nested array policy validation Johannes Berg
2018-09-19 12:15 ` [PATCH 0/7] netlink recursive " Johannes Berg
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=20180919190851.GM4590@localhost.localdomain \
--to=marcelo.leitner@gmail.com \
--cc=dsahern@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.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).