Thread (5 messages) 5 messages, 4 authors, 2012-11-01

Re: [PATCH] device_cgroup: fix unchecked cgroup parent usage

From: Serge Hallyn <hidden>
Date: 2012-10-31 17:21:13
Also in: lkml

Quoting Aristeu Rozanski (aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org):
In 4cef7299b4786879a3e113e84084a72b24590c5b the cgroup parent usage is
unchecked. root will not have a parent and trying to use
device.{allow,deny} will cause problems. For some reason my stressing
scripts didn't test the root directory so I didn't catch it on my
regular tests.

Andrew, Tejun, this patch needs to make Linus tree ASAP or a revert for
4cef7299b4786879a3e113e84084a72b24590c5b.

Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Tejun Heo <redacted>
Cc: Li Zefan <redacted>
Cc: James Morris <jmorris-gx6/JNMH7DfYtjvyW6yDsg@public.gmane.org>
Cc: Pavel Emelyanov <redacted>
Cc: Serge Hallyn <redacted>
Acked-by: Serge E. Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
quoted hunk ↗ jump to hunk
Cc: Jiri Slaby <redacted>
Signed-off-by: Aristeu Rozanski <redacted>
--- github.orig/security/device_cgroup.c	2012-10-26 17:18:01.739366780 -0400
+++ github/security/device_cgroup.c	2012-10-29 10:03:33.221918003 -0400
@@ -352,6 +352,8 @@
  */
 static inline int may_allow_all(struct dev_cgroup *parent)
 {
+	if (!parent)
+		return 1;
 	return parent->behavior == DEVCG_DEFAULT_ALLOW;
 }
 
@@ -376,11 +378,14 @@
 	int count, rc;
 	struct dev_exception_item ex;
 	struct cgroup *p = devcgroup->css.cgroup;
-	struct dev_cgroup *parent = cgroup_to_devcgroup(p->parent);
+	struct dev_cgroup *parent = NULL;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
+	if (p->parent)
+		parent = cgroup_to_devcgroup(p->parent);
+
 	memset(&ex, 0, sizeof(ex));
 	b = buffer;
 
@@ -391,11 +396,14 @@
 			if (!may_allow_all(parent))
 				return -EPERM;
 			dev_exception_clean(devcgroup);
+			devcgroup->behavior = DEVCG_DEFAULT_ALLOW;
+			if (!parent)
+				break;
+
 			rc = dev_exceptions_copy(&devcgroup->exceptions,
 						 &parent->exceptions);
 			if (rc)
 				return rc;
-			devcgroup->behavior = DEVCG_DEFAULT_ALLOW;
 			break;
 		case DEVCG_DENY:
 			dev_exception_clean(devcgroup);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help