diff options
author | Kirill Tkhai <ktkhai@virtuozzo.com> | 2017-05-02 13:11:52 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2017-07-20 08:46:06 -0400 |
commit | 64db4c7f4c1dde23d47b60f887000e28f82b268f (patch) | |
tree | e7f344fb2015e7c138fc1d05804da2969c205be9 | |
parent | a2b426267c56773201f968fdb5eda6ab9ae94e34 (diff) |
security: Use user_namespace::level to avoid redundant iterations in cap_capable()
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 sense to search in parents.
So, break the cycle earlier and skip needless iterations.
v2: Change comment on suggested by Andy Lutomirski.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
-rw-r--r-- | security/commoncap.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/security/commoncap.c b/security/commoncap.c index 7abebd782d5e..d59320282294 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, | |||
82 | if (ns == cred->user_ns) | 82 | if (ns == cred->user_ns) |
83 | return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM; | 83 | return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM; |
84 | 84 | ||
85 | /* Have we tried all of the parent namespaces? */ | 85 | /* |
86 | if (ns == &init_user_ns) | 86 | * If we're already at a lower level than we're looking for, |
87 | * we're done searching. | ||
88 | */ | ||
89 | if (ns->level <= cred->user_ns->level) | ||
87 | return -EPERM; | 90 | return -EPERM; |
88 | 91 | ||
89 | /* | 92 | /* |