2008-12-11 15:50:47

by Serge E. Hallyn

[permalink] [raw]
Subject: [PATCH 1/1] devices cgroup: allow mkfifo

The devcgroup_inode_permission() hook in the devices whitelist
cgroup has always bypassed access checks on fifos. But the
mknod hook did not. The devices whitelist is only about block
and char devices, and fifos can't even be added to the whitelist,
so fifos can't be created at all except by tasks which have 'a'
in their whitelist (meaning they have access to all devices).

Fix the behavior by bypassing access checks to mkfifo (and mksock).

(Thanks, Daniel, for finding this)

Signed-off-by: Serge E. Hallyn <[email protected]>
Reviewed-by: Li Zefan <[email protected]>
---
security/device_cgroup.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 5ba7870..df9d491 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -513,6 +513,9 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
struct dev_cgroup *dev_cgroup;
struct dev_whitelist_item *wh;

+ if (!S_ISBLK(mode) && !S_ISCHR(mode))
+ return 0;
+
rcu_read_lock();

dev_cgroup = task_devcgroup(current);
--
1.5.4.3


2008-12-12 03:12:31

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 1/1] devices cgroup: allow mkfifo

On Thu, 11 Dec 2008 09:50:27 -0600 "Serge E. Hallyn" <[email protected]> wrote:

> The devcgroup_inode_permission() hook in the devices whitelist
> cgroup has always bypassed access checks on fifos. But the
> mknod hook did not. The devices whitelist is only about block
> and char devices, and fifos can't even be added to the whitelist,
> so fifos can't be created at all except by tasks which have 'a'
> in their whitelist (meaning they have access to all devices).
>
> Fix the behavior by bypassing access checks to mkfifo (and mksock).
>
> (Thanks, Daniel, for finding this)
>
> Signed-off-by: Serge E. Hallyn <[email protected]>
> Reviewed-by: Li Zefan <[email protected]>
> ---
> security/device_cgroup.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
> index 5ba7870..df9d491 100644
> --- a/security/device_cgroup.c
> +++ b/security/device_cgroup.c
> @@ -513,6 +513,9 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
> struct dev_cgroup *dev_cgroup;
> struct dev_whitelist_item *wh;
>
> + if (!S_ISBLK(mode) && !S_ISCHR(mode))
> + return 0;
> +
> rcu_read_lock();
>
> dev_cgroup = task_devcgroup(current);

hm. I'd looked at your description and decided this was 2.6.29 material.

But you think it's for 2.6.28 and even for 2.6.27. How come?

(iow, your changelog sucked :)

2008-12-12 14:35:23

by Serge E. Hallyn

[permalink] [raw]
Subject: Re: [PATCH 1/1] devices cgroup: allow mkfifo

Quoting Andrew Morton ([email protected]):
> On Thu, 11 Dec 2008 09:50:27 -0600 "Serge E. Hallyn" <[email protected]> wrote:
>
> > The devcgroup_inode_permission() hook in the devices whitelist
> > cgroup has always bypassed access checks on fifos. But the
> > mknod hook did not. The devices whitelist is only about block
> > and char devices, and fifos can't even be added to the whitelist,
> > so fifos can't be created at all except by tasks which have 'a'
> > in their whitelist (meaning they have access to all devices).
> >
> > Fix the behavior by bypassing access checks to mkfifo (and mksock).
> >
> > (Thanks, Daniel, for finding this)
> >
> > Signed-off-by: Serge E. Hallyn <[email protected]>
> > Reviewed-by: Li Zefan <[email protected]>
> > ---
> > security/device_cgroup.c | 3 +++
> > 1 files changed, 3 insertions(+), 0 deletions(-)
> >
> > diff --git a/security/device_cgroup.c b/security/device_cgroup.c
> > index 5ba7870..df9d491 100644
> > --- a/security/device_cgroup.c
> > +++ b/security/device_cgroup.c
> > @@ -513,6 +513,9 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
> > struct dev_cgroup *dev_cgroup;
> > struct dev_whitelist_item *wh;
> >
> > + if (!S_ISBLK(mode) && !S_ISCHR(mode))
> > + return 0;
> > +
> > rcu_read_lock();
> >
> > dev_cgroup = task_devcgroup(current);
>
> hm. I'd looked at your description and decided this was 2.6.29 material.
>
> But you think it's for 2.6.28 and even for 2.6.27. How come?
>
> (iow, your changelog sucked :)

Sorry, I should have put the exchange between Li and I in there.
(Ouch, and I didn't cc: Li this time! Sorry, Li.)

Li thought it was 2.6.27/2.6.27 material. I thought not, but wanted
to see what the -stable folks thought.

This is not a security hole, and since noone has complained before
it doesn't appear to be too inconvenient. Until the fix goes
up, container users can always create the fifos and socks on the
root image while creating the container, before entering the
device whitelist.

thanks,
-serge

2008-12-13 07:10:39

by Li Zefan

[permalink] [raw]
Subject: Re: [PATCH 1/1] devices cgroup: allow mkfifo

>> hm. I'd looked at your description and decided this was 2.6.29 material.
>>
>> But you think it's for 2.6.28 and even for 2.6.27. How come?
>>
>> (iow, your changelog sucked :)
>
> Sorry, I should have put the exchange between Li and I in there.
> (Ouch, and I didn't cc: Li this time! Sorry, Li.)
>
> Li thought it was 2.6.27/2.6.27 material. I thought not, but wanted
> to see what the -stable folks thought.
>

I was not sure about this.

> This is not a security hole, and since noone has complained before
> it doesn't appear to be too inconvenient. Until the fix goes
> up, container users can always create the fifos and socks on the
> root image while creating the container, before entering the
> device whitelist.
>

Now the explanation makes it clear for me, thx. :)