linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] security: Use user_namespace::level to avoid redundant iterations in cap_capable()
@ 2017-05-02 12:40 Kirill Tkhai
  2017-05-02 16:36 ` Andy Lutomirski
  0 siblings, 1 reply; 2+ messages in thread
From: Kirill Tkhai @ 2017-05-02 12:40 UTC (permalink / raw)
  To: serge-A9i7LUbDfNHQT0dZR+AlfA, ebiederm-aS9lmoZGLiVWk0Htik3J/w,
	agruenba-H+wXaHxf7aLQT0dZR+AlfA,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, oleg-H+wXaHxf7aLQT0dZR+AlfA,
	paul-r2n+y4ga6xFZroRs9YW3xA, ktkhai-5HdwGun5lf+gSpxsJD1C4w,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	avagin-GEFAQzZX7r8dnm+yROfE0A, linux-api-u79uwXL29TY76Z2rM5mHXA,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	luto-kltTT9wpgjJwATOyAt5JVQ, gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	mingo-DgEjT+Ai2ygdnm+yROfE0A, keescook-F7+t8E8rja9g9hUCZPvPmw

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-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org>
---
 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;
 
 		/* 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-02 16:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).