From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: netdev@vger.kernel.org
Subject: Re: [RFC] netlink: limit recursion depth in policy validation
Date: Fri, 26 Apr 2019 19:06:49 +0200 [thread overview]
Message-ID: <20190426170649.5aa6b64464zmeeze@salvia> (raw)
In-Reply-To: <7be848796a1f5552e611e131c8613408c128bfc8.camel@sipsolutions.net>
On Fri, Apr 26, 2019 at 07:03:10PM +0200, Johannes Berg wrote:
> On Fri, 2019-04-26 at 18:57 +0200, Pablo Neira Ayuso wrote:
> >
> > > +/*
> > > + * Nested policies might refer back to the original
> > > + * policy in some cases, and userspace could try to
> > > + * abuse that and recurse by nesting in the right
> > > + * ways. Limit recursion to avoid this problem.
> > > + */
> > > +#define MAX_POLICY_RECURSION_DEPTH 10
> >
> > In your policy description approach, you iterate over the policy
> > structures. How do you deal with this recursions from there?
>
> Well, check out the code :-)
>
> It doesn't actually recurse. What it does is build a list of policies
> that are reachable from the root policy and each policy in the list. So
> basically, there we do:
>
> list = [root policy]
> list_len = 1
> i = 0
>
> walk_policy(policy)
> {
> for_each_policy_entry(entry, policy) {
> nested = nested_policy_or_null(entry);
> if (nested) {
> list[i] = nested;
> list_len += 1
> }
> }
> }
>
> while (i < list_len) {
> walk_policy(list[i]);
> i++;
> }
>
> Then, we walk the list again:
>
> for (i = 0; i < list_len; i++) {
> for_each_policy_entry(entry, list[i]) {
> send_entry_to_userspace(i, entry); // mark it as occurring in policy i
> }
> }
>
>
> This basically flattens the whole thing.
>
> Obviously, the walking may allocate some memory, and the last loop to
> send it out isn't actually a loop like that because it's a netlink dump
> with each entry being in a separate netlink message, but that's the gist
> of it.
I see, following this approach, I can just remove the duplicated code
in my netlink description stuff by using the list of policy
structures.
next prev parent reply other threads:[~2019-04-26 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 21:24 [RFC] netlink: limit recursion depth in policy validation Johannes Berg
2019-04-26 16:57 ` Pablo Neira Ayuso
2019-04-26 17:03 ` Johannes Berg
2019-04-26 17:06 ` Pablo Neira Ayuso [this message]
2019-04-26 17:08 ` 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=20190426170649.5aa6b64464zmeeze@salvia \
--to=pablo@netfilter.org \
--cc=johannes@sipsolutions.net \
--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