* [PATCH v2] security: Use user_namespace::level to avoid redundant iterations in cap_capable()
@ 2017-05-02 17:11 Kirill Tkhai
0 siblings, 0 replies; only message in thread
From: Kirill Tkhai @ 2017-05-02 17:11 UTC (permalink / raw)
To: serge, ebiederm, agruenba, gregkh, oleg, linux-kernel, paul,
ktkhai, viro, avagin, gorcunov, mtk.manpages, akpm, luto, mingo,
keescook
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.
v2: Change comment on suggested by Andy Lutomirski.
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..a424aa0123af 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 we're already at a lower level than we're looking for, we're
+ * done searching.
+ */
+ if (ns->level <= cred->user_ns->level)
return -EPERM;
/*
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-05-02 17:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 17:11 [PATCH v2] security: Use user_namespace::level to avoid redundant iterations in cap_capable() Kirill Tkhai
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).