lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CALCETrWT5u=dpRadn_dHosa0YEpC9j_-Gttu7qk1pOrN9XmfUA@mail.gmail.com>
Date:   Tue, 2 May 2017 09:36:40 -0700
From:   Andy Lutomirski <luto@...nel.org>
To:     Kirill Tkhai <ktkhai@...tuozzo.com>
Cc:     "Serge E. Hallyn" <serge@...lyn.com>,
        "Eric W. Biederman" <ebiederm@...ssion.com>,
        Andreas Gruenbacher <agruenba@...hat.com>,
        Greg KH <gregkh@...uxfoundation.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Oleg Nesterov <oleg@...hat.com>,
        Paul Moore <paul@...l-moore.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        Andrey Vagin <avagin@...nvz.org>,
        Linux API <linux-api@...r.kernel.org>,
        Linux FS Devel <linux-fsdevel@...r.kernel.org>,
        Michael Kerrisk <mtk.manpages@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Cyrill Gorcunov <gorcunov@...nvz.org>,
        Ingo Molnar <mingo@...nel.org>,
        Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH] security: Use user_namespace::level to avoid redundant
 iterations in cap_capable()

On Tue, May 2, 2017 at 5:40 AM, Kirill Tkhai <ktkhai@...tuozzo.com> wrote:
> When ns->level is not larger then cred->user_ns->level,
> then ns can't be cred->user_ns's descendant, and
> there is no a sence to search in parents.
>
> So, breake the cycle earlier and skip needless iterations.
>
> Signed-off-by: Kirill Tkhai <ktkhai@...tuozzo.com>
> ---
>  security/commoncap.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/security/commoncap.c b/security/commoncap.c
> index 78b37838a2d3..f6ef78208d2d 100644
> --- a/security/commoncap.c
> +++ b/security/commoncap.c
> @@ -82,8 +82,11 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
>                 if (ns == cred->user_ns)
>                         return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
>
> -               /* Have we tried all of the parent namespaces? */
> -               if (ns == &init_user_ns)
> +               /*
> +                * If ns can't be a descendant of cred->user_ns, then it's
> +                * needlessly to go up.
> +                */
> +               if (ns->level <= cred->user_ns->level)
>                         return -EPERM;

This is a nice improvement, but the comment could be better.  How
about "If we're already at a lower level than we're looking for, we're
done searching."

--Andy

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ