2012-10-31 16:04:48

by Aristeu Rozanski

[permalink] [raw]
Subject: [PATCH] device_cgroup: fix unchecked cgroup parent usage

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 <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: James Morris <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Serge Hallyn <[email protected]>
Cc: Jiri Slaby <[email protected]>
Signed-off-by: Aristeu Rozanski <[email protected]>

--- 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);


2012-10-31 16:23:37

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] device_cgroup: fix unchecked cgroup parent usage

On Wed, Oct 31, 2012 at 12:04:30PM -0400, Aristeu Rozanski wrote:
> 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.

Acked-by: Tejun Heo <[email protected]>

Andrew, can you please pick this one up?

Thanks.

--
tejun

2012-10-31 17:21:13

by Serge Hallyn

[permalink] [raw]
Subject: Re: [PATCH] device_cgroup: fix unchecked cgroup parent usage

Quoting Aristeu Rozanski ([email protected]):
> 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 <[email protected]>
> Cc: Tejun Heo <[email protected]>
> Cc: Li Zefan <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: Pavel Emelyanov <[email protected]>
> Cc: Serge Hallyn <[email protected]>

Acked-by: Serge E. Hallyn <[email protected]>

> Cc: Jiri Slaby <[email protected]>
> Signed-off-by: Aristeu Rozanski <[email protected]>
>
> --- 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);

2012-10-31 23:35:06

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] device_cgroup: fix unchecked cgroup parent usage

On Wed, 31 Oct 2012 12:04:30 -0400
Aristeu Rozanski <[email protected]> wrote:

> In 4cef7299b4786879a3e113e84084a72b24590c5b the cgroup parent usage is
> unchecked. root will not have a parent and trying to use
> device.{allow,deny} will cause problems.

>From my reading of the code "problems" means "kernel null pointer
dereference".

> For some reason my stressing
> scripts didn't test the root directory so I didn't catch it on my
> regular tests.
>
> --- 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)

offtopic: this function could quite neatly have a bool return type.

> {
> + if (!parent)
> + return 1;

hm. Does it need a comment explaining what and why? I guess not... just.

> return parent->behavior == DEVCG_DEFAULT_ALLOW;
> }

2012-11-01 13:29:00

by Aristeu Rozanski

[permalink] [raw]
Subject: Re: [PATCH] device_cgroup: fix unchecked cgroup parent usage

On Wed, Oct 31, 2012 at 04:35:01PM -0700, Andrew Morton wrote:
> On Wed, 31 Oct 2012 12:04:30 -0400
> Aristeu Rozanski <[email protected]> wrote:
>
> > In 4cef7299b4786879a3e113e84084a72b24590c5b the cgroup parent usage is
> > unchecked. root will not have a parent and trying to use
> > device.{allow,deny} will cause problems.
>
> From my reading of the code "problems" means "kernel null pointer
> dereference".

yes. you want me to resubmit it fixing it or you want to update it?

> > static inline int may_allow_all(struct dev_cgroup *parent)
>
> offtopic: this function could quite neatly have a bool return type.

ok, will do.

> > {
> > + if (!parent)
> > + return 1;
>
> hm. Does it need a comment explaining what and why? I guess not... just.

it's because the root's parent has to always allows full access to all
devices. I can add a comment when I turn into a bool if you want.

--
Aristeu