From: Andy Lutomirski <luto@kernel.org>
To: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Andreas Gruenbacher <agruenba@redhat.com>,
Greg KH <gregkh@linuxfoundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Oleg Nesterov <oleg@redhat.com>, Paul Moore <paul@paul-moore.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Andrey Vagin <avagin@openvz.org>,
Linux API <linux-api@vger.kernel.org>,
Linux FS Devel <linux-fsdevel@vger.kernel.org>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Cyrill Gorcunov <gorcunov@openvz.org>,
Ingo Molnar <mingo@kernel.org>, Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] security: Use user_namespace::level to avoid redundant iterations in cap_capable()
Date: Tue, 2 May 2017 09:36:40 -0700 [thread overview]
Message-ID: <CALCETrWT5u=dpRadn_dHosa0YEpC9j_-Gttu7qk1pOrN9XmfUA@mail.gmail.com> (raw)
In-Reply-To: <149372879732.11927.12565684278286604561.stgit@localhost.localdomain>
On Tue, May 2, 2017 at 5:40 AM, Kirill Tkhai <ktkhai@virtuozzo.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@virtuozzo.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
prev parent reply other threads:[~2017-05-02 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-02 12:40 [PATCH] security: Use user_namespace::level to avoid redundant iterations in cap_capable() Kirill Tkhai
2017-05-02 16:36 ` Andy Lutomirski [this message]
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='CALCETrWT5u=dpRadn_dHosa0YEpC9j_-Gttu7qk1pOrN9XmfUA@mail.gmail.com' \
--to=luto@kernel.org \
--cc=agruenba@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@openvz.org \
--cc=ebiederm@xmission.com \
--cc=gorcunov@openvz.org \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=ktkhai@virtuozzo.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=oleg@redhat.com \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=viro@zeniv.linux.org.uk \
/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).