cgroups: implement device whitelist lsm (v2)
Subsystems (4)
RFC 1/1 cgroups: implement device whitelist lsm (v2)
Implement a cgroup using the LSM interface to enforce mknod and open on device files.
This implements a simple device access whitelist. A whitelist entry has 4 fields. 'type' is a (all), c (char), or b (block). 'all' means it applies to all types, all major numbers, and all minor numbers. Major and minor are obvious. Access is a composition of r (read), w (write), and m (mknod).
The root devcgroup starts with rwm to 'all'. A child devcg gets a copy of the parent. Admins can then add and remove devices to the whitelist. Once CAP_HOST_ADMIN is introduced it will be needed to add entries as well or remove entries from another cgroup, though just CAP_SYS_ADMIN will suffice to remove entries for your own group.
An entry is added by doing "echo <type> <maj> <min> <access>" > devcg.allow, for instance:
echo b 7 0 mrw > /cgroups/1/devcg.allow
An entry is removed by doing likewise into devcg.deny. Since this is a pure whitelist, not acls, you can only remove entries which exist in the whitelist. You must explicitly
echo a 0 0 mrw > /cgroups/1/devcg.deny
to remove the "allow all" entry which is automatically inherited from the root cgroup.
While composing this with the ns_cgroup may seem logical, it is not the right thing to do, because updates to /cg/cg1/devcg.deny are not reflected in /cg/cg1/cg2/devcg.allow.
A task may only be moved to another devcgroup if it is moving to a direct descendent of its current devcgroup.
CAP_NS_OVERRIDE is defined as the capability needed to cross namespaces. A task needs both CAP_NS_OVERRIDE and CAP_SYS_ADMIN to create a new devcgroup, update a devcgroup's access, or move a task to a new devcgroup.
CONFIG_COMMONCAP is defined whenever security/commoncap.c should be compiled, so that the decision of whether to show the option for FILE_CAPABILITIES can be a bit cleaner.
Pavel, do you have any experience with what sorts of rules a typical customer would get? I wasn't sure whether it was worth having some sort of hash or tree for searching through a cgroup's rules since if most containers have say 0-2 rules then the overhead will just be higher.
Changelog:
Mar 12 2008: allow dev_cgroup lsm to be used when
SECURITY=n, and allow stacking with SELinux and Smack. Don't work too hard in Kconfig to prevent a warning when smack+devcg are both compiled in, worry about that later.
--- include/linux/capability.h | 11 +- include/linux/cgroup_subsys.h | 6 + include/linux/devcg.h | 55 ++++++ include/linux/security.h | 15 ++ init/Kconfig | 7 + kernel/Makefile | 1 + kernel/dev_cgroup.c | 411 +++++++++++++++++++++++++++++++++++++++++ security/Kconfig | 8 +- security/Makefile | 12 +- security/dev_cgroup.c | 138 ++++++++++++++ security/smack/smack_lsm.c | 38 ++++ 11 files changed, 692 insertions(+), 10 deletions(-) create mode 100644 include/linux/devcg.h create mode 100644 kernel/dev_cgroup.c create mode 100644 security/dev_cgroup.c
include/linux/capability.h +10 -1
@@ -333,7 +333,16 @@ typedef struct kernel_cap_struct {#define CAP_MAC_ADMIN 33 -#define CAP_LAST_CAP CAP_MAC_ADMIN +/* Allow acting on resources in another namespace. In particular: +* 1. when combined with CAP_MKNOD and dev_cgroup is enabled, +* allow creation of devices not in the device whitelist. +* 2. whencombined with CAP_SYS_ADMIN and dev_cgroup is enabled, +* allow editing device cgroup whitelist +*/ + +#define CAP_NS_OVERRIDE 34 + +#define CAP_LAST_CAP CAP_NS_OVERRIDE#define cap_valid (x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
include/linux/cgroup_subsys.h +6 -0
@@ -42,3 +42,9 @@ SUBSYS(mem_cgroup)#endif /* */ + +#ifdef CONFIG_CGROUP_DEV +SUBSYS(devcg) +#endif + +/* */
include/linux/devcg.h new file +55 -0
55 lines not on this page · raw message
include/linux/security.h +15 -0
@@ -1735,6 +1735,13 @@ int security_secctx_to_secid(char *secdata, u32 seclen, u32 *secid);void security_release_secctx (char *secdata,u32 seclen);#else /* CONFIG_SECURITY */ +#ifdef CONFIG_CGROUP_DEV +extern int devcgroup_inode_mknod (struct inode *dir,struct dentry *dentry, +int mode,dev_t dev); +extern int devcgroup_inode_permission (struct inode *inode,int mask, +struct nameidata *nd); +#endif +struct security_mnt_opts { };
@@ -2011,7 +2018,11 @@ static inline int security_inode_mknod (struct inode *dir,struct dentry *dentry, int mode, dev_t dev) { +#ifdef CONFIG_CGROUP_DEV + return devcgroup_inode_mknod(dir, dentry, mode, dev); +#else return 0 ; +#endif } static inline int security_inode_rename (struct inode *old_dir,
@@ -2036,7 +2047,11 @@ static inline int security_inode_follow_link (struct dentry *dentry,static inline int security_inode_permission (struct inode *inode,int mask,struct nameidata *nd) { +#ifdef CONFIG_CGROUP_DEV +return devcgroup_inode_permission (inode, mask, nd); +#else return 0 ; +#endif } static inline int security_inode_setattr (struct dentry *dentry,
init/Kconfig +7 -0
@@ -298,6 +298,13 @@ config CGROUP_NS for instance virtual servers and checkpoint/restart jobs. +config CGROUP_DEV + bool "Device controller for cgroups" + depends on CGROUPS && EXPERIMENTAL + help + Provides a cgroup implementing whitelists for devices which + a process in the cgroup can mknod or open. + config CPUSETS bool "Cpuset support" depends on SMP && CGROUPS
kernel/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_CGROUPS) += cgroup.o obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o +obj-$(CONFIG_CGROUP_DEV) += dev_cgroup.o obj-$(CONFIG_UTS_NS) += utsname.o obj-$(CONFIG_USER_NS) += user_namespace.o obj-$(CONFIG_PID_NS) += pid_namespace.o
kernel/dev_cgroup.c new file +411 -0
411 lines not on this page · raw message
security/Kconfig +6 -2
@@ -75,15 +75,19 @@ config SECURITY_NETWORK_XFRM config SECURITY_CAPABILITIES bool "Default Linux Capabilities" - depends on SECURITY + depends on SECURITY && !CGROUP_DEV default y help This enables the "default" Linux capabilities functionality. If you are unsure how to answer this question, answer Y. +config COMMONCAP + bool + default !SECURITY || SECURITY_CAPABILITIES || SECURITY_ROOTPLUG || SECURITY_SMACK || CGROUP_DEV + config SECURITY_FILE_CAPABILITIES bool "File POSIX Capabilities (EXPERIMENTAL)" - depends on (SECURITY=n || SECURITY_CAPABILITIES!=n) && EXPERIMENTAL + depends on COMMONCAP && EXPERIMENTAL default n help This enables filesystem capabilities, allowing you to give
security/Makefile +5 -7
@@ -6,15 +6,13 @@ obj-$(CONFIG_KEYS) += keys/ subdir-$(CONFIG_SECURITY_SELINUX) += selinux subdir-$(CONFIG_SECURITY_SMACK) += smack -# if we don't select a security model, use the default capabilities -ifneq ($(CONFIG_SECURITY),y) -obj-y += commoncap.o -endif +obj-$(CONFIG_COMMONCAP) += commoncap.o # Object file lists obj-$(CONFIG_SECURITY) += security.o dummy.o inode.o # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o -obj-$(CONFIG_SECURITY_SMACK) += commoncap.o smack/built-in.o -obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o -obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o +obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o +obj-$(CONFIG_SECURITY_CAPABILITIES) += capability.o +obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o +obj-$(CONFIG_CGROUP_DEV) += dev_cgroup.o
security/dev_cgroup.c new file +138 -0
138 lines not on this page · raw message
security/smack/smack_lsm.c +38 -0
@@ -36,6 +36,18 @@#define SOCKFS_MAGIC 0x534F434B#define TMPFS_MAGIC 0x01021994 +#ifdef CONFIG_CGROUP_DEV +/* +* A better approach is probably to switch to full secondary-> +* support for smack, but for now just hook the devcgroup lsm +* hooks explicitly when compiled in +*/ +int devcgroup_inode_mknod (struct inode *dir,struct dentry *dentry, +int mode,dev_t dev); +int devcgroup_inode_permission (struct inode *inode,int mask, +struct nameidata *nd); +#endif +/** * smk_fetch - Fetch the smack label from a file. * @ip: a pointer to the inode
@@ -523,6 +535,12 @@ static int smack_inode_rename(struct inode *old_inode,static int smack_inode_permission (struct inode *inode,int mask,struct nameidata *nd) { +#ifdef CONFIG_CGROUP_DEV +int err; + err =devcgroup_inode_permission (inode, mask, nd); +if (err) +return err; +#endif /* * No permission to check. Existence test. Yup, it's there. */
@@ -1370,6 +1388,23 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,return 0 ; } +#ifdef CONFIG_CGROUP_DEV +/** +* smack_inode_mknod +* @dir contains the inode structure of parent of the new file. +* @dentry contains the dentry structure of the new file. +* @mode contains the mode of the new file. +* @dev contains the device number. +* +* Just calls the devcgroup hook to allow stacking. +*/ +static int smack_inode_mknod (struct inode *dir,struct dentry *dentry, +int mode,dev_t dev) +{ +return devcgroup_inode_mknod (dir, dentry, mode, dev); +} +#endif +/** * smack_socket_post_create - finish socket setup * @sock: the socket
@@ -2460,6 +2495,9 @@ struct security_operations smack_ops = { .inode_getsecurity = smack_inode_getsecurity, .inode_setsecurity = smack_inode_setsecurity, .inode_listsecurity = smack_inode_listsecurity, +#ifdef CONFIG_CGROUP_DEV + .inode_mknod = smack_inode_mknod, +#endif .file_permission = smack_file_permission, .file_alloc_security = smack_file_alloc_security,
Signature · 1 line
1.5.1
James Morris
maintainerQuoted 25 lines · Serge E. Hallyn
security/dev_cgroup.c new file +25
-0+#ifdef CONFIG_SECURITY +static struct security_operations devcgroup_security_ops = { + .inode_mknod = devcgroup_inode_mknod, + .inode_permission = devcgroup_inode_permission, + + .ptrace = cap_ptrace, + .capget = cap_capget, + .capset_check = cap_capset_check, + .capset_set = cap_capset_set, + .capable = cap_capable, + .settime = cap_settime, + .netlink_send = cap_netlink_send, + .netlink_recv = cap_netlink_recv, + + .bprm_apply_creds = cap_bprm_apply_creds, + .bprm_set_security = cap_bprm_set_security, + .bprm_secureexec = cap_bprm_secureexec, + + .inode_setxattr = cap_inode_setxattr, + .inode_removexattr = cap_inode_removexattr, + .inode_need_killpriv = cap_inode_need_killpriv, + .inode_killpriv = cap_inode_killpriv, + + .task_kill = cap_task_kill, + .task_setscheduler = cap_task_setscheduler,
security/dev_cgroup.c line 119
Quoted 10 lines
security/dev_cgroup.c new file +10
-0+ .task_setioprio = cap_task_setioprio, + .task_setnice = cap_task_setnice, + .task_post_setuid = cap_task_post_setuid, + .task_prctl = cap_task_prctl, + .task_reparent_to_init = cap_task_reparent_to_init, + + .syslog = cap_syslog, + + .vm_enough_memory = cap_vm_enough_memory, +};
For lower overall complexity, why not just extend the capability LSM to include the devcgroup_ perms if CONFIG_CGROUP_DEV ?
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 32 lines · James Morris
Quoted 30 lines · Serge E. Hallyn
security/dev_cgroup.c new file +30
-0+#ifdef CONFIG_SECURITY +static struct security_operations devcgroup_security_ops = { + .inode_mknod = devcgroup_inode_mknod, + .inode_permission = devcgroup_inode_permission, + + .ptrace = cap_ptrace, + .capget = cap_capget, + .capset_check = cap_capset_check, + .capset_set = cap_capset_set, + .capable = cap_capable, + .settime = cap_settime, + .netlink_send = cap_netlink_send, + .netlink_recv = cap_netlink_recv, + + .bprm_apply_creds = cap_bprm_apply_creds, + .bprm_set_security = cap_bprm_set_security, + .bprm_secureexec = cap_bprm_secureexec, + + .inode_setxattr = cap_inode_setxattr, + .inode_removexattr = cap_inode_removexattr, + .inode_need_killpriv = cap_inode_need_killpriv, + .inode_killpriv = cap_inode_killpriv, + + .task_kill = cap_task_kill, + .task_setscheduler = cap_task_setscheduler, + .task_setioprio = cap_task_setioprio, + .task_setnice = cap_task_setnice, + .task_post_setuid = cap_task_post_setuid, + .task_prctl = cap_task_prctl, + .task_reparent_to_init = cap_task_reparent_to_init,
Quoted 8 lines
security/dev_cgroup.c line 119
Quoted 5 lines
security/dev_cgroup.c new file +5
-0+ + .syslog = cap_syslog, + + .vm_enough_memory = cap_vm_enough_memory, +};For lower overall complexity, why not just extend the capability LSM to include the
devcgroup_perms ifCONFIG_CGROUP_DEV?
That does make for a simpler implementation at this point, however if any other such LSMs come along (as Casey seemed to think they would) the end result could end up being horrible spaghetti code of dependencies and interrelated configs.
But OTOH we went years with no such changes, so that's probably not a particularly practical concern unless someone can cite specific upcoming examples. So if noone objects I'll try that approach.
thanks,
-serge
James Morris
maintainerQuoted 4 lines · Serge E. Hallyn
That does make for a simpler implementation at this point, however if any other such LSMs come along (as Casey seemed to think they would) the end result could end up being horrible spaghetti code of dependencies and interrelated configs.
That can be addressed as the need arises. A basic tenet of kernel development is to avoid speculative infrastructure.
Quoted 3 lines
But OTOH we went years with no such changes, so that's probably not a particularly practical concern unless someone can cite specific upcoming examples. So if noone objects I'll try that approach.
Signature · 2 lines
James Morris <[email protected]>
Quoted 9 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
That does make for a simpler implementation at this point, however if any other such LSMs come along (as Casey seemed to think they would) the end result could end up being horrible spaghetti code of dependencies and interrelated configs.
That can be addressed as the need arises. A basic tenet of kernel development is to avoid speculative infrastructure.
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when CONFIG_CGROUP_DEV=y and:
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabled
It will not be enforcing when
dummy is loaded
only selinux (and not capabilities) is loaded
If that's ok with people then I'm fine with it. I suppose it should be explained in the CONFIG_CGROUP_DEV help section, which it isn't in this version I'm about to set. Patch hitting the wire in a minute.
thanks,
-serge
Quoted 7 lines
Quoted 3 lines
But OTOH we went years with no such changes, so that's probably not a particularly practical concern unless someone can cite specific upcoming examples. So if noone objects I'll try that approach.
Signature · 2 lines
James Morris <[email protected]>
James Morris
maintainerQuoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabled
Well, this is how real systems are going to be deployed.
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
Signature · 2 lines
James Morris <[email protected]>
Quoted 6 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:
Quoted 7 lines
Quoted 5 lines
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledWell, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use dev_cgroup? (Just making sure I understand right)
-serge
James Morris
maintainerQuoted 13 lines · Serge E. Hallyn
Quoted 12 lines · James Morris
Quoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabled
Quoted 3 lines
Quoted 1 line
Well, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 5 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)
Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Signature · 2 lines
James Morris <[email protected]>
Quoted 27 lines · James Morris
Quoted 13 lines · Serge E. Hallyn
Quoted 12 lines · James Morris
Quoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledQuoted 3 lines
Quoted 1 line
Well, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 3 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
Quoted 6 lines
Quoted 2 lines
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
thanks,
-serge
Quoted 31 lines · Serge E. Hallyn
Quoted 30 lines · James Morris
Quoted 13 lines · Serge E. Hallyn
Quoted 12 lines · James Morris
Quoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledQuoted 3 lines
Quoted 1 line
Well, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 5 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)
Quoted 7 lines
Quoted 3 lines
Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
My main question was why was that file in the kernel/ directory? Shouldn't that also be in the security/ directory?
And to be honest, I didn't really look at it at all other than the diffstat to make sure you weren't messing with the kobj_map stuff anymore :)
thanks,
greg k-h
Quoted 36 lines · Greg KH
Quoted 35 lines · Serge E. Hallyn
Quoted 33 lines · James Morris
Quoted 13 lines · Serge E. Hallyn
Quoted 12 lines · James Morris
Quoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledQuoted 3 lines
Quoted 1 line
Well, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 5 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Quoted 6 lines
Quoted 3 lines
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
My main question was why was that file in the
kernel/directory? Shouldn't that also be in thesecurity/directory?
I'm using cgroups to track the tasks which should have their device permissions restricted. Right now cgroups are all under kernel/.
Quoted 11 lines
And to be honest, I didn't really look at it at all other than the diffstat to make sure you weren't messing with the
kobj_mapstuff anymore :)thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
[snip]
Quoted 5 lines
Quoted 2 lines
My main question was why was that file in the
kernel/directory? Shouldn't that also be in thesecurity/directory?I'm using cgroups to track the tasks which should have their device permissions restricted. Right now cgroups are all under
kernel/.
No. Memory cgroup is under mm/ :)
Quoted 12 lines
Quoted 11 lines
And to be honest, I didn't really look at it at all other than the diffstat to make sure you weren't messing with the
kobj_mapstuff anymore :)thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Pavel Emelyanov
[snip]
Quoted 5 lines
Quoted 2 lines
My main question was why was that file in the
kernel/directory? Shouldn't that also be in thesecurity/directory?I'm using cgroups to track the tasks which should have their device permissions restricted. Right now cgroups are all under
kernel/.No. Memory cgroup is under
mm/:)
Ah.
Guess it could all go under security/. Should it still go there even if we make it not use lsm?
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
And to be honest, I didn't really look at it at all other than the diffstat to make sure you weren't messing with the
kobj_mapstuff anymore :)thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Serge E. Hallyn
Quoted 4 lines · Pavel Emelyanov
[snip]
Quoted 2 lines
Quoted 2 lines
My main question was why was that file in the
kernel/directory? Shouldn't that also be in thesecurity/directory?
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
I'm using cgroups to track the tasks which should have their device permissions restricted. Right now cgroups are all under
kernel/.No. Memory cgroup is under
mm/:)Ah.
Guess it could all go under
security/. Should it still go there even if we make it not use lsm?
Sure it can - security/ is in obj-y regardless of whether the SECURITY itself is on or off :)
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
And to be honest, I didn't really look at it at all other than the diffstat to make sure you weren't messing with the
kobj_mapstuff anymore :)thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Serge E. Hallyn
Quoted 8 lines · Pavel Emelyanov
[snip]
Quoted 5 lines
Quoted 2 lines
My main question was why was that file in the
kernel/directory? Shouldn't that also be in thesecurity/directory?I'm using cgroups to track the tasks which should have their device permissions restricted. Right now cgroups are all under
kernel/.
Quoted 6 lines
Quoted 1 line
No. Memory cgroup is under
mm/:)Ah.
Guess it could all go under
security/. Should it still go there even if we make it not use lsm?
There is the precedent of the security/keys directory (security-related, but not using LSM - aside from calling LSM hooks for access checks and labeling of keys).
Signature · 2 lines
Stephen Smalley National Security Agency
Quoted 26 lines · Serge E. Hallyn
Quoted 25 lines · James Morris
Quoted 7 lines · Serge E. Hallyn
Quoted 6 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledWell, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 4 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)
Quoted 7 lines
Quoted 3 lines
Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
Well, I saw your previous patch, that was implemented as just another LSM module and I liked it except for the LSM dependency.
Since this version can happily work w/o LSM, I like it too :)
Quoted 3 lines
thanks,
-serge
Quoted 31 lines · Pavel Emelyanov
Quoted 30 lines · Serge E. Hallyn
Quoted 28 lines · James Morris
Quoted 7 lines · Serge E. Hallyn
Quoted 6 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledWell, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 4 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Quoted 6 lines
Quoted 3 lines
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
Well, I saw your previous patch, that was implemented as just another LSM module and I liked it except for the LSM dependency.
James and Stephen agree with your LSM qualms. I suppose we could add cgroups next to the lsm hooks. I suspect Paul Menage would complain about that (Paul?), and I do think it's silly as they are security questions, not group tracking questions, but if it's what people want I can send out a new patch next week.
Quoted 1 line
Since this version can happily work w/o LSM, I like it too :)
In an earlier version I asked whether you had any experience with usual
# rules per container. Do you have an idea? Right now the whitelist is a straight list we search through linearly. If # rules is generally tiny then I'm inclined to keep it that way...
thanks,
-serge
Quoted 3 lines · Serge E. Hallyn
James and Stephen agree with your LSM qualms. I suppose we could add cgroups next to the lsm hooks. I suspect Paul Menage would complain about that (Paul?),
Depends on what you mean by "add cgroups to the LSM hooks". Could you expand on that?
Paul
Quoted 7 lines · Paul Menage
Quoted 3 lines · Serge E. Hallyn
James and Stephen agree with your LSM qualms. I suppose we could add cgroups next to the lsm hooks. I suspect Paul Menage would complain about that (Paul?),
Depends on what you mean by "add cgroups to the LSM hooks". Could you expand on that?
cgroup hooks next to the lsm hooks. So in fs/namei.c where there are security_inode_permission() hooks, there would also be cgroup_inode_permission() hooks to let the devices cgroup mediate the access. Well, in permission(), probably not in exec_permission_lite() since that's probalby not a device access :)
So far it looks like everyone likes that, so as long as you don't nack I guess that'll be the way to go.
thanks,
-serge
Quoted 6 lines · Serge E. Hallyn
cgroup hooks next to the lsm hooks. So in
fs/namei.cwhere there aresecurity_inode_permission()hooks, there would also becgroup_inode_permission()hooks to let the devices cgroup mediate the access. Well, inpermission(), probably not inexec_permission_lite()since that's probalby not a device access :)
This would just be a device cgroup-specific thing, right? Nothing to do with the generic framework? If so, then that sounds fine (to me, at least).
Paul
Quoted 31 lines · Serge E. Hallyn
Quoted 30 lines · Pavel Emelyanov
Quoted 29 lines · Serge E. Hallyn
Quoted 28 lines · James Morris
Quoted 7 lines · Serge E. Hallyn
Quoted 6 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledWell, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 4 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
Well, I saw your previous patch, that was implemented as just another LSM module and I liked it except for the LSM dependency.
James and Stephen agree with your LSM qualms. I suppose we could add
Thanks!
Quoted 4 lines
cgroups next to the lsm hooks. I suspect Paul Menage would complain about that (Paul?), and I do think it's silly as they are security questions, not group tracking questions, but if it's what people want I can send out a new patch next week.
The way I see this is: cgroups provide a common way to group tasks and an API for general configuration - that's the controller "face", and it's up to the controller to decide where he turns his "back", IOW where the hooks are placed. For the memory controller - they are injected directly into the mm code. For this controller, I think it would be OK to use LSM or about-LSM hooks.
Quoted 6 lines
Quoted 1 line
Since this version can happily work w/o LSM, I like it too :)
In an earlier version I asked whether you had any experience with usual
# rules per container. Do you have an idea? Right now the whitelist is a straight list we search through linearly. If # rules is generally tiny then I'm inclined to keep it that way...
The # of rules usually has a linear dependency on the number of containers (each of then has to have an access to /dev/null,zero,random at least), so having 100 containers we will have to scan through a 300-entries list. I'd vote for a hash table or a radix/binary/rb tree for that. Or any other way for non-linear search you can provide :)
Quoted 3 lines
thanks,
-serge
Quoted 56 lines · Pavel Emelyanov
Quoted 31 lines · Serge E. Hallyn
Quoted 30 lines · Pavel Emelyanov
Quoted 29 lines · Serge E. Hallyn
Quoted 28 lines · James Morris
Quoted 7 lines · Serge E. Hallyn
Quoted 6 lines · James Morris
Quoted 4 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledWell, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 4 lines
Quoted 2 lines
It becomes confusing, IMHO, if you have to change which secondary LSM you stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Oh, ok.
Will let the patch stand until Pavel and Greg comment then.
Well, I saw your previous patch, that was implemented as just another LSM module and I liked it except for the LSM dependency.
James and Stephen agree with your LSM qualms. I suppose we could add
Thanks!
Quoted 4 lines
cgroups next to the lsm hooks. I suspect Paul Menage would complain about that (Paul?), and I do think it's silly as they are security questions, not group tracking questions, but if it's what people want I can send out a new patch next week.
The way I see this is: cgroups provide a common way to group tasks and an API for general configuration - that's the controller "face", and it's up to the controller to decide where he turns his "back", IOW where the hooks are placed. For the memory controller - they are injected directly into the mm code. For this controller, I think it would be OK to use LSM or about-LSM hooks.
Quoted 2 lines
Quoted 1 line
Since this version can happily work w/o LSM, I like it too :)
Quoted 8 lines
Quoted 4 lines
In an earlier version I asked whether you had any experience with usual
# rules per container. Do you have an idea? Right now the whitelist is a straight list we search through linearly. If # rules is generally tiny then I'm inclined to keep it that way...The # of rules usually has a linear dependency on the number of containers (each of then has to have an access to
/dev/null,zero,randomat least), so having 100 containers we will have to scan through a 300-entries list.
Oh no, the rules are stored per-container, so it sounds like you're saying 3 entries per container?
Quoted 3 lines
I'd
vote for a hash table or a radix/binary/rb tree for that. Or any other way for non-linear search you can provide :)
I'm fine with that, but not for 3 rules :)
-serge
[snip]
Quoted 6 lines
Quoted 3 lines
The # of rules usually has a linear dependency on the number of containers (each of then has to have an access to
/dev/null,zero,randomat least), so having 100 containers we will have to scan through a 300-entries list.Oh no, the rules are stored per-container, so it sounds like you're saying 3 entries per container?
Oops :) I've missed that part :(
Quoted 5 lines
Quoted 3 lines
I'd
vote for a hash table or a radix/binary/rb tree for that. Or any other way for non-linear search you can provide :)I'm fine with that, but not for 3 rules :)
So am I :) Anyway - if someday this will grow up to tens of entries turning it into a more scalable lookup would be easy.
Quoted 2 lines
-serge
Casey Schaufler
maintainerQuoted 26 lines · --- James Morris
Quoted 13 lines · Serge E. Hallyn
Quoted 12 lines · James Morris
Quoted 9 lines · Serge E. Hallyn
True, but while this change simplifies the code a bit, the semantics seem more muddled - devcg will be enforcing when
CONFIG_CGROUP_DEV=yand:SECURITY=n or
rootplug is enabled
capabilities is enabled
smack is enabled
selinux+capabilities is enabledQuoted 3 lines
Quoted 1 line
Well, this is how real systems are going to be deployed.
Sorry, do you mean with capabilities?
Yes.
All Fedora, RHEL, CentOS etc. ship with SELinux+capabilities. I can't imagine not enabling them on other kernels.
Quoted 1 line
Quoted 1 line
It becomes confusing, IMHO, if you have to change which secondary LSM you
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
stack with SELinux to enable a cgroup feature.
So you're saying selinux without capabilities should still be able to use
dev_cgroup? (Just making sure I understand right)Nope, SELinux always stacks with capabilities, so havng the cgroup hooks in capabilities makes sense (rather than having us change the secondary stacking LSM just to enable a feature).
That's what I was getting at. When the next feature comes along are we going to stuff it into capabilities, too? Maybe we'll cram it into audit or CIPSO instead, but how long can this go on? Eventually we need a mechanism that allows more or less general mix-and-match, maybe with a few rules like "don't mix plaids and stripes" to keep things sane or these lesser facilities have no chance. Seems like we're still making LSM too hard to use.
Unless I take an aggressive approach to adding them to Smack. Hmm, might be a way to make a buck or two that way. (Only kidding)(Well, mostly only kidding)
And yes, I understand that there are still those about who don't like LSM in any form, much less in a useful one.
Casey Schaufler
[email protected]
Quoted 4 lines · Serge E. Hallyn
While composing this with the
ns_cgroupmay seem logical, it is not the right thing to do, because updates to /cg/cg1/devcg.deny are not reflected in /cg/cg1/cg2/devcg.allow.
Maybe you should follow up the tree to ensure that all parent groups have access to the device too? Or alternatively, cache the results of this lookup whenever permissions for a device change?
Quoted 3 lines
A task may only be moved to another devcgroup if it is moving to a direct descendent of its current devcgroup.
What's the rationale for that?
Quoted 5 lines
CAP_NS_OVERRIDEis defined as the capability needed to cross namespaces. A task needs bothCAP_NS_OVERRIDEandCAP_SYS_ADMINto create a new devcgroup, update a devcgroup's access, or move a task to a new devcgroup.
But this isn't necessarily crossing namespaces. It could be used for device control in the same namespace (e.g. allowing a job to access a raw disk for its data storage rather than going through the filesystem).
Paul
Quoted 9 lines · Paul Menage
Quoted 4 lines · Serge E. Hallyn
While composing this with the
ns_cgroupmay seem logical, it is not the right thing to do, because updates to /cg/cg1/devcg.deny are not reflected in /cg/cg1/cg2/devcg.allow.Maybe you should follow up the tree to ensure that all parent groups have access to the device too? Or alternatively, cache the results of this lookup whenever permissions for a device change?
Yes, I considered that. Alternatively additions to a parent cgroup's .deny could be propagated to all its descendents (but not additions to the .allow).
I've noted this as something to add to the next version.
Quoted 4 lines
Quoted 2 lines
A task may only be moved to another devcgroup if it is moving to a direct descendent of its current devcgroup.
What's the rationale for that?
To prevent it escaping to laxer device permissions, which of course only makes sense if we do what you recommend above :)
Quoted 9 lines
Quoted 4 lines
CAP_NS_OVERRIDEis defined as the capability needed to cross namespaces. A task needs bothCAP_NS_OVERRIDEandCAP_SYS_ADMINto create a new devcgroup, update a devcgroup's access, or move a task to a new devcgroup.But this isn't necessarily crossing namespaces. It could be used for device control in the same namespace (e.g. allowing a job to access a raw disk for its data storage rather than going through the filesystem).
Yeah it should be renamed. I want to use the same cap which we would use for user namespaces though. CAP_NS_CONT(ainer)? Even though there really is no such thing as a 'container'. But that would tie together any such privileges for cgroups and namespaces.
thanks,
-serge
Quoted 8 lines · Serge E. Hallyn
Quoted 4 lines
Quoted 2 lines
A task may only be moved to another devcgroup if it is moving to a direct descendent of its current devcgroup.
What's the rationale for that?
To prevent it escaping to laxer device permissions, which of course only makes sense if we do what you recommend above :)
That makes it impossible for a root process to enter a child cgroup, do something, and then go back to its own cgroup. Why aren't the existing cgroup security semantics sufficient?
Paul
Quoted 4 lines · Paul Menage
Quoted 3 lines · Serge E. Hallyn
Quoted 3 lines
Quoted 2 lines
A task may only be moved to another devcgroup if it is moving to a direct descendent of its current devcgroup.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What's the rationale for that?
To prevent it escaping to laxer device permissions, which of course only makes sense if we do what you recommend above :)
That makes it impossible for a root process to enter a child cgroup, do something, and then go back to its own cgroup.
Yes, but it can fire off a child in the child cgroup to do something, and go on on its own cgroup when the child finishes.
Quoted 2 lines
Why aren't the
existing cgroup security semantics sufficient?
Because the point of this is to provide some restrictions to otherwise privileged users, and cgroups only provides dac-based permissions.
But that doesn't mean that I'm not doing too much. I could just add a CAP_SYS_ADMIN or CAP_CONT_OVERRIDE+CAP_SYS_ADMIN check, and not restrict which cgroups a task can move to. Does that sound good?
-serge
Quoted 10 lines · Serge E. Hallyn
Quoted 3 lines
Why aren't the
existing cgroup security semantics sufficient?Because the point of this is to provide some restrictions to otherwise privileged users, and cgroups only provides dac-based permissions.
But that doesn't mean that I'm not doing too much. I could just add a
CAP_SYS_ADMINor CAP_CONT_OVERRIDE+CAP_SYS_ADMIN check, and not restrict which cgroups a task can move to. Does that sound good?
Sounds reasonable.
Paul
Quoted 20 lines · Serge E. Hallyn
Implement a cgroup using the LSM interface to enforce mknod and open
on device files.This implements a simple device access whitelist. A whitelist entry has 4 fields. 'type' is a (all), c (char), or b (block). 'all' means it applies to all types, all major numbers, and all minor numbers. Major and minor are obvious. Access is a composition of r (read), w (write), and m (mknod).
The root devcgroup starts with rwm to 'all'. A child devcg gets a copy of the parent. Admins can then add and remove devices to the whitelist. Once
CAP_HOST_ADMINis introduced it will be needed to add entries as well or remove entries from another cgroup, though justCAP_SYS_ADMINwill suffice to remove entries for your own group.An entry is added by doing "echo <type> <maj> <min> <access>" > devcg.allow, for instance:
echo b 7 0 mrw > /cgroups/1/devcg.allow
Quoted 8 lines
An entry is removed by doing likewise into devcg.deny. Since this is a pure whitelist, not acls, you can only remove entries which exist in the whitelist. You must explicitly
echo a 0 0 mrw > /cgroups/1/devcg.deny
to remove the "allow all" entry which is automatically inherited from the root cgroup.
In keeping with the naming convention for control groups, "devices" would be better than "devcg".
Paul
Quoted 25 lines · Paul Menage
Quoted 24 lines · Serge E. Hallyn
Implement a cgroup using the LSM interface to enforce mknod and open
on device files.This implements a simple device access whitelist. A whitelist entry has 4 fields. 'type' is a (all), c (char), or b (block). 'all' means it applies to all types, all major numbers, and all minor numbers. Major and minor are obvious. Access is a composition of r (read), w (write), and m (mknod).
The root devcgroup starts with rwm to 'all'. A child devcg gets a copy of the parent. Admins can then add and remove devices to the whitelist. Once
CAP_HOST_ADMINis introduced it will be needed to add entries as well or remove entries from another cgroup, though justCAP_SYS_ADMINwill suffice to remove entries for your own group.An entry is added by doing "echo <type> <maj> <min> <access>" > devcg.allow, for instance:
echo b 7 0 mrw > /cgroups/1/devcg.allow
An entry is removed by doing likewise into devcg.deny. Since this is a pure whitelist, not acls, you can only remove entries which exist in the whitelist. You must explicitly
Quoted 7 lines
Quoted 4 lines
echo a 0 0 mrw > /cgroups/1/devcg.deny
to remove the "allow all" entry which is automatically inherited from the root cgroup.
In keeping with the naming convention for control groups, "devices" would be better than "devcg".
Noted, thanks.
-serge