Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1634519 > unrolled thread
| Started by | Andy Lutomirski <luto@kernel.org> |
|---|---|
| First post | 2017-05-02 18:40 +0200 |
| Last post | 2017-05-02 18:40 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH] security: Use user_namespace::level to avoid redundant iterations in cap_capable() Andy Lutomirski <luto@kernel.org> - 2017-05-02 18:40 +0200
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-05-02 18:40 +0200 |
| Subject | Re: [PATCH] security: Use user_namespace::level to avoid redundant iterations in cap_capable() |
| Message-ID | <tCJ0e-ID-15@gated-at.bofh.it> |
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
Back to top | Article view | linux.kernel
csiph-web