lsm stacking v0.3: intro
Subsystems (9)
cover lsm stacking v0.3: intro
Hi,
The set of patches to follow introduces support for stacking LSMs. This is its third posting to lkml. I am sending it out in the hopes of soliciting more widespread feedback and testing, with the obvious eventual goal of mainline adoption.
Any feedback from people actually using this patch is appreciated. Even better would be posts of (stackable) LSMs for upstream inclusion :)
The patches mainly do the following:
1. Introduce the stacker LSM.
2. Change the kernel object void * security fields to be hlists, and introduce an api for modules to share these.
3. Modify SELinux to make use of stacker.
4. Modify seclvl to use stacker.
Motivation:
The purpose of these patches is to enable stacking multiple security modules. There are several cases where this would be very useful. It eases the testing of new modules with distro kernels, as it makes it possible to stack new modules with selinux and capabilities -- for instance if a user is running fedora. Second, it enables running selinux (or LIDS, etc) with integrity verification modules. (Digsig is an example of these, and within a few months hopefully the TPM-enabled slim+evm modules, which verifies integrity of file contents and extended attributes such as selinux contexts
(http://www.acsac.org/2004/workshop/David-Safford.pdf) will be released for mainline inclusion). Thirdly, there are systems where running selinux is not practical for footprint reasons, and the security goals are easily expressed as a very small module. For instance, it might be desirable to confine a web browser on a zaurus, or to implement a site security policy on old hardware as per
http://mail.wirex.com/pipermail/linux-security-module/2005-May/6071.html
Performance impact of the actual stacker module is negligable. The security_{get,set,del,add}_value API does have a small performance impact. Please see
http://marc.theaimsgroup.com/?l=linux-security-module&m=111820455332752&w=2
and
http://marc.theaimsgroup.com/?l=linux-security-module&m=111824326500837&w=2
if interested in the performance results. I am certainly interested in ways to further speed up security_get_value.
This version adds support for safe unloading of LSMs. This is documented in the stacker-doc.patch. Included below are performance results comparing the last version of stacker to this version.
Tests run were dbench, kernbench, reaim, and tbench. These were run in the following configurations:
16-way ppc with old patchset ("16-plain")
16-way ppc with this patchset ("16-new")
16-way ppc with this patchset, but without the
security_{del,unlink}_value race fix ("16-test") (note - there may be a faster way to do this anyway)
4-way P-III with old patchset ("4-plain")
4-way P-III with this patchset ("4-new")
dbench and tbench were run 50 times each (48 for tbench for 16-new due to mis-set timeout), kernbench and reaim 10 times. The numbers here are mean +/- 95% confidence half-interval.
Results:
dbench (throughput, larger is better):
16-plain: 1560.825000 +/- 9.844956 16-new: 1555.401800 +/- 4.083806 16-test: 1558.164400 +/- 4.685493 4-plain: 351.299100 +/- 5.941376 4-new: 361.487720 +/- 1.624589
tbench (throughput, larger is better)
16-plain: 142.822420 +/- 2.504416 16-new: 142.671510 +/- 3.149260 16-test: 147.186280 +/- 3.548984 4-plain: 37.011122 +/- 0.038450 4-new: 37.014408 +/- 0.038272
kernbench (smaller is better):
16-plain: 52.376000 +/- 0.108133 16-new: 52.378000 +/- 0.119692 16-test: 52.368000 +/- 0.173884 4-plain: 91.739000 +/- 0.349240 4-new: 91.437000 +/- 0.443560
reaim (number of clients versus jobs/minute (+/- CI, larger is better):
16-plain:
1 104040.000000 4614.800612
3 306000.000000 0.000000
5 480857.144000 26914.062669
7 673200.000000 37679.689215
9 878657.142000 45316.443392
11 977742.861000 36259.146697
13 1122364.287000 32138.790300
15 1233107.142000 76974.633465
16-new:
1 100542.857000 3296.286475
3 306000.000000 0.000000
5 495428.572000 21975.240148
7 673200.000000 37679.689215
9 813085.712000 39555.434680
11 961714.290000 0.000000
13 1065535.715000 53564.650500
15 1134750.000000 28842.503826
16-test:
1 104622.857000 7448.926210
3 306000.000000 0.000000
5 495428.572000 21975.240148
7 693600.000000 30765.337414
9 813085.712000 39555.434680
11 1025828.574000 59210.938611
13 1122364.287000 32138.790300
15 1163892.857000 37083.218881
4-plain:
1 45104.176000 1612.185481
3 126771.430000 3296.287229
5 124676.143000 4423.046551
7 154852.416000 4062.286334
9 148950.244000 2664.391611
11 164234.214000 1911.366919
13 161290.790000 4651.698507
15 165440.327000 1813.071866
4-new:
1 46068.131000 1161.957518
3 125022.858000 3021.097148
5 126014.348000 2531.399484
7 158797.437000 3438.066799
9 148186.835000 3186.764542
11 164234.214000 1911.366919
13 160272.056000 4139.820526
15 165748.837000 2045.298142
thanks,
-serge
PATCH 1/15 lsm stacking v0.3: introduce securityfs
This patch from Greg KH is in -mm, and implements the securityfs which is now used by stacker.
--
include/linux/security.h | 5 security/Makefile | 2 security/inode.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 353 insertions(+), 1 deletion(-)
security/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y += commoncap.o endif # Object file lists -obj-$(CONFIG_SECURITY) += security.o dummy.o +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_CAPABILITIES) += commoncap.o capability.o
security/inode.c new file +347 -0
347 lines not on this page · raw message
include/linux/security.h +5 -0
@@ -1983,6 +1983,11 @@ extern int register_security (struct secextern int unregister_security (struct security_operations *ops);extern int mod_reg_security (const char *name,struct security_operations *ops);extern int mod_unreg_security (const char *name,struct security_operations *ops); +extern struct dentry *securityfs_create_file (const char *name,mode_t mode, +struct dentry *parent,void *data, +struct file_operations *fops); +extern struct dentry *securityfs_create_dir (const char *name,struct dentry *parent); +extern void securityfs_remove (struct dentry *dentry);#else /* CONFIG_SECURITY */
PATCH 2/15 lsm stacking v0.3: add module * to security_ops
Add the owning module to the security_operations struct. This will allow stacker to module_get the LSM to prevent its premature unloading.
--
include/linux/security.h | 7 +++++++ security/capability.c | 1 + security/root_plug.c | 2 ++ security/seclvl.c | 1 + security/selinux/hooks.c | 2 ++ 5 files changed, 13 insertions(+)
include/linux/security.h +7 -0
@@ -32,6 +32,7 @@#include <linux/sched.h> struct ctl_table ; +struct module ;/* * These functions are in security/capability.c and are used
@@ -94,6 +95,10 @@ struct swap_info_struct;* * Security hooks for program execution operations. * +* +* @owner: +* Module owning this security_operations. NULL if not a module. +* * @bprm_alloc_security: * Allocate and attach a security structure to the @bprm->security field. * The security field is initialized to NULL when the bprm structure is
@@ -1027,6 +1032,8 @@ struct swap_info_struct;* This is the main security structure. */ struct security_operations { +struct module *owner; +int (*ptrace) (struct task_struct * parent,struct task_struct * child); int (*capget) (struct task_struct * target, kernel_cap_t * effective,
security/capability.c +1 -0
@@ -25,6 +25,7 @@#include <linux/moduleparam.h> static struct security_operations capability_ops = { + .owner =THIS_MODULE , .ptrace = cap_ptrace, .capget = cap_capget, .capset_check = cap_capset_check,
security/root_plug.c +2 -0
@@ -83,6 +83,8 @@ static int rootplug_bprm_check_security }static struct security_operations rootplug_security_ops = { + .owner =THIS_MODULE , +/* Use the capability functions for some of the hooks */ .ptrace = cap_ptrace, .capget = cap_capget,
security/seclvl.c +1 -0
@@ -591,6 +591,7 @@ static int seclvl_umount(struct vfsmount }static struct security_operations seclvl_ops = { + .owner =THIS_MODULE , .ptrace = seclvl_ptrace, .capable = seclvl_capable, .inode_permission = seclvl_inode_permission,
security/selinux/hooks.c +2 -0
@@ -4265,6 +4265,8 @@ static int selinux_setprocattr(struct ta }static struct security_operations selinux_ops = { + .owner =THIS_MODULE , + .ptrace = selinux_ptrace, .capget = selinux_capget, .capset_check = selinux_capset_check,
PATCH 3/15 lsm stacking v0.3: don't default to dummy_##hook
In reply to [email protected]When stacking multiple LSMs, we do not want hooks which are undefined to be substituted with the dummy_##hook.
--
security.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
security/security.c +6 -6
@@ -81,15 +81,15 @@ int __init security_init(void)*/ int register_security (struct security_operations *ops) { +if (security_ops != &dummy_security_ops) +return -EAGAIN ; +if (verify (ops)) {printk (KERN_DEBUG "%s could not verify " "security_operations structure.\n" , __FUNCTION__);return -EINVAL ; } -if (security_ops != &dummy_security_ops) -return -EAGAIN ; - security_ops = ops;return 0 ;
@@ -134,9 +134,9 @@ int unregister_security(struct security_*/ int mod_reg_security (const char *name,struct security_operations *ops) { -if (verify (ops)) { -printk (KERN_INFO "%s could not verify " -"security operations.\n" , __FUNCTION__); +if (!ops) { +printk (KERN_INFO "%s received NULL security operations" , + __FUNCTION__);return -EINVAL ; }
PATCH 4/15 lsm stacking v0.3: swith ->security to hlist
In reply to [email protected]Replace kernel object ->security void*'s with hlists. This will permit multiple LSMs to each store information under one kernel object.
fs/compat.c | 4 ++-- fs/exec.c | 4 ++-- fs/inode.c | 2 +- include/linux/binfmts.h | 2 +- include/linux/fs.h | 8 ++++---- include/linux/ipc.h | 3 ++- include/linux/msg.h | 2 +- include/linux/sched.h | 2 +- include/net/sock.h | 2 +- ipc/msg.c | 2 +- ipc/msgutil.c | 2 +- ipc/sem.c | 2 +- ipc/shm.c | 2 +- kernel/fork.c | 2 +- 14 files changed, 20 insertions(+), 19 deletions(-)
fs/compat.c +2 -2
@@ -1523,6 +1523,7 @@ int compat_do_execve(char * filename, bprm->file = file; bprm->filename = filename; bprm->interp = filename; +INIT_HLIST_HEAD (&bprm->security); bprm->mm =mm_alloc (); retval = -ENOMEM ;if (!bprm->mm)
@@ -1579,8 +1580,7 @@ out:__free_page (page); } -if (bprm->security) -security_bprm_free (bprm); +security_bprm_free (bprm); out_mm:if (bprm->mm)
fs/exec.c +2 -2
@@ -1166,6 +1166,7 @@ int do_execve(char * filename, bprm->file = file; bprm->filename = filename; bprm->interp = filename; +INIT_HLIST_HEAD (&bprm->security); bprm->mm =mm_alloc (); retval = -ENOMEM ;if (!bprm->mm)
@@ -1224,8 +1225,7 @@ out:__free_page (page); } -if (bprm->security) -security_bprm_free (bprm); +security_bprm_free (bprm); out_mm:if (bprm->mm)
fs/inode.c +1 -1
@@ -133,7 +133,7 @@ static struct inode *alloc_inode(struct inode->i_bdev =NULL ; inode->i_cdev =NULL ; inode->i_rdev =0 ; - inode->i_security =NULL ; +INIT_HLIST_HEAD (&inode->i_security); inode->dirtied_when =0 ;if (security_inode_alloc (inode)) {if (inode->i_sb->s_op->destroy_inode)
include/linux/binfmts.h +1 -1
@@ -29,7 +29,7 @@ struct linux_binprm{struct file * file;int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective; -void *security; +struct hlist_head security;int argc, envc;char * filename;/* Name of binary as seen by procps */ char * interp;/* Name of the binary really executed. Most
include/linux/fs.h +4 -4
@@ -485,7 +485,7 @@ struct inode {unsigned int i_flags;atomic_t i_writecount; -void *i_security; +struct hlist_head i_security;union {void *generic_ip; } u;
@@ -559,7 +559,7 @@ struct fown_struct {rwlock_t lock;/* protects pid, uid, euid fields */ int pid;/* pid or -pgrp where SIGIO should be sent */ uid_t uid, euid;/* uid/euid of process setting the owner */ -void *security; +struct hlist_head security;int signum;/* posix.1b rt signal to be delivered on IO */ };
@@ -596,7 +596,7 @@ struct file {size_t f_maxcount;unsigned long f_version; -void *f_security; +struct hlist_head f_security;/* needed for tty driver, and maybe others */ void *private_data;
@@ -783,7 +783,7 @@ struct super_block {int s_syncing;int s_need_sync_fs;atomic_t s_active; -void *s_security; +struct hlist_head s_security;struct xattr_handler **s_xattr;struct list_head s_inodes;/* all inodes */
include/linux/ipc.h +2 -1
@@ -2,6 +2,7 @@#define _LINUX_IPC_H#include <linux/types.h> +#include <linux/list.h> #define IPC_PRIVATE ((__kernel_key_t) 0)
@@ -65,7 +66,7 @@ struct kern_ipc_permgid_t cgid;mode_t mode;unsigned long seq; - void *security; + struct hlist_head security; };#endif /* __KERNEL__ */
include/linux/msg.h +1 -1
@@ -70,7 +70,7 @@ struct msg_msg {long m_type;int m_ts;/* message text size */ struct msg_msgseg * next; -void *security; +struct hlist_head security;/* the actual message follows immediately */ };
include/linux/sched.h +1 -1
@@ -721,7 +721,7 @@ struct task_struct {void *notifier_data;sigset_t *notifier_mask; -void *security; +struct hlist_head security;struct audit_context *audit_context;seccomp_t seccomp;
include/net/sock.h +1 -1
@@ -240,7 +240,7 @@ struct sock {struct sk_buff *sk_send_head;__u32 sk_sndmsg_off;int sk_write_pending; -void *sk_security; +struct hlist_head sk_security;void (*sk_state_change)(struct sock *sk);void (*sk_data_ready)(struct sock *sk,int bytes);void (*sk_write_space)(struct sock *sk);
ipc/msg.c +1 -1
@@ -99,7 +99,7 @@ static int newque (key_t key, int msgflg msq->q_perm.mode = (msgflg &S_IRWXUGO ); msq->q_perm.key = key; - msq->q_perm.security =NULL ; +INIT_HLIST_HEAD (&msq->q_perm.security); retval =security_msg_queue_alloc (msq);if (retval) {ipc_rcu_putref (msq);
ipc/msgutil.c +1 -1
@@ -41,7 +41,7 @@ struct msg_msg *load_msg(const void __usreturn ERR_PTR (-ENOMEM ); msg->next =NULL ; - msg->security =NULL ; +INIT_HLIST_HEAD (&msg->security);if (copy_from_user (msg +1 , src, alen)) { err = -EFAULT ;
ipc/sem.c +1 -1
@@ -178,7 +178,7 @@ static int newary (key_t key, int nsems, sma->sem_perm.mode = (semflg &S_IRWXUGO ); sma->sem_perm.key = key; - sma->sem_perm.security =NULL ; +INIT_HLIST_HEAD (&sma->sem_perm.security); retval =security_sem_alloc (sma);if (retval) {ipc_rcu_putref (sma);
ipc/shm.c +1 -1
@@ -199,7 +199,7 @@ static int newseg (key_t key, int shmflg shp->shm_flags = (shmflg &S_IRWXUGO ); shp->mlock_user =NULL ; - shp->shm_perm.security =NULL ; +INIT_HLIST_HEAD (&shp->shm_perm.security); error =security_shm_alloc (shp);if (error) {ipc_rcu_putref (shp);
kernel/fork.c +1 -1
@@ -941,7 +941,7 @@ static task_t *copy_process(unsigned lon p->lock_depth =-1 ;/* -1 = no lock */ do_posix_clock_monotonic_gettime (&p->start_time); - p->security =NULL ; +INIT_HLIST_HEAD (&p->security); p->io_context =NULL ; p->io_wait =NULL ; p->audit_context =NULL ;
PATCH 5/15 lsm stacking v0.3: introduce security_*_value API
In reply to [email protected]Define the functions to be used by LSMs to add, retrieve, and remove elements to the kernel object ->security hlists.
Changelog:
[July 26] Fixed prototypes which did not specify fastcall.
[July 26] Added security_unlink_value, for use by modules
to free data when they are unloaded, and security_disown_value, which is used when a module has not freed it's object->security data when object is being freed.
include/linux/security-stack.h | 25 +++++++ include/linux/security.h | 32 ++++++++++ security/security.c | 130 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+)
include/linux/security-stack.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* security-stack.h +* +* Contains function prototypes or inline definitions for the +* function which manipulate kernel object security annotations. +* +* If stacker is compiled in, then we use the full functions as +* defined in security/security.c. Otherwise we use the #defines +* here. +*/ + +extern fastcall struct security_list *security_get_value( +struct hlist_head *head, +int security_id); + +extern fastcall struct security_list *security_set_value( +struct hlist_head *head, +int security_id,struct security_list *obj_node); +extern fastcall struct security_list *security_add_value( +struct hlist_head *head, +int security_id,struct security_list *obj_node); +extern int security_unlink_value (struct hlist_node *n); +extern fastcall struct security_list *security_del_value( +struct hlist_head *head, +int security_id);
include/linux/security.h +32 -0
@@ -35,6 +35,38 @@ struct ctl_table;struct module ;/* +* structure to be embedded at top of each LSM's security +* objects. +*/ +struct security_list { +struct hlist_node list; +int security_id; +}; + + +/* +* These #defines present more convenient interfaces to +* LSMs for using the security{g,d,s}et_value functions. +*/ +#define security_get_value_type (head, id, type) ( { \ + struct security_list *v = security_get_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; } ) + +#define security_set_value_type (head, id, value) \ + security_set_value((head), id, &(value)->lsm_list); + +#define security_add_value_type (head, id, value) \ + security_add_value((head), id, &(value)->lsm_list); + +#define security_del_value_type (head, id, type) ( { \ + struct security_list *v; \ + v = security_del_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; } ) + +/* security_disown_value is really only to be used by stacker */ +extern void security_disown_value (struct hlist_head *); + +/* * These functions are in security/capability.c and are used * as the default capabilities functions */
security/security.c +130 -0
136 lines not on this page · raw message
PATCH 6/15 lsm stacking v0.3: stacker documentation
In reply to [email protected]Add documentation about stacker and its usage.
Changelog:
[Jul 26]: Update with information regarding safe LSM unloading,
and added the stacker locking rationale.
LSM-stacker-locking.txt | 77 ++++++++++++++++++++++ LSM-stacking.txt | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+)
Documentation/LSM-stacking.txt new file +166 -0
@@ -0,0 +1,166 @@ +------------ +LSM stacking +------------ + +This document consists of two parts. The first describes the stacker LSM. +The second describes what is needed from an LSM in order to permit it to +stack with other LSMs. + +-------------------------------------------------------- +stacker LSM - enable stacking multiple security modules. +-------------------------------------------------------- + +Stacker is compiled into the kernel. Find the "Stacker" option under +the Security submenu, and say 'Y'. Now, any security modules which are +loaded or compiled into the kernel will be managed by stacker. + +You may interact with stacker through its securityfs interface, located +under /sys/kernel/security/stacker/ (henceforth simply /security/stacker). +This consists of the following files: + +/security/stacker/lockdown: +Once you write to this file, you will no longer be able to load +LSMs. + +/security/stacker/list_modules: +Reading this file will show which LSMs are being stacked. + +/security/stacker/stop_responding: +Unregisters the /security/stacker directory, so that you can no longer +interact with stacker. + +/security/stacker/unload: +Disables the specified module. The module will actually still be +loaded, but will no longer be asked to mediate accesses or update +security information. Stacker will release it's refcount on the +module, so that after this you are able to rmmod the module. By +separating unload into these two steps, no cpu should be executing +any of the module's hooks by the time you rmmod, so that the module +can be safely freed. + +--------------------------------------------- +Readying an LSM for stacking with other LSMs. +--------------------------------------------- + +LSM stacking is not a simple matter. You must consider the cumulative +behavior of all stacked LSMs very carefully, as well as certain subtle +effects of the LSM implementation. Please do not try to stack arbitrary +modules! For instance, while SELinux and cap-stack should always be +used together, SELinux cannot be combined with the original capability +module. The reason for this is that capability enforces that a process +must have CAP_SYS_ADMIN when writing "security.*" extended attributes. +However selinux requires that non-CAP_SYS_ADMIN processes be able to +write security.selinux attributes, instead enforcing its own permission +check. More subtle interactions are certainly imaginable, such as a +first security module updating state on a kernel object such that a +second security module denies or allows the action when it otherwise +would not have. + +If you have any questions about the proper or actual behavior of +modules, whether existing or ones to be written by yourself, a good +place to engage in discussion is the lsm mailing list, [email protected]. Information about the mailing list can +be found at lsm.immunix.org. + +If your module will be annotating security information to kernel +objects, then you must use the provided API. The functions intended +for use by modules are defined in include/linux/security.h. A +good example of a user of these functions is the SELinux module. The +following describes the API usage. + +Assume you wish to annotate an instance of the following struct to an +inode: + +struct my_security_info { + int a; + struct list_head some_list; + spinlock_t lock; +}; + +At the top of the struct, you must add a struct security_list lsm_list, +as follows: + +struct my_security_info { ++ struct security_list lsm_list; + int count; + struct list_head some_list; + spinlock_t lock; +}; + +This will add the information which the API will need to tell your +information apart from that of other modules. You also need to define a +unique ID to distinguish information owned by your module. Usually +people "echo <module_name> | sha1sum" and use the first several digits. +For instance, if +#echo seclvl | sha1sum | awk --field-separator="" '{ print \ +$1$2$3$4$5$6$7$8 '} +40e81e47 + +then in your my_lsm.h, add +#define MY_LSM_ID 0x40e81e47 + +Do make sure that no other module happens to have the same ID. + +Now when the kernel object is created, you may use +security_set_value_type() to append the struct to the object's list of +security information. Note that you may ONLY use this while the kernel +object is being created, ie during the security_<KERNEL_OBJECT>_alloc +function. Since you are appending my_security_info to the inode, you +will do so during the security_inode_alloc() hook. For instance, + +static inline int my_inode_alloc(struct inode *inode) +{ + struct my_security_info *my_data; + + my_data = kmalloc(sizeof(struct my_security_info), GFP_KERNEL); + if (!my_data) + return -ENOMEM; + init_inode_data(my_data); + + security_set_value_type(&inode->i_security, MY_LSM_ID, my_data); +} + +If you need to append your information after the kernel object has been +created, you may do so using security_add_value_type() hook. However, +for both performance and security reasons, it is preferable to compile +your module into the kernel and always append your info while the object +is created. See security/seclvl.c or the digsig stacking patch for +examples of this usage. + +To get your information back, you may use security_get_value_type(). +For instance, + +static inline int my_inode_create(struct inode *dir, + struct dentry *dentry, + int mode) +{ + struct my_security_info *my_data; + + my_data = security_get_value_type(&dir->i_security, + MY_LSM_ID, struct my_security_info); + if (!my_data || my_data->count) + return -EPERM; + return 0; +} + +There are two ways of removing kernel object data for freeing. +If you can wait until security_<object>_free(), ie security_inode_free,() +then you may use + + my_data = security_del_value_type(&dir->i_security, + MY_LSM_ID, struct my_security_info); + kfree(my_data); + +See security/selinux/hooks.c for example usage. + +If you must free the data before the object is freed, because your +module is being unloaded, then you must use + + security_unlink_value(&dir->i_security->lsm_list.list); + +and wait a full rcu cycle before freeing the data in order to +ensure proper locking. See security/seclvl.c and the digsig +stacking patch for sample usage. Both of these modules simply +link together all the objects in one list_head chain, and, if +unloaded, unlink each object from the object, wait a full rcu +cycle, then walk the same chain again to free the objects.
Documentation/LSM-stacker-locking.txt new file +77 -0
77 lines not on this page · raw message
PATCH 7/15 lsm stacking v0.3: actual stacker module
In reply to [email protected]Adds the actual stacker LSM.
Changelog:
[July 26]:
sparse fixes - make dentries static, add __user to shmaddr in
stacker_shm_shmat.
security_disown_value after calling all modules' free function for any freed kernel object. It is expected that any LSM being unloaded will eventually call security_unlink_value(), which is safe only if we disown.
Fixed stacker_inode_{get,set,list}security bug pointed out by Stephen Smalley.
Switched to using securityfs.
vm_enough_memory was calling dummy_capable rather than stacker_capable.
try_module_get any loaded LSMs until someone asks for it to be unloaded, so that we can give time for all the LSMs functions to finish running before the module is freed.
Load dummy module if no modules have yet been stacked.
Share procattr among multiple LSMs, instead of only supporting SELinux. Data is now expected to be of the form
"data (module_name)"
If the "(module_name)" part is missing, we assume the data is intended for SELinux.
Support unloading of LSMs.
--
Kconfig | 6 Makefile | 1 stacker.c | 1664 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1671 insertions(+)
security/Kconfig +6 -0
@@ -87,5 +87,11 @@ config SECURITY_SECLVL source security/selinux/Kconfig +config SECURITY_STACKER + boolean "LSM Stacking" + depends on SECURITY + help + Stack multiple LSMs. + endmenu
security/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-$(CONFIG_KEYS) += keys/ +obj-$(CONFIG_SECURITY_STACKER) += stacker.o subdir-$(CONFIG_SECURITY_SELINUX) += selinux # if we don't select a security model, use the default capabilities
security/stacker.c new file +1664 -0
1,664 lines not on this page · raw message
PATCH 8/15 lsm stacking v0.3: stackable capabilities lsm
In reply to [email protected]This patch adds a version of the capability module which is safe to stack with SELinux. It notably does not define the inode_setxattr and inode_removexattr hooks, as these otherwise prevent selinux from saving file types to disk.
--
Kconfig | 21 +++++++++++ Makefile | 1 cap_stack.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ selinux/Kconfig | 2 + 4 files changed, 124 insertions(+), 1 deletion(-)
security/Kconfig +20 -1
@@ -56,10 +56,29 @@ config SECURITY_NETWORK config SECURITY_CAPABILITIES tristate "Default Linux Capabilities" depends on SECURITY + depends on SECURITY_SELINUX=n && SECURITY_CAP_STACK=n help - This enables the "default" Linux capabilities functionality. + This enables the default Linux capabilities functionality. + This module may not be used in conjunction with the stackable + capabilities or SELinux modules. + If you are unsure how to answer this question, answer Y. + If you are using SELinux, answer N here and look at the + Stackable Linux Capabilities instead. + +config SECURITY_CAP_STACK + tristate "Stackable Linux Capabilities" + depends on SECURITY + help + This enables the "stackable" Linux capabilities functionality. + + If you are using SELinux, this option will be automatically + enabled. + + If you are not using any other LSMs, answer N here and see above + for the Default Linux Capabilities. + config SECURITY_ROOTPLUG tristate "Root Plug Support" depends on USB && SECURITY
security/Makefile +1 -0
@@ -16,5 +16,6 @@ obj-$(CONFIG_SECURITY) += security.o d # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o +obj-$(CONFIG_SECURITY_CAP_STACK) += commoncap.o cap_stack.o obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o
security/cap_stack.c new file +101 -0
101 lines not on this page · raw message
security/selinux/Kconfig +2 -0
@@ -2,6 +2,8 @@ config SECURITY_SELINUX bool "NSA SELinux Support" depends on SECURITY && NET && INET default n + select SECURITY_CAP_STACK + select SECURITY_STACKER help This selects NSA Security-Enhanced Linux (SELinux). You will also need a policy configuration and a labeled filesystem.
PATCH 9/15 lsm stacking v0.3: selinux: update ->security structs
In reply to [email protected]Add the struct security_list lsm_list; to each structure which SELinux will be appending to a kernel object.
--
objsec.h | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-)
security/selinux/include/objsec.h +11 -8
@@ -23,11 +23,14 @@#include <linux/fs.h> #include <linux/binfmts.h> #include <linux/in.h> +#include <linux/security.h> #include "flask.h" #include "avc.h" +#define SELINUX_LSM_ID 0xB65 +struct task_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct task_struct *task;/* back pointer to task object */ u32 osid;/* SID prior to last execve */ u32 sid;/* current SID */
@@ -37,7 +40,7 @@ struct task_security_struct { };struct inode_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct inode *inode;/* back pointer to inode object */ struct list_head list;/* list of inode_security_struct */ u32 task_sid;/* SID of creating task */
@@ -49,14 +52,14 @@ struct inode_security_struct { };struct file_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct file *file;/* back pointer to file object */ u32 sid;/* SID of open file description */ u32 fown_sid;/* SID of file owner (for SIGIO) */ };struct superblock_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct super_block *sb;/* back pointer to sb object */ struct list_head list;/* list of superblock_security_struct */ u32 sid;/* SID of file system */
@@ -70,20 +73,20 @@ struct superblock_security_struct { };struct msg_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct msg_msg *msg;/* back pointer */ u32 sid;/* SID of message */ };struct ipc_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct kern_ipc_perm *ipc_perm;/* back pointer */ u16 sclass;/* security class of this object */ u32 sid;/* SID of IPC resource */ };struct bprm_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct linux_binprm *bprm;/* back pointer to bprm object */ u32 sid;/* SID for transformed process */ unsigned char set;
@@ -102,7 +105,7 @@ struct netif_security_struct { };struct sk_security_struct { -unsigned long magic;/* magic number for this module */ +struct security_list lsm_list;/* chained security objects */ struct sock *sk;/* back pointer to sk object */ u32 peer_sid;/* SID of peer */ };
PATCH 10/15 lsm stacking v0.3: selinux: use security_*_value API
In reply to [email protected]Convert SELinux to use the security_*_value_type API for storing and using information appended to kernel objects, instead of directly using the void*.
--
hooks.c | 446 +++++++++++++++++++++++++++++++++++++++--------------------- selinuxfs.c | 10 - 2 files changed, 300 insertions(+), 156 deletions(-)
security/selinux/hooks.c +293 -153
@@ -26,6 +26,7 @@#include <linux/errno.h> #include <linux/sched.h> #include <linux/security.h> +#include <linux/security-stack.h> #include <linux/xattr.h> #include <linux/capability.h> #include <linux/unistd.h>
@@ -127,30 +128,30 @@ static int task_alloc_security(struct tareturn -ENOMEM ;memset (tsec,0 ,sizeof (struct task_security_struct )); - tsec->magic =SELINUX_MAGIC ; tsec->task = task; tsec->osid = tsec->sid = tsec->ptrace_sid =SECINITSID_UNLABELED ; - task->security = tsec; +security_set_value_type (&task->security,SELINUX_LSM_ID , tsec);return 0 ; }static void task_free_security (struct task_struct *task) { -struct task_security_struct *tsec = task->security; - -if (!tsec || tsec->magic !=SELINUX_MAGIC ) -return ; +struct task_security_struct *tsec; + + tsec =security_del_value_type (&task->security,SELINUX_LSM_ID , + struct task_security_struct); - task->security =NULL ;kfree (tsec); }static int inode_alloc_security (struct inode *inode) { -struct task_security_struct *tsec = current->security; +struct task_security_struct *tsec;struct inode_security_struct *isec; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); isec =kmalloc (sizeof (struct inode_security_struct ),GFP_KERNEL );if (!isec)return -ENOMEM ;
@@ -158,68 +159,71 @@ static int inode_alloc_security(struct imemset (isec,0 ,sizeof (struct inode_security_struct ));init_MUTEX (&isec->sem);INIT_LIST_HEAD (&isec->list); - isec->magic =SELINUX_MAGIC ; isec->inode = inode; isec->sid =SECINITSID_UNLABELED ; isec->sclass =SECCLASS_FILE ; -if (tsec && tsec->magic ==SELINUX_MAGIC ) +if (tsec) isec->task_sid = tsec->sid;else isec->task_sid =SECINITSID_UNLABELED ; - inode->i_security = isec; +security_set_value_type (&inode->i_security,SELINUX_LSM_ID , isec);return 0 ; }static void inode_free_security (struct inode *inode) { -struct inode_security_struct *isec = inode->i_security; -struct superblock_security_struct *sbsec = inode->i_sb->s_security; +struct inode_security_struct *isec; +struct superblock_security_struct *sbsec; -if (!isec || isec->magic !=SELINUX_MAGIC ) + isec =security_del_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); +if (!isec)return ; + sbsec =security_get_value_type (&inode->i_sb->s_security, + SELINUX_LSM_ID, struct superblock_security_struct); +spin_lock (&sbsec->isec_lock);if (!list_empty (&isec->list))list_del_init (&isec->list);spin_unlock (&sbsec->isec_lock); - inode->i_security =NULL ;kfree (isec); }static int file_alloc_security (struct file *file) { -struct task_security_struct *tsec = current->security; +struct task_security_struct *tsec;struct file_security_struct *fsec; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); fsec =kmalloc (sizeof (struct file_security_struct ),GFP_ATOMIC );if (!fsec)return -ENOMEM ;memset (fsec,0 ,sizeof (struct file_security_struct )); - fsec->magic =SELINUX_MAGIC ; fsec->file = file; -if (tsec && tsec->magic ==SELINUX_MAGIC ) { +if (tsec) { fsec->sid = tsec->sid; fsec->fown_sid = tsec->sid; }else { fsec->sid =SECINITSID_UNLABELED ; fsec->fown_sid =SECINITSID_UNLABELED ; } - file->f_security = fsec; +security_set_value_type (&file->f_security,SELINUX_LSM_ID , fsec);return 0 ; }static void file_free_security (struct file *file) { -struct file_security_struct *fsec = file->f_security; +struct file_security_struct *fsec; -if (!fsec || fsec->magic !=SELINUX_MAGIC ) -return ; + fsec =security_del_value_type (&file->f_security,SELINUX_LSM_ID , + struct file_security_struct); - file->f_security =NULL ;kfree (fsec); }
@@ -236,20 +240,21 @@ static int superblock_alloc_security(strINIT_LIST_HEAD (&sbsec->list);INIT_LIST_HEAD (&sbsec->isec_head);spin_lock_init (&sbsec->isec_lock); - sbsec->magic =SELINUX_MAGIC ; sbsec->sb = sb; sbsec->sid =SECINITSID_UNLABELED ; sbsec->def_sid =SECINITSID_FILE ; - sb->s_security = sbsec; +security_set_value_type (&sb->s_security,SELINUX_LSM_ID , sbsec);return 0 ; }static void superblock_free_security (struct super_block *sb) { -struct superblock_security_struct *sbsec = sb->s_security; +struct superblock_security_struct *sbsec; -if (!sbsec || sbsec->magic !=SELINUX_MAGIC ) + sbsec =security_del_value_type (&sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct); +if (!sbsec)return ;spin_lock (&sb_security_lock);
@@ -257,7 +262,6 @@ static void superblock_free_security(strlist_del_init (&sbsec->list);spin_unlock (&sb_security_lock); - sb->s_security =NULL ;kfree (sbsec); }
@@ -274,22 +278,23 @@ static int sk_alloc_security(struct sockreturn -ENOMEM ;memset (ssec,0 ,sizeof (*ssec)); - ssec->magic =SELINUX_MAGIC ; ssec->sk = sk; ssec->peer_sid =SECINITSID_UNLABELED ; - sk->sk_security = ssec; +security_set_value_type (&sk->sk_security,SELINUX_LSM_ID , ssec);return 0 ; }static void sk_free_security (struct sock *sk) { -struct sk_security_struct *ssec = sk->sk_security; +struct sk_security_struct *ssec; -if (sk->sk_family !=PF_UNIX || ssec->magic !=SELINUX_MAGIC ) +if (sk->sk_family !=PF_UNIX )return ; - sk->sk_security =NULL ; + ssec =security_del_value_type (&sk->sk_security,SELINUX_LSM_ID , + struct sk_security_struct); +kfree (ssec); }#endif /* CONFIG_SECURITY_NETWORK */
@@ -336,8 +341,13 @@ static int try_context_mount(struct supeconst char *name;u32 sid;int alloc =0 , rc =0 , seen =0 ; -struct task_security_struct *tsec = current->security; -struct superblock_security_struct *sbsec = sb->s_security; +struct task_security_struct *tsec; +struct superblock_security_struct *sbsec; + + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + sbsec =security_get_value_type (&sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct);if (!data) goto out;
@@ -503,11 +513,14 @@ out:static int superblock_doinit (struct super_block *sb,void *data) { -struct superblock_security_struct *sbsec = sb->s_security; +struct superblock_security_struct *sbsec;struct dentry *root = sb->s_root;struct inode *inode = root->d_inode;int rc =0 ; + sbsec =security_get_value_type (&sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct); +down (&sbsec->sem);if (sbsec->initialized) goto out;
@@ -732,7 +745,7 @@ static int selinux_proc_get_sid(struct pstatic int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry) {struct superblock_security_struct *sbsec =NULL ; -struct inode_security_struct *isec = inode->i_security; +struct inode_security_struct *isec;u32 sid;struct dentry *dentry;#define INITCONTEXTLEN 255
@@ -741,6 +754,9 @@ static int inode_doinit_with_dentry(struint rc =0 ;int hold_sem =0 ; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); +if (isec->initialized) goto out;
@@ -749,7 +765,8 @@ static int inode_doinit_with_dentry(struif (isec->initialized) goto out; - sbsec = inode->i_sb->s_security; + sbsec =security_get_value_type (&inode->i_sb->s_security, + SELINUX_LSM_ID, struct superblock_security_struct);if (!sbsec->initialized) {/* Defer initialization until selinux_complete_init, after the initial policy is loaded and the security
@@ -923,8 +940,10 @@ static int task_has_perm(struct task_str {struct task_security_struct *tsec1, *tsec2; - tsec1 = tsk1->security; - tsec2 = tsk2->security; + tsec1 =security_get_value_type (&tsk1->security,SELINUX_LSM_ID , + struct task_security_struct); + tsec2 =security_get_value_type (&tsk2->security,SELINUX_LSM_ID , + struct task_security_struct);return avc_has_perm (tsec1->sid, tsec2->sid,SECCLASS_PROCESS , perms,NULL ); }
@@ -936,7 +955,8 @@ static int task_has_capability(struct tastruct task_security_struct *tsec;struct avc_audit_data ad; - tsec = tsk->security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct);AVC_AUDIT_DATA_INIT (&ad,CAP ); ad.tsk = tsk;
@@ -952,7 +972,8 @@ static int task_has_system(struct task_s {struct task_security_struct *tsec; - tsec = tsk->security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct);return avc_has_perm (tsec->sid,SECINITSID_KERNEL ,SECCLASS_SYSTEM , perms,NULL );
@@ -970,8 +991,10 @@ static int inode_has_perm(struct task_ststruct inode_security_struct *isec;struct avc_audit_data ad; - tsec = tsk->security; - isec = inode->i_security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct);if (!adp) { adp = &ad;
@@ -1010,14 +1033,19 @@ static inline int file_has_perm(struct t struct file *file, u32 av) { -struct task_security_struct *tsec = tsk->security; -struct file_security_struct *fsec = file->f_security; +struct task_security_struct *tsec; +struct file_security_struct *fsec;struct vfsmount *mnt = file->f_vfsmnt;struct dentry *dentry = file->f_dentry;struct inode *inode = dentry->d_inode;struct avc_audit_data ad;int rc; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct); + fsec =security_get_value_type (&file->f_security,SELINUX_LSM_ID , + struct file_security_struct); +AVC_AUDIT_DATA_INIT (&ad,FS ); ad.u.fs.mnt = mnt; ad.u.fs.dentry = dentry;
@@ -1050,9 +1078,12 @@ static int may_create(struct inode *dir,struct avc_audit_data ad;int rc; - tsec = current->security; - dsec = dir->i_security; - sbsec = dir->i_sb->s_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + dsec =security_get_value_type (&dir->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + sbsec =security_get_value_type (&dir->i_sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct);AVC_AUDIT_DATA_INIT (&ad,FS ); ad.u.fs.dentry = dentry;
@@ -1097,9 +1128,12 @@ static int may_link(struct inode *dir,u32 av;int rc; - tsec = current->security; - dsec = dir->i_security; - isec = dentry->d_inode->i_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + dsec =security_get_value_type (&dir->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + isec =security_get_value_type (&dentry->d_inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct);AVC_AUDIT_DATA_INIT (&ad,FS ); ad.u.fs.dentry = dentry;
@@ -1141,11 +1175,15 @@ static inline int may_rename(struct inodint old_is_dir, new_is_dir;int rc; - tsec = current->security; - old_dsec = old_dir->i_security; - old_isec = old_dentry->d_inode->i_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + old_dsec =security_get_value_type (&old_dir->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + old_isec =security_get_value_type (&old_dentry->d_inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct); old_is_dir =S_ISDIR (old_dentry->d_inode->i_mode); - new_dsec = new_dir->i_security; + new_dsec =security_get_value_type (&new_dir->i_security,SELINUX_LSM_ID , + struct inode_security_struct);AVC_AUDIT_DATA_INIT (&ad,FS );
@@ -1173,7 +1211,8 @@ static inline int may_rename(struct inodif (rc)return rc;if (new_dentry->d_inode) { - new_isec = new_dentry->d_inode->i_security; + new_isec =security_get_value_type (&new_dentry->d_inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct); new_is_dir =S_ISDIR (new_dentry->d_inode->i_mode); rc = avc_has_perm(tsec->sid, new_isec->sid, new_isec->sclass,
@@ -1194,8 +1233,10 @@ static int superblock_has_perm(struct tastruct task_security_struct *tsec;struct superblock_security_struct *sbsec; - tsec = tsk->security; - sbsec = sb->s_security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct); + sbsec =security_get_value_type (&sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct);return avc_has_perm (tsec->sid, sbsec->sid,SECCLASS_FILESYSTEM , perms, ad); }
@@ -1248,8 +1289,13 @@ static inline u32 file_to_av(struct file/* Set an inode's SID to a specified value. */ static int inode_security_set_sid (struct inode *inode,u32 sid) { -struct inode_security_struct *isec = inode->i_security; -struct superblock_security_struct *sbsec = inode->i_sb->s_security; +struct inode_security_struct *isec; +struct superblock_security_struct *sbsec; + + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + sbsec =security_get_value_type (&inode->i_sb->s_security, + SELINUX_LSM_ID, struct superblock_security_struct);if (!sbsec->initialized) {/* Defer initialization to selinux_complete_init. */
@@ -1278,9 +1324,12 @@ static int post_create(struct inode *dirunsigned int len;int rc; - tsec = current->security; - dsec = dir->i_security; - sbsec = dir->i_sb->s_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + dsec =security_get_value_type (&dir->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + sbsec =security_get_value_type (&dir->i_sb->s_security,SELINUX_LSM_ID , + struct superblock_security_struct); inode = dentry->d_inode;if (!inode) {
@@ -1347,13 +1396,17 @@ static int post_create(struct inode *dirstatic int selinux_ptrace (struct task_struct *parent,struct task_struct *child) { -struct task_security_struct *psec = parent->security; -struct task_security_struct *csec = child->security; +struct task_security_struct *psec; +struct task_security_struct *csec;int rc; rc = secondary_ops->ptrace (parent,child);if (rc)return rc; + psec =security_get_value_type (&parent->security,SELINUX_LSM_ID , + struct task_security_struct); + csec =security_get_value_type (&child->security,SELINUX_LSM_ID , + struct task_security_struct); rc =task_has_perm (parent, child,PROCESS__PTRACE );/* Save the SID of the tracing process for later use in apply_creds. */
@@ -1415,7 +1468,8 @@ static int selinux_sysctl(ctl_table *tabif (rc)return rc; - tsec = current->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); rc =selinux_proc_get_sid (table->de, (op ==001 ) ?SECCLASS_DIR :SECCLASS_FILE , &tsid);
@@ -1550,12 +1604,11 @@ static int selinux_bprm_alloc_security(sreturn -ENOMEM ;memset (bsec,0 ,sizeof *bsec); - bsec->magic =SELINUX_MAGIC ; bsec->bprm = bprm; bsec->sid =SECINITSID_UNLABELED ; bsec->set =0 ; - bprm->security = bsec; +security_set_value_type (&bprm->security,SELINUX_LSM_ID , bsec);return 0 ; }
@@ -1573,13 +1626,16 @@ static int selinux_bprm_set_security(strif (rc)return rc; - bsec = bprm->security; + bsec =security_get_value_type (&bprm->security,SELINUX_LSM_ID , + struct bprm_security_struct);if (bsec->set)return 0 ; - tsec = current->security; - isec = inode->i_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct);/* Default to the current task SID. */ bsec->sid = tsec->sid;
@@ -1642,9 +1698,11 @@ static int selinux_bprm_check_security (static int selinux_bprm_secureexec (struct linux_binprm *bprm) { -struct task_security_struct *tsec = current->security; +struct task_security_struct *tsec;int atsecure =0 ; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct);if (tsec->osid != tsec->sid) {/* Enable secure mode for SIDs transitions unless the noatsecure permission is granted between
@@ -1659,8 +1717,11 @@ static int selinux_bprm_secureexec (strustatic void selinux_bprm_free_security (struct linux_binprm *bprm) { -kfree (bprm->security); - bprm->security =NULL ; +struct bprm_security_struct *bsec; + + bsec =security_del_value_type (&bprm->security,SELINUX_LSM_ID , + struct bprm_security_struct); +kfree (bsec); }extern struct vfsmount *selinuxfs_mount;
@@ -1757,9 +1818,10 @@ static void selinux_bprm_apply_creds(str secondary_ops->bprm_apply_creds (bprm, unsafe); - tsec = current->security; - - bsec = bprm->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + bsec =security_get_value_type (&bprm->security,SELINUX_LSM_ID , + struct bprm_security_struct); sid = bsec->sid; tsec->osid = tsec->sid;
@@ -1802,8 +1864,10 @@ static void selinux_bprm_post_apply_credstruct bprm_security_struct *bsec;int rc, i; - tsec = current->security; - bsec = bprm->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + bsec =security_get_value_type (&bprm->security,SELINUX_LSM_ID , + struct bprm_security_struct);if (bsec->unsafe) {force_sig_specific (SIGKILL , current);
@@ -2163,9 +2227,9 @@ static int selinux_inode_getattr(structstatic int selinux_inode_setxattr (struct dentry *dentry,char *name,void *value,size_t size,int flags) { -struct task_security_struct *tsec = current->security; +struct task_security_struct *tsec;struct inode *inode = dentry->d_inode; -struct inode_security_struct *isec = inode->i_security; +struct inode_security_struct *isec;struct superblock_security_struct *sbsec;struct avc_audit_data ad;u32 newsid;
@@ -2185,7 +2249,8 @@ static int selinux_inode_setxattr(structreturn dentry_has_perm (current,NULL , dentry,FILE__SETATTR ); } - sbsec = inode->i_sb->s_security; + sbsec =security_get_value_type (&inode->i_sb->s_security, + SELINUX_LSM_ID, struct superblock_security_struct);if (sbsec->behavior ==SECURITY_FS_USE_MNTPOINT )return -EOPNOTSUPP ;
@@ -2195,6 +2260,10 @@ static int selinux_inode_setxattr(structAVC_AUDIT_DATA_INIT (&ad,FS ); ad.u.fs.dentry = dentry; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); rc =avc_has_perm (tsec->sid, isec->sid, isec->sclass,FILE__RELABELFROM , &ad);if (rc)
@@ -2225,10 +2294,13 @@ static void selinux_inode_post_setxattr( void *value, size_t size, int flags) {struct inode *inode = dentry->d_inode; -struct inode_security_struct *isec = inode->i_security; +struct inode_security_struct *isec;u32 newsid;int rc; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); +if (strcmp (name,XATTR_NAME_SELINUX )) {/* Not an attribute we recognize, so nothing to do. */ return ;
@@ -2248,7 +2320,10 @@ static void selinux_inode_post_setxattr(static int selinux_inode_getxattr (struct dentry *dentry,char *name) {struct inode *inode = dentry->d_inode; -struct superblock_security_struct *sbsec = inode->i_sb->s_security; +struct superblock_security_struct *sbsec; + + sbsec =security_get_value_type (&inode->i_sb->s_security, + SELINUX_LSM_ID, struct superblock_security_struct);if (sbsec->behavior ==SECURITY_FS_USE_MNTPOINT )return -EOPNOTSUPP ;
@@ -2285,7 +2360,7 @@ static int selinux_inode_removexattr (ststatic int selinux_inode_getsecurity (struct inode *inode,const char *name,void *buffer,size_t size) { -struct inode_security_struct *isec = inode->i_security; +struct inode_security_struct *isec;char *context;unsigned len;int rc;
@@ -2295,6 +2370,9 @@ static int selinux_inode_getsecurity(strif (strcmp (name,XATTR_SELINUX_SUFFIX ))return -EOPNOTSUPP ; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); + rc =security_sid_to_context (isec->sid, &context, &len);if (rc)return rc;
@@ -2315,13 +2393,16 @@ static int selinux_inode_getsecurity(strstatic int selinux_inode_setsecurity (struct inode *inode,const char *name,const void *value,size_t size,int flags) { -struct inode_security_struct *isec = inode->i_security; +struct inode_security_struct *isec;u32 newsid;int rc;if (strcmp (name,XATTR_SELINUX_SUFFIX ))return -EOPNOTSUPP ; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); +if (!value || !size)return -EACCES ;
@@ -2568,8 +2649,10 @@ static int selinux_file_set_fowner(strucstruct task_security_struct *tsec;struct file_security_struct *fsec; - tsec = current->security; - fsec = file->f_security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + fsec =security_get_value_type (&file->f_security,SELINUX_LSM_ID , + struct file_security_struct); fsec->fown_sid = tsec->sid;return 0 ;
@@ -2586,8 +2669,10 @@ static int selinux_file_send_sigiotask(s/* struct fown_struct is never outside the context of a struct file */ file = (struct file *)((long )fown - offsetof(struct file ,f_owner)); - tsec = tsk->security; - fsec = file->f_security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct); + fsec =security_get_value_type (&file->f_security,SELINUX_LSM_ID , + struct file_security_struct);if (!signum) perm =signal_to_av (SIGIO );/* as per send_sigio_to_task */
@@ -2621,12 +2706,14 @@ static int selinux_task_alloc_security(sstruct task_security_struct *tsec1, *tsec2;int rc; - tsec1 = current->security; + tsec1 =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); rc =task_alloc_security (tsk);if (rc)return rc; - tsec2 = tsk->security; + tsec2 =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct); tsec2->osid = tsec1->osid; tsec2->sid = tsec1->sid;
@@ -2779,7 +2866,8 @@ static void selinux_task_reparent_to_ini secondary_ops->task_reparent_to_init (p); - tsec = p->security; + tsec =security_get_value_type (&p->security,SELINUX_LSM_ID , + struct task_security_struct); tsec->osid = tsec->sid; tsec->sid =SECINITSID_KERNEL ;return ;
@@ -2788,8 +2876,13 @@ static void selinux_task_reparent_to_inistatic void selinux_task_to_inode (struct task_struct *p,struct inode *inode) { -struct task_security_struct *tsec = p->security; -struct inode_security_struct *isec = inode->i_security; +struct task_security_struct *tsec; +struct inode_security_struct *isec; + + tsec =security_get_value_type (&p->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); isec->sid = tsec->sid; isec->initialized =1 ;
@@ -2957,8 +3050,10 @@ static int socket_has_perm(struct task_sstruct avc_audit_data ad;int err =0 ; - tsec = task->security; - isec =SOCK_INODE (sock)->i_security; + tsec =security_get_value_type (&task->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&SOCK_INODE (sock)->i_security,SELINUX_LSM_ID , + struct inode_security_struct);if (isec->sid ==SECINITSID_KERNEL ) goto out;
@@ -2980,7 +3075,8 @@ static int selinux_socket_create(int famif (kern) goto out; - tsec = current->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); err =avc_has_perm (tsec->sid, tsec->sid,socket_type_to_security_class (family, type, protocol),SOCKET__CREATE ,NULL );
@@ -2995,9 +3091,11 @@ static void selinux_socket_post_create(sstruct inode_security_struct *isec;struct task_security_struct *tsec; - isec =SOCK_INODE (sock)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct); - tsec = current->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); isec->sclass =socket_type_to_security_class (family, type, protocol); isec->sid = kern ?SECINITSID_KERNEL : tsec->sid; isec->initialized =1 ;
@@ -3035,8 +3133,10 @@ static int selinux_socket_bind(struct sostruct sock *sk = sock->sk;u32 sid, node_perm, addrlen; - tsec = current->security; - isec =SOCK_INODE (sock)->i_security; + tsec =security_get_value_type (¤t->security, + SELINUX_LSM_ID, struct task_security_struct); + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);if (family ==PF_INET ) { addr4 = (struct sockaddr_in *)address;
@@ -3114,7 +3214,8 @@ static int selinux_socket_connect(struct/* * If a TCP socket, check name_connect permission for the port. */ - isec =SOCK_INODE (sock)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);if (isec->sclass ==SECCLASS_TCP_SOCKET ) {struct sock *sk = sock->sk;struct avc_audit_data ad;
@@ -3168,9 +3269,11 @@ static int selinux_socket_accept(structif (err)return err; - newisec =SOCK_INODE (newsock)->i_security; + newisec =security_get_value_type (&SOCK_INODE (newsock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct); - isec =SOCK_INODE (sock)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct); newisec->sclass = isec->sclass; newisec->sid = isec->sid; newisec->initialized =1 ;
@@ -3230,8 +3333,10 @@ static int selinux_socket_unix_stream_coif (err)return err; - isec =SOCK_INODE (sock)->i_security; - other_isec =SOCK_INODE (other)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct); + other_isec =security_get_value_type (&SOCK_INODE (other)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);AVC_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.sk = other->sk;
@@ -3243,11 +3348,13 @@ static int selinux_socket_unix_stream_coreturn err;/* connecting socket */ - ssec = sock->sk->sk_security; + ssec =security_get_value_type (&sock->sk->sk_security,SELINUX_LSM_ID , + struct sk_security_struct); ssec->peer_sid = other_isec->sid;/* server child socket */ - ssec = newsk->sk_security; + ssec =security_get_value_type (&newsk->sk_security,SELINUX_LSM_ID , + struct sk_security_struct); ssec->peer_sid = isec->sid;return 0 ;
@@ -3261,8 +3368,10 @@ static int selinux_socket_unix_may_send(struct avc_audit_data ad;int err; - isec =SOCK_INODE (sock)->i_security; - other_isec =SOCK_INODE (other)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct); + other_isec =security_get_value_type (&SOCK_INODE (other)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);AVC_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.sk = other->sk;
@@ -3302,7 +3411,8 @@ static int selinux_socket_sock_rcv_skb(s inode =SOCK_INODE (sock);if (inode) {struct inode_security_struct *isec; - isec = inode->i_security; + isec =security_get_value_type (&inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct); sock_sid = isec->sid; sock_class = isec->sclass; }
@@ -3385,13 +3495,15 @@ static int selinux_socket_getpeersec(strstruct sk_security_struct *ssec;struct inode_security_struct *isec; - isec =SOCK_INODE (sock)->i_security; + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);if (isec->sclass !=SECCLASS_UNIX_STREAM_SOCKET ) { err = -ENOPROTOOPT ; goto out; } - ssec = sock->sk->sk_security; + ssec =security_get_value_type (&sock->sk->sk_security,SELINUX_LSM_ID , + struct sk_security_struct); err =security_sid_to_context (ssec->peer_sid, &scontext, &scontext_len);if (err)
@@ -3430,7 +3542,10 @@ static int selinux_nlmsg_perm(struct socu32 perm;struct nlmsghdr *nlh;struct socket *sock = sk->sk_socket; -struct inode_security_struct *isec =SOCK_INODE (sock)->i_security; +struct inode_security_struct *isec; + + isec =security_get_value_type (&SOCK_INODE (sock)->i_security, + SELINUX_LSM_ID, struct inode_security_struct);if (skb->len <NLMSG_SPACE (0 )) { err = -EINVAL ;
@@ -3496,7 +3611,8 @@ static unsigned int selinux_ip_postrouteif (err) goto out; - isec = inode->i_security; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct);switch (isec->sclass) {case SECCLASS_UDP_SOCKET :
@@ -3606,7 +3722,8 @@ static int selinux_netlink_send(struct sif (err)return err; - tsec = current->security; + tsec =security_get_value_type (¤t->security, + SELINUX_LSM_ID, struct task_security_struct); avd.allowed =0 ; avc_has_perm_noaudit(tsec->sid, tsec->sid,
@@ -3630,15 +3747,17 @@ static int ipc_alloc_security(struct tas struct kern_ipc_perm *perm, u16 sclass) { -struct task_security_struct *tsec = task->security; +struct task_security_struct *tsec;struct ipc_security_struct *isec; + tsec =security_get_value_type (&task->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =kmalloc (sizeof (struct ipc_security_struct ),GFP_KERNEL );if (!isec)return -ENOMEM ;memset (isec,0 ,sizeof (struct ipc_security_struct )); - isec->magic =SELINUX_MAGIC ; isec->sclass = sclass; isec->ipc_perm = perm;if (tsec) {
@@ -3646,18 +3765,18 @@ static int ipc_alloc_security(struct tas }else { isec->sid =SECINITSID_UNLABELED ; } - perm->security = isec; +security_set_value_type (&perm->security,SELINUX_LSM_ID , isec);return 0 ; }static void ipc_free_security (struct kern_ipc_perm *perm) { -struct ipc_security_struct *isec = perm->security; -if (!isec || isec->magic !=SELINUX_MAGIC ) -return ; +struct ipc_security_struct *isec; + + isec =security_del_value_type (&perm->security,SELINUX_LSM_ID , + struct ipc_security_struct); - perm->security =NULL ;kfree (isec); }
@@ -3670,21 +3789,20 @@ static int msg_msg_alloc_security(structreturn -ENOMEM ;memset (msec,0 ,sizeof (struct msg_security_struct )); - msec->magic =SELINUX_MAGIC ; msec->msg = msg; msec->sid =SECINITSID_UNLABELED ; - msg->security = msec; +security_set_value_type (&msg->security,SELINUX_LSM_ID , msec);return 0 ; }static void msg_msg_free_security (struct msg_msg *msg) { -struct msg_security_struct *msec = msg->security; -if (!msec || msec->magic !=SELINUX_MAGIC ) -return ; +struct msg_security_struct *msec; + + msec =security_del_value_type (&msg->security,SELINUX_LSM_ID , + struct msg_security_struct); - msg->security =NULL ;kfree (msec); }
@@ -3695,8 +3813,10 @@ static int ipc_has_perm(struct kern_ipc_struct ipc_security_struct *isec;struct avc_audit_data ad; - tsec = current->security; - isec = ipc_perms->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&ipc_perms->security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = ipc_perms->key;
@@ -3726,8 +3846,10 @@ static int selinux_msg_queue_alloc_securif (rc)return rc; - tsec = current->security; - isec = msq->q_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&msq->q_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = msq->q_perm.key;
@@ -3752,8 +3874,10 @@ static int selinux_msg_queue_associate(sstruct ipc_security_struct *isec;struct avc_audit_data ad; - tsec = current->security; - isec = msq->q_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&msq->q_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = msq->q_perm.key;
@@ -3798,9 +3922,12 @@ static int selinux_msg_queue_msgsnd(strustruct avc_audit_data ad;int rc; - tsec = current->security; - isec = msq->q_perm.security; - msec = msg->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&msq->q_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct); + msec =security_get_value_type (&msg->security,SELINUX_LSM_ID , + struct msg_security_struct);/* * First time through, need to assign label to the message
@@ -3846,9 +3973,12 @@ static int selinux_msg_queue_msgrcv(strustruct avc_audit_data ad;int rc; - tsec = target->security; - isec = msq->q_perm.security; - msec = msg->security; + tsec =security_get_value_type (&target->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&msq->q_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct); + msec =security_get_value_type (&msg->security,SELINUX_LSM_ID , + struct msg_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = msq->q_perm.key;
@@ -3873,8 +4003,10 @@ static int selinux_shm_alloc_security(stif (rc)return rc; - tsec = current->security; - isec = shp->shm_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&shp->shm_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = shp->shm_perm.key;
@@ -3899,8 +4031,10 @@ static int selinux_shm_associate(structstruct ipc_security_struct *isec;struct avc_audit_data ad; - tsec = current->security; - isec = shp->shm_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&shp->shm_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = shp->shm_perm.key;
@@ -3972,8 +4106,10 @@ static int selinux_sem_alloc_security(stif (rc)return rc; - tsec = current->security; - isec = sma->sem_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&sma->sem_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = sma->sem_perm.key;
@@ -3998,8 +4134,10 @@ static int selinux_sem_associate(structstruct ipc_security_struct *isec;struct avc_audit_data ad; - tsec = current->security; - isec = sma->sem_perm.security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); + isec =security_get_value_type (&sma->sem_perm.security,SELINUX_LSM_ID , + struct ipc_security_struct);AVC_AUDIT_DATA_INIT (&ad,IPC ); ad.u.ipc_id = sma->sem_perm.key;
@@ -4133,7 +4271,8 @@ static int selinux_getprocattr(struct taif (!size)return -ERANGE ; - tsec = p->security; + tsec =security_get_value_type (&p->security,SELINUX_LSM_ID , + struct task_security_struct);if (!strcmp (name,"current" )) sid = tsec->sid;
@@ -4208,7 +4347,8 @@ static int selinux_setprocattr(struct taoperation. See selinux_bprm_set_security for the execve checks and may_create for the file creation checks. The operation will then fail if the context is not permitted. */ - tsec = p->security; + tsec =security_get_value_type (&p->security,SELINUX_LSM_ID , + struct task_security_struct);if (!strcmp (name,"exec" )) tsec->exec_sid = sid;else if (!strcmp (name,"fscreate" ))
security/selinux/selinuxfs.c +7 -3
@@ -18,6 +18,7 @@#include <linux/init.h> #include <linux/string.h> #include <linux/security.h> +#include <linux/security-stack.h> #include <linux/major.h> #include <linux/seq_file.h> #include <linux/percpu.h>
@@ -59,7 +60,8 @@ static int task_has_security(struct task {struct task_security_struct *tsec; - tsec = tsk->security; + tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , + struct task_security_struct);if (!tsec)return -EACCES ;
@@ -982,7 +984,8 @@ static int sel_make_bools(void) ret = -ENAMETOOLONG ; goto err; } - isec = (struct inode_security_struct *)inode->i_security; + isec =security_get_value_type (&inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct);if ((ret =security_genfs_sid ("selinuxfs" , page,SECCLASS_FILE , &sid))) goto err; isec->sid = sid;
@@ -1267,7 +1270,8 @@ static int sel_fill_super(struct super_b inode =sel_make_inode (sb,S_IFCHR |S_IRUGO |S_IWUGO );if (!inode) goto out; - isec = (struct inode_security_struct *)inode->i_security; + isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct); isec->sid =SECINITSID_DEVNULL ; isec->sclass =SECCLASS_CHR_FILE ; isec->initialized =1 ;
PATCH 11/15 lsm stacking v0.3: selinux: remove secondary support
In reply to [email protected]Remove the SELinux support for secondary modules. This is no longer necessary as SELinux can now be simply stacked with the cap-stack module.
--
hooks.c | 266 ++++++++-------------------------------------------------------- 1 files changed, 35 insertions(+), 231 deletions(-)
security/selinux/hooks.c +35 -231
@@ -81,6 +81,8 @@extern unsigned int policydb_loaded_version;extern int selinux_nlmsg_lookup (u16 sclass,u16 nlmsg_type,u32 *perm); +static int secondary;/* how were we registered? */ +#ifdef CONFIG_SECURITY_SELINUX_DEVELOP int selinux_enforcing =0 ;
@@ -103,15 +105,6 @@ static int __init selinux_enabled_setup(__setup ("selinux=" , selinux_enabled_setup);#endif -/* Original (dummy) security module. */ -static struct security_operations *original_ops =NULL ; - -/* Minimal support for a secondary security module, -just to allow the use of the dummy or capability modules. -The owlsm module can alternatively be used as a secondary -module as long as CONFIG_OWLSM_FD is not enabled. */ -static struct security_operations *secondary_ops =NULL ; -/* Lists of inode and superblock security structures initialized before the policy was loaded. */ static LIST_HEAD (superblock_security_head);
@@ -1400,9 +1393,6 @@ static int selinux_ptrace(struct task_ststruct task_security_struct *csec;int rc; - rc = secondary_ops->ptrace (parent,child); -if (rc) -return rc; psec =security_get_value_type (&parent->security,SELINUX_LSM_ID , struct task_security_struct); csec = security_get_value_type(&child->security, SELINUX_LSM_ID,
@@ -1418,41 +1408,17 @@ static int selinux_ptrace(struct task_ststatic int selinux_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { -int error; - - error =task_has_perm (current, target,PROCESS__GETCAP ); -if (error) -return error; - -return secondary_ops->capget (target, effective, inheritable, permitted); +return task_has_perm (current, target,PROCESS__GETCAP ); }static int selinux_capset_check (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { -int error; - - error = secondary_ops->capset_check (target, effective, inheritable, permitted); -if (error) -return error; -return task_has_perm (current, target,PROCESS__SETCAP ); } -static void selinux_capset_set (struct task_struct *target,kernel_cap_t *effective, -kernel_cap_t *inheritable,kernel_cap_t *permitted) -{ - secondary_ops->capset_set (target, effective, inheritable, permitted); -} -static int selinux_capable (struct task_struct *tsk,int cap) { -int rc; - - rc = secondary_ops->capable (tsk, cap); -if (rc) -return rc; -return task_has_capability (tsk,cap); }
@@ -1464,10 +1430,6 @@ static int selinux_sysctl(ctl_table *tabu32 tsid;int rc; - rc = secondary_ops->sysctl (table, op); -if (rc) -return rc; - tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , struct task_security_struct);
@@ -1535,11 +1497,7 @@ static int selinux_quota_on(struct dentrstatic int selinux_syslog (int type) { -int rc; - - rc = secondary_ops->syslog (type); -if (rc) -return rc; +int rc =0 ;switch (type) {case 3 :/* Read last kernel messages */
@@ -1563,36 +1521,6 @@ static int selinux_syslog(int type)return rc; } -/* -* Check that a process has enough memory to allocate a new virtual -* mapping. 0 means there is enough memory for the allocation to -* succeed and -ENOMEM implies there is not. -* -* Note that secondary_ops->capable and task_has_perm_noaudit return 0 -* if the capability is granted, but __vm_enough_memory requires 1 if -* the capability is granted. -* -* Do not audit the selinux permission check, as this is applied to all -* processes that allocate mappings. -*/ -static int selinux_vm_enough_memory (long pages) -{ -int rc, cap_sys_admin =0 ; -struct task_security_struct *tsec = current->security; - - rc = secondary_ops->capable (current,CAP_SYS_ADMIN ); -if (rc ==0 ) - rc =avc_has_perm_noaudit (tsec->sid, tsec->sid, -SECCLASS_CAPABILITY , -CAP_TO_MASK (CAP_SYS_ADMIN ), -NULL ); - -if (rc ==0 ) - cap_sys_admin =1 ; - -return __vm_enough_memory (pages, cap_sys_admin); -} -/* binprm security operations */ static int selinux_bprm_alloc_security (struct linux_binprm *bprm)
@@ -1622,10 +1550,6 @@ static int selinux_bprm_set_security(strstruct avc_audit_data ad;int rc; - rc = secondary_ops->bprm_set_security (bprm); -if (rc) -return rc; - bsec =security_get_value_type (&bprm->security,SELINUX_LSM_ID , struct bprm_security_struct);
@@ -1690,12 +1614,6 @@ static int selinux_bprm_set_security(strreturn 0 ; } -static int selinux_bprm_check_security (struct linux_binprm *bprm) -{ -return secondary_ops->bprm_check_security (bprm); -} - -static int selinux_bprm_secureexec (struct linux_binprm *bprm) {struct task_security_struct *tsec;
@@ -1712,7 +1630,7 @@ static int selinux_bprm_secureexec (stru PROCESS__NOATSECURE, NULL); } -return (atsecure || secondary_ops->bprm_secureexec (bprm)); +return atsecure; }static void selinux_bprm_free_security (struct linux_binprm *bprm)
@@ -1816,8 +1734,6 @@ static void selinux_bprm_apply_creds(stru32 sid;int rc; - secondary_ops->bprm_apply_creds (bprm, unsafe); - tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , struct task_security_struct); bsec = security_get_value_type(&bprm->security, SELINUX_LSM_ID,
@@ -2043,12 +1959,6 @@ static int selinux_mount(char * dev_name unsigned long flags, void * data) { - int rc; - - rc = secondary_ops->sb_mount (dev_name, nd, type, flags, data); -if (rc) -return rc; -if (flags &MS_REMOUNT )return superblock_has_perm (current, nd->mnt->mnt_sb,FILESYSTEM__REMOUNT ,NULL );
@@ -2059,12 +1969,6 @@ static int selinux_mount(char * dev_namestatic int selinux_umount (struct vfsmount *mnt,int flags) { -int rc; - - rc = secondary_ops->sb_umount (mnt, flags); -if (rc) -return rc; -return superblock_has_perm (current,mnt->mnt_sb,FILESYSTEM__UNMOUNT ,NULL ); }
@@ -2093,11 +1997,6 @@ static void selinux_inode_post_create(ststatic int selinux_inode_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) { -int rc; - - rc = secondary_ops->inode_link (old_dentry,dir,new_dentry); -if (rc) -return rc;return may_link (dir, old_dentry,MAY_LINK ); }
@@ -2108,11 +2007,6 @@ static void selinux_inode_post_link(strustatic int selinux_inode_unlink (struct inode *dir,struct dentry *dentry) { -int rc; - - rc = secondary_ops->inode_unlink (dir, dentry); -if (rc) -return rc;return may_link (dir, dentry,MAY_UNLINK ); }
@@ -2143,12 +2037,6 @@ static int selinux_inode_rmdir(struct instatic int selinux_inode_mknod (struct inode *dir,struct dentry *dentry,int mode,dev_t dev) { -int rc; - - rc = secondary_ops->inode_mknod (dir, dentry, mode, dev); -if (rc) -return rc; -return may_create (dir, dentry,inode_mode_to_security_class (mode)); }
@@ -2176,23 +2064,12 @@ static int selinux_inode_readlink(structstatic int selinux_inode_follow_link (struct dentry *dentry,struct nameidata *nameidata) { -int rc; - - rc = secondary_ops->inode_follow_link (dentry,nameidata); -if (rc) -return rc;return dentry_has_perm (current,NULL , dentry,FILE__READ ); }static int selinux_inode_permission (struct inode *inode,int mask,struct nameidata *nd) { -int rc; - - rc = secondary_ops->inode_permission (inode, mask, nd); -if (rc) -return rc; -if (!mask) {/* No permission to check. Existence test. */ return 0 ;
@@ -2204,12 +2081,6 @@ static int selinux_inode_permission(strustatic int selinux_inode_setattr (struct dentry *dentry,struct iattr *iattr) { -int rc; - - rc = secondary_ops->inode_setattr (dentry, iattr); -if (rc) -return rc; -if (iattr->ia_valid &ATTR_FORCE )return 0 ;
@@ -2531,12 +2402,6 @@ static int file_map_prot_check(struct fistatic int selinux_file_mmap (struct file *file,unsigned long reqprot,unsigned long prot,unsigned long flags) { -int rc; - - rc = secondary_ops->file_mmap (file, reqprot, prot, flags); -if (rc) -return rc; -if (selinux_checkreqprot) prot = reqprot;
@@ -2550,10 +2415,6 @@ static int selinux_file_mprotect(struct {int rc; - rc = secondary_ops->file_mprotect (vma, reqprot, prot); -if (rc) -return rc; -if (selinux_checkreqprot) prot = reqprot;
@@ -2576,7 +2437,7 @@ static int selinux_file_mprotect(struct* check ability to execute the possibly modified content. * This typically should only occur for text relocations. */ -int rc =file_has_perm (current, vma->vm_file,FILE__EXECMOD ); + rc =file_has_perm (current, vma->vm_file,FILE__EXECMOD );if (rc)return rc; }
@@ -2692,12 +2553,6 @@ static int selinux_file_receive(struct fstatic int selinux_task_create (unsigned long clone_flags) { -int rc; - - rc = secondary_ops->task_create (clone_flags); -if (rc) -return rc; -return task_has_perm (current, current,PROCESS__FORK ); }
@@ -2746,11 +2601,6 @@ static int selinux_task_setuid(uid_t id0return 0 ; } -static int selinux_task_post_setuid (uid_t id0,uid_t id1,uid_t id2,int flags) -{ -return secondary_ops->task_post_setuid (id0,id1,id2,flags); -} -static int selinux_task_setgid (gid_t id0,gid_t id1,gid_t id2,int flags) {/* See the comment for setuid above. */
@@ -2780,24 +2630,12 @@ static int selinux_task_setgroups(structstatic int selinux_task_setnice (struct task_struct *p,int nice) { -int rc; - - rc = secondary_ops->task_setnice (p, nice); -if (rc) -return rc; -return task_has_perm (current,p,PROCESS__SETSCHED ); }static int selinux_task_setrlimit (unsigned int resource,struct rlimit *new_rlim) {struct rlimit *old_rlim = current->signal->rlim + resource; -int rc; - - rc = secondary_ops->task_setrlimit (resource, new_rlim); -if (rc) -return rc; -/* Control the ability to change the hard limit (whether lowering or raising it), so that the hard limit can later be used as a safe reset point for the soft limit
@@ -2821,11 +2659,6 @@ static int selinux_task_getscheduler(strstatic int selinux_task_kill (struct task_struct *p,struct siginfo *info,int sig) {u32 perm; -int rc; - - rc = secondary_ops->task_kill (p, info, sig); -if (rc) -return rc;if (info && ((unsigned long )info ==1 || (unsigned long )info ==2 ||SI_FROMKERNEL (info)))
@@ -2864,8 +2697,6 @@ static void selinux_task_reparent_to_ini {struct task_security_struct *tsec; - secondary_ops->task_reparent_to_init (p); - tsec =security_get_value_type (&p->security,SELINUX_LSM_ID , struct task_security_struct); tsec->osid = tsec->sid;
@@ -3329,10 +3160,6 @@ static int selinux_socket_unix_stream_costruct avc_audit_data ad;int err; - err = secondary_ops->unix_stream_connect (sock, other, newsk); -if (err) -return err; - isec =security_get_value_type (&SOCK_INODE (sock)->i_security, SELINUX_LSM_ID, struct inode_security_struct); other_isec = security_get_value_type(&SOCK_INODE(other)->i_security,
@@ -3716,11 +3543,7 @@ static int selinux_netlink_send(struct s {struct task_security_struct *tsec;struct av_decision avd; -int err; - - err = secondary_ops->netlink_send (sk, skb); -if (err) -return err; +int err =0 ; tsec =security_get_value_type (¤t->security, SELINUX_LSM_ID, struct task_security_struct);
@@ -3736,13 +3559,6 @@ static int selinux_netlink_send(struct sreturn err; } -static int selinux_netlink_recv (struct sk_buff *skb) -{ -if (!cap_raised (NETLINK_CB (skb).eff_cap,CAP_NET_ADMIN )) -return -EPERM ; -return 0 ; -} -static int ipc_alloc_security (struct task_struct *task,struct kern_ipc_perm *perm,u16 sclass)
@@ -4080,11 +3896,6 @@ static int selinux_shm_shmat(struct shmi char __user *shmaddr, int shmflg) {u32 perms; -int rc; - - rc = secondary_ops->shm_shmat (shp, shmaddr, shmflg); -if (rc) -return rc;if (shmflg &SHM_RDONLY ) perms =SHM__READ ;
@@ -4220,32 +4031,12 @@ static int selinux_ipc_permission(struct/* module stacking operations */ static int selinux_register_security (const char *name,struct security_operations *ops) { -if (secondary_ops != original_ops) { -printk (KERN_INFO "%s: There is already a secondary security " -"module registered.\n" , __FUNCTION__); -return -EINVAL ; - } - - secondary_ops = ops; - -printk (KERN_INFO "%s: Registering secondary module %s\n" , - __FUNCTION__, - name); - -return 0 ; +return -EINVAL ; }static int selinux_unregister_security (const char *name,struct security_operations *ops) { -if (ops != secondary_ops) { -printk (KERN_INFO "%s: trying to unregister a security module " -"that is not registered.\n" , __FUNCTION__); -return -EINVAL ; - } - - secondary_ops = original_ops; - -return 0 ; +return -EINVAL ; }static void selinux_d_instantiate (struct dentry *dentry,struct inode *inode)
@@ -4410,23 +4201,19 @@ static struct security_operations selinu .ptrace = selinux_ptrace, .capget = selinux_capget, .capset_check = selinux_capset_check, - .capset_set = selinux_capset_set, .sysctl = selinux_sysctl, .capable = selinux_capable, .quotactl = selinux_quotactl, .quota_on = selinux_quota_on, .syslog = selinux_syslog, - .vm_enough_memory = selinux_vm_enough_memory, .netlink_send = selinux_netlink_send, - .netlink_recv = selinux_netlink_recv, .bprm_alloc_security = selinux_bprm_alloc_security, .bprm_free_security = selinux_bprm_free_security, .bprm_apply_creds = selinux_bprm_apply_creds, .bprm_post_apply_creds = selinux_bprm_post_apply_creds, .bprm_set_security = selinux_bprm_set_security, - .bprm_check_security = selinux_bprm_check_security, .bprm_secureexec = selinux_bprm_secureexec, .sb_alloc_security = selinux_sb_alloc_security,
@@ -4483,7 +4270,6 @@ static struct security_operations selinu .task_alloc_security = selinux_task_alloc_security, .task_free_security = selinux_task_free_security, .task_setuid = selinux_task_setuid, - .task_post_setuid = selinux_task_post_setuid, .task_setgid = selinux_task_setgid, .task_setpgid = selinux_task_setpgid, .task_getpgid = selinux_task_getpgid,
@@ -4555,10 +4341,12 @@ static struct security_operations selinu#endif }; +#define MY_NAME "selinux"static __init int selinux_init (void ) {struct task_security_struct *tsec; + secondary =0 ;if (!selinux_enabled) {printk (KERN_INFO "SELinux: Disabled at boot.\n" );return 0 ;
@@ -4569,22 +4357,30 @@ static __init int selinux_init(void)/* Set the security state for the initial task. */ if (task_alloc_security (current))panic ("SELinux: Failed to initialize initial task.\n" ); - tsec = current->security; + tsec =security_get_value_type (¤t->security,SELINUX_LSM_ID , + struct task_security_struct); tsec->osid = tsec->sid =SECINITSID_KERNEL ;avc_init (); - original_ops = secondary_ops = security_ops; -if (!secondary_ops) -panic ("SELinux: No initial security operations\n" ); -if (register_security (&selinux_ops)) -panic ("SELinux: Unable to register with kernel.\n" ); +if (register_security (&selinux_ops)) { +if (mod_reg_security (MY_NAME , &selinux_ops)) { +printk (KERN_ERR "%s: Failed to register with primary LSM.\n" , + __FUNCTION__); +panic ("SELinux: Unable to register with kernel.\n" ); + }else { +printk (KERN_ERR "%s: registered with primary LSM.\n" , + __FUNCTION__); + } + secondary =1 ; + }if (selinux_enforcing) {printk (KERN_INFO "SELinux: Starting in enforcing mode\n" ); }else {printk (KERN_INFO "SELinux: Starting in permissive mode\n" ); } +return 0 ; }
@@ -4694,6 +4490,7 @@ int selinux_disable(void) {extern void exit_sel_fs (void );static int selinux_disabled =0 ; +int ret;if (ss_initialized) {/* Not permitted after initial policy load. */
@@ -4709,8 +4506,15 @@ int selinux_disable(void) selinux_disabled =1 ; -/* Reset security_ops to the secondary module, dummy or capability. */ - security_ops = secondary_ops; +if (secondary) + ret =mod_unreg_security (MY_NAME , &selinux_ops); +else + ret =unregister_security (&selinux_ops); + +if (ret) +printk (KERN_INFO "Failure unregistering selinux.\n" ); +else +printk (KERN_INFO "Unregistered selinux.\n" );/* Unregister netfilter hooks. */ selinux_nf_ip_exit ();
PATCH 12/15 lsm stacking v0.3: hook completeness verification script
In reply to [email protected]Add a script to check whether all security_operations hooks are defined in both dummy_security_ops (through security_fixup_ops) and in stacker_ops. Also adds a note in security.h to remind developers that all hooks must be defined in these two modules, and to verify this using the lsm_verify_hooks.sh script.
--- include/linux/security.h | 4 ++++ scripts/lsm_verify_hooks.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
include/linux/security.h +4 -0
@@ -125,6 +125,10 @@ struct swap_info_struct;/** * struct security_operations - main security structure * +* When adding functions to this structure, please add them to +* dummy.c and stacker.c, and run linux/scripts/lsm_verify_hooks.sh +* to verify their inclusion in these modules. +* * Security hooks for program execution operations. * *
scripts/lsm_verify_hooks.sh new file +44 -0
44 lines not on this page · raw message
PATCH 13/15 lsm stacking v0.3: seclvl: update for stacking
In reply to [email protected]Add stacking support to the seclvl module.
Note that seclvl is currently unable to prevent it's own unloading, as it actually claims to do.
Changelog:
[Jul 26] Updated seclvl to use security_unlink_value to free its data when seclvl is unloaded.
--- seclvl.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 123 insertions(+), 10 deletions(-)
security/seclvl.c +123 -10
@@ -21,6 +21,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/security.h> +#include <linux/security-stack.h> #include <linux/netlink.h> #include <linux/fs.h> #include <linux/namei.h>
@@ -35,6 +36,7 @@#include <linux/sysfs.h> #define SHA1_DIGEST_SIZE 20 +#define SECLVL_LSM_ID 0xF45/** * Module parameter that defines the initial secure level.
@@ -485,12 +487,46 @@ static int seclvl_settime(struct timespereturn 0 ; } +/* +* A structure which is stored with the inode when a process +* has a unmounted block device open for writing. +*/ +struct seclvl_i_sec { +struct security_list lsm_list; +struct task_struct *task; +spinlock_t spinlock; +struct list_head chain; +}; + +static LIST_HEAD (seclvl_ichain); +static DEFINE_SPINLOCK (seclvl_ichain_lock); + +static void seclvl_inode_free (struct inode *inode) +{ +struct seclvl_i_sec *isec; + + isec =security_del_value_type (&inode->i_security,SECLVL_LSM_ID , + struct seclvl_i_sec); +if (isec) { +spin_lock (&seclvl_ichain_lock); +list_del (&isec->chain); +spin_unlock (&seclvl_ichain_lock); +if (isec->task == current) + isec->task =NULL ; +kfree (isec); + } +} +/* claim the blockdev to exclude mounters, release on file close */ -static int seclvl_bd_claim (struct inode *inode) +static int seclvl_bd_claim (struct inode *inode,struct seclvl_i_sec *isec) {int holder;struct block_device *bdev =NULL ;dev_t dev = inode->i_rdev; + +if (isec->task && isec->task != current) +return -EPERM ; + bdev =open_by_devnum (dev,FMODE_WRITE );if (bdev) {if (bd_claim (bdev, &holder)) {
@@ -498,7 +534,7 @@ static int seclvl_bd_claim(struct inodereturn -EPERM ; }/* claimed, mark it to release on close */ - inode->i_security = current; + isec->task = current; }return 0 ; }
@@ -506,17 +542,60 @@ static int seclvl_bd_claim(struct inode/* release the blockdev if you claimed it */ static void seclvl_bd_release (struct inode *inode) { -if (inode &&S_ISBLK (inode->i_mode) && inode->i_security == current) { -struct block_device *bdev = inode->i_bdev; -if (bdev) { -bd_release (bdev); -blkdev_put (bdev); - inode->i_security =NULL ; - } +struct seclvl_i_sec *isec; + +if (inode &&S_ISBLK (inode->i_mode)) { + isec =security_get_value_type (&inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec); +if (!isec) +return ; +spin_lock (&isec->spinlock); +if (isec->task == current) { +struct block_device *bdev = inode->i_bdev; +if (bdev) { +bd_release (bdev); +blkdev_put (bdev); + isec->task =NULL ; + } + } +spin_unlock (&isec->spinlock); } }/** +* Either returns the existing inode isec, or creates a new +* isec, places it on the inode->i_security list, and returns +* it. +* On error, return NULL. +*/ +static struct seclvl_i_sec * +seclvl_inode_get_or_alloc (struct inode *inode) +{ +struct seclvl_i_sec *isec; + + isec =security_get_value_type (&inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec); +if (isec) +return isec; +spin_lock (&seclvl_ichain_lock); + isec =security_get_value_type (&inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec); +if (isec) + goto out; + isec =kmalloc (sizeof (struct seclvl_i_sec ),GFP_KERNEL ); +if (!isec) + goto out; +spin_lock_init (&isec->spinlock); +INIT_LIST_HEAD (&isec->chain); +list_add (&isec->chain, &seclvl_ichain); +security_add_value_type (&inode->i_security,SECLVL_LSM_ID , isec); + +out: +spin_unlock (&seclvl_ichain_lock); +return isec; +} + +/** * Security for writes to block devices is regulated by this seclvl * function. Deny all writes to block devices in seclvl 2. In * seclvl 1, we only deny writes to *mounted* block devices.
@@ -524,6 +603,8 @@ static void seclvl_bd_release(struct inostatic int seclvl_inode_permission (struct inode *inode,int mask,struct nameidata *nd) { +struct seclvl_i_sec *isec; +if (current->pid !=1 &&S_ISBLK (inode->i_mode) && (mask &MAY_WRITE )) {switch (seclvl) {case 2 :
@@ -531,13 +612,19 @@ seclvl_inode_permission(struct inode *in "denied in secure level [%d]\n", seclvl);return -EPERM ;case 1 : -if (seclvl_bd_claim (inode)) { + isec =seclvl_inode_get_or_alloc (inode); +if (!isec) +return -ENOMEM ; +spin_lock (&isec->spinlock); +if (seclvl_bd_claim (inode, isec)) {seclvl_printk (1 ,KERN_WARNING ,"Write to mounted block device " "denied in secure level [%d]\n" , seclvl); +spin_unlock (&isec->spinlock);return -EPERM ; } +spin_unlock (&isec->spinlock); } }return 0 ;
@@ -596,6 +683,7 @@ static struct security_operations seclvl .capable = seclvl_capable, .inode_permission = seclvl_inode_permission, .inode_setattr = seclvl_inode_setattr, + .inode_free_security = seclvl_inode_free, .file_free_security = seclvl_file_free_security, .settime = seclvl_settime, .sb_umount = seclvl_umount,
@@ -720,6 +808,29 @@ static int __init seclvl_init(void)return rc; } +/* +* free_ichain: Called when seclvl is unloaded to free all the memory +* it has attached to inodes. +* First we go through the list and remove the objects from the +* object chains (ie inode->i_security). Then we wait an rcu cycle. +* Then we can safely delete the object, as any any stacker m->hook() +* loop should have moved on to isec->lsm_list.next. +*/ +static void free_ichain (void ) +{ +struct seclvl_i_sec *isec, *n; + +list_for_each_entry_safe (isec, n, &seclvl_ichain, chain) { +security_unlink_value (&isec->lsm_list.list); + } + +synchronize_rcu (); +list_for_each_entry_safe (isec, n, &seclvl_ichain, chain) { +list_del (&isec->chain); +kfree (isec); + } +} +/** * Remove the seclvl module. */
@@ -738,6 +849,8 @@ static void __exit seclvl_exit(void)"seclvl: Failure unregistering with the " "kernel\n"); } + +free_ichain (); }module_init (seclvl_init);
PATCH 14/15 lsm stacking v0.3: fix security_{del,unlink}_value race
In reply to [email protected]The security_unlink_value() hook can race with security_del_value(). This is because security_del_value() is optimized to assume that it is naturally serialized by only being called from security_<object>_free().
At the moment we want modules to only call security_unlink_value() while they are being unloaded, so we try to avoid a spinlock at any other time. If this is unreasonable, we can simply protect security_del_value() with the spinlock at all times. Or, we can try to find another solution.
--- security.c | 18 ++++++++++++++++-- stacker.c | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-)
security/security.c +16 -2
@@ -125,22 +125,36 @@ void security_disown_value(struct hlist_spin_unlock (&stacker_value_spinlock); } +int lsm_unloading; +/* No locking needed: only called during object_destroy */ fastcall struct security_list *security_del_value (struct hlist_head *head,int security_id) {struct security_list *e;struct hlist_node *tmp; +char d =0 ; + +if (lsm_unloading) { + d =1 ; +spin_lock (&stacker_value_spinlock); + }for (tmp = head->first; tmp; tmp = tmp->next) { e = hlist_entry(tmp, struct security_list, list);if (e->security_id == security_id) {hlist_del (&e->list); -return e; + goto out; } } -return NULL ; + e =NULL ; + +out: +if (d) +spin_unlock (&stacker_value_spinlock); + +return e; }EXPORT_SYMBOL_GPL (security_get_value);
security/stacker.c +2 -0
@@ -1267,6 +1267,7 @@ find_lsm_with_namelen(const char *name,return ret; } +extern int lsm_unloading;/* from security/security.c */ /* * XXX TODO I need an all_modules list again to use here */
@@ -1286,6 +1287,7 @@ static int stacker_unregister (const cha }list_del_rcu (&m->all_lsms);call_rcu (&m->m_rcu, stacker_del_module); + lsm_unloading =1 ; out:spin_unlock (&stacker_lock);
PATCH 15/15 lsm stacking v0.3: stacking for digsig
In reply to [email protected]Support stacking in digsig. This patch is on top of the cvs version from www.sf.net/projects/disec.
[Jul 16] Update to support dynamic unloading by freeing object->security data at unload.
--
digsig.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 128 insertions(+), 14 deletions(-)
digsig.c +128 -14
@@ -33,6 +33,7 @@#include <linux/fs.h> #include <asm/uaccess.h> #include <linux/security.h> +#include <linux/security-stack.h> #include <linux/dcache.h> #include <linux/kobject.h> #include <linux/mman.h>
@@ -47,6 +48,8 @@#include "gnupg/mpi/mpi.h" #include "gnupg/cipher/rsa-verify.h" +#define DIGSIG_LSM_ID 0x5AA8 +#ifdef DIGSIG_DEBUG #define DIGSIG_MODE 0/*permissive mode */ #define DIGSIG_BENCH 1
@@ -55,11 +58,11 @@#define DIGSIG_BENCH 0#endif -#define get_inode_security (ino) ((unsigned long)(ino->i_security)) -#define set_inode_security (ino,val) (ino->i_security = (void *)val) - -#define get_file_security (file) ((unsigned long)(file->f_security)) -#define set_file_security (file,val) (file->f_security = (void *)val) +struct digsig_ksec { +struct security_list lsm_list; +struct list_head chain; +unsigned count; +};unsigned long int total_jiffies =0 ;
@@ -82,6 +85,73 @@ int dsi_cache_buckets = 128;module_param (dsi_cache_buckets, int,0 );MODULE_PARM_DESC (dsi_cache_buckets,"Number of cache buckets for signatures validations.\n" ); +LIST_HEAD (digsig_del_chain); +DEFINE_SPINLOCK (digsig_chain_lock); + +static int get_file_security (struct file *file) +{ +struct digsig_ksec *ksec; + + ksec =security_get_value_type (&file->f_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) +return 0 ; +return ksec->count; +} + +static int set_file_security (struct file *file,int v) +{ +struct digsig_ksec *ksec; + + ksec =security_get_value_type (&file->f_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) { + ksec =kmalloc (sizeof (struct digsig_ksec ),GFP_KERNEL ); +if (!ksec) +return -ENOMEM ; +INIT_LIST_HEAD (&ksec->chain); +spin_lock (&digsig_chain_lock); +list_add_rcu (&ksec->chain, &digsig_del_chain); +spin_unlock (&digsig_chain_lock); +security_add_value_type (&file->f_security,DIGSIG_LSM_ID , + ksec); + } + ksec->count = v; +return 0 ; +} + + +static int get_inode_security (struct inode *inode) +{ +struct digsig_ksec *ksec; + + ksec =security_get_value_type (&inode->i_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) +return 0 ; +return ksec->count; +} + +static int set_inode_security (struct inode *inode,int v) +{ +struct digsig_ksec *ksec; + + ksec =security_get_value_type (&inode->i_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) { + ksec =kmalloc (sizeof (struct digsig_ksec ),GFP_KERNEL ); +if (!ksec) +return -ENOMEM ; +INIT_LIST_HEAD (&ksec->chain); +spin_lock (&digsig_chain_lock); +list_add (&ksec->chain, &digsig_del_chain); +spin_unlock (&digsig_chain_lock); +security_add_value_type (&inode->i_security,DIGSIG_LSM_ID , + ksec); + } + ksec->count = v; +return 0 ; +}/****************************************************************************** Description :
@@ -342,18 +412,22 @@ static int digsig_deny_write_access(stru {struct inode *inode = file->f_dentry->d_inode;unsigned long isec; +int err;spin_lock (&inode->i_lock); isec =get_inode_security (inode);if (atomic_read (&inode->i_writecount) >0 ) { -spin_unlock (&inode->i_lock); -return -ETXTBSY ; + err = -ETXTBSY ; + goto out; }set_inode_security (inode, (isec+1 )); -set_file_security (file,1 ); -spin_unlock (&inode->i_lock); + err =set_file_security (file,1 ); +if (err) +set_inode_security (inode, (isec)); -return 0 ; +out: +spin_unlock (&inode->i_lock); +return err; }/*
@@ -379,9 +453,17 @@ static void digsig_allow_write_access(st*/ static void digsig_file_free_security (struct file *file) { -if (file->f_security) { -digsig_allow_write_access (file); - } +struct digsig_ksec *ksec; + + ksec =security_get_value_type (&file->f_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) +return ; + +spin_lock (&digsig_chain_lock); +list_del (&ksec->chain); +spin_unlock (&digsig_chain_lock); +kfree (ksec); }/**
@@ -530,7 +612,7 @@ static inline int is_unprotected_file(st __FUNCTION__, file->f_dentry->d_name.name, exec_time); \ } -static int digsig_file_mmap (struct file * file,unsigned long prot,unsigned long flags) +static int digsig_file_mmap (struct file * file,unsigned long reqprot,unsigned long prot,unsigned long flags) {struct elf64_hdr *elf64_ex;struct elf32_hdr *elf32_ex;
@@ -668,8 +750,20 @@ static int digsig_file_mmap(struct filestatic void digsig_inode_free_security (struct inode *inode) { +struct digsig_ksec *ksec; +if (is_cached_signature (inode))remove_signature (inode); + + ksec =security_del_value_type (&inode->i_security,DIGSIG_LSM_ID , + struct digsig_ksec); +if (!ksec) +return ; + +spin_lock (&digsig_chain_lock); +list_del (&ksec->chain); +spin_unlock (&digsig_chain_lock); +kfree (ksec); }static struct security_operations digsig_security_ops = {
@@ -715,6 +809,25 @@ out:return ret; } +static void digsig_free_secchain (void ) +{ +struct digsig_ksec *ksec, *n; + +list_for_each_entry_safe (ksec, n, &digsig_del_chain, chain) { +printk (KERN_NOTICE "free_ichain unlinking %u, %d, %lu\n" , + ksec->count, ksec->lsm_list.security_id, + (unsigned long )ksec->lsm_list.list.pprev); +security_unlink_value (&ksec->lsm_list.list); + } + +synchronize_rcu (); +list_for_each_entry_safe (ksec, n, &digsig_del_chain, chain) { +printk (KERN_NOTICE "free_ichain freeing 1\n" ); +list_del (&ksec->chain); +kfree (ksec); + } +} + static void __exit digsig_exit_module(void) {DSM_PRINT (DEBUG_INIT ,"Deinitializing module\n" );
@@ -734,6 +847,7 @@ static void __exit digsig_exit_module(vodigsig_cleanup_sysfs ();digsig_cleanup_revocation ();digsig_cache_cleanup (); +digsig_free_secchain ();mpi_free (digsig_public_key[0 ]);mpi_free (digsig_public_key[1 ]); }
Quoted 2 lines · On Wed, 27 Jul 2005 [email protected] wrote:
if interested in the performance results. I am certainly interested in ways to further speed up
security_get_value.
What about having a small static array of security blob pointers for the common case (e.g. SELinux + capabilities + perhaps something else), the total number of which is compile-time configurable. Reserve one pointer at the end for the hlist.
When a module registers with stacker, if there's room in the array, it reserves a slot for the module. This slot value can be stored by stacker in a handle held by the module (along with the stacker ID etc. perhaps).
Calls to security_get_value() etc. can then be very fast and simple for the common case, where the security blob is a pointer offset by an index in a small array. The arbitrarily sized hlist would then be a fallback with a higher performance hit.
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 4 lines · James Morris
Calls to
security_get_value()etc. can then be very fast and simple for the common case, where the security blob is a pointer offset by an index in a small array. The arbitrarily sized hlist would then be a fallback with a higher performance hit.
Also, the static slots could be single-use only, so once a module registers for one, it's permanently assigned (even if the module unloads), to avoid locking overhead. Module registration can just be test & set a bitmap.
- James
Signature · 2 lines
James Morris <[email protected]>
PATCH 1/1 Stacker - single-use static slots
Quoted 11 lines · James Morris
Quoted 4 lines · James Morris
Calls to
security_get_value()etc. can then be very fast and simple for the common case, where the security blob is a pointer offset by an index in a small array. The arbitrarily sized hlist would then be a fallback with a higher performance hit.Also, the static slots could be single-use only, so once a module registers for one, it's permanently assigned (even if the module unloads), to avoid locking overhead. Module registration can just be test & set a bitmap.
Oops, I didn't notice this last part, so module unload does unregister the slot, but this shouldn't affect performance. However I may get rid of it still since the non-stacker mod_reg_security is not protected. Or, I may just throw in a spinlock, since this is clearly an infrequent call.
The attached patch implements your idea on top of my previous patchset. Following is performance data on a 16-way ppc. dbench and tbench were run 50 times, kernbench and reaim 10 times each; results are mean +/- 95% confidence half-interval. The 'static slot' kernel had a single static slot for selinux, plus the (unused in this case) shared struct hlist_head security.
The improvements are very slight, but at least in the case of dbench they appear to be significant. I'm particularly surprised by the reaim results, as I would have expected some punishment for the extra memory use.
dbench (throughput, higher is better):
plain stacker: 1450.847800 +/- 12.666275 static slot: 1471.137400 +/- 5.905005
kernbench (time, lower is better):
plain stacker: 52.977000 +/- 0.101730 static slot: 52.976000 +/- 0.129828
tbench (throughput, higher is better):
plain stacker: 140.335360 +/- 2.622280 static slot: 142.455340 +/- 2.957549
reaim (number of jobs vs number of children forked, higher is better) plain stacker:
1 100542.857000 3296.286475
3 284142.855000 16481.432373
5 480857.144000 26914.062669
7 622200.000000 23074.003061
9 799971.426000 29666.576010
11 949692.861000 27194.361719
13 1065535.715000 53564.650500
15 1147500.000000 0.000000
static slot:
1 100542.857000 3296.286475
3 288514.284000 16148.439818
5 488142.858000 25175.800349
7 612000.000000 0.000000
9 799971.426000 29666.576010
11 949692.861000 27194.361719
13 1093950.001000 49092.813099
15 1147500.000000 0.000000
thank,
-serge
--
fs/inode.c | 2 include/linux/binfmts.h | 1 include/linux/fs.h | 4 include/linux/ipc.h | 1 include/linux/msg.h | 1 include/linux/sched.h | 1 include/linux/security-stack.h | 2 include/linux/security.h | 74 ++++++-- include/net/sock.h | 1 ipc/msg.c | 2 ipc/msgutil.c | 2 ipc/sem.c | 2 ipc/shm.c | 2 kernel/fork.c | 2 security/Kconfig | 12 + security/cap_stack.c | 4 security/capability.c | 4 security/root_plug.c | 4 security/seclvl.c | 22 +- security/security.c | 79 +++++++- security/selinux/hooks.c | 375 +++++++++++++++++++++++++++-------------- security/selinux/selinuxfs.c | 11 - security/stacker.c | 2 23 files changed, 443 insertions(+), 167 deletions(-)
include/linux/security.h +58 -16
@@ -44,24 +44,65 @@ struct security_list { }; +static inline void *__get_value (void *head,int idx) +{ +void **p = head +sizeof (struct hlist_head ); +#if 0 +printk (KERN_NOTICE "__get_value: %s (%d): head %lx p %lx idx %d returning %lx at %lx\n" , + __FUNCTION__, __LINE__, (long )head, (long )p, idx, (long )p[idx], (long )&p[idx]); +#endif +return p[idx]; +} + +static inline void __set_value (void *head,int idx,void *v) +{ +void **p = head +sizeof (struct hlist_head ); + p[idx] = v; +#if 0 +printk (KERN_NOTICE "%s (%d): hd %lx, p %lx, idx %d," +"v %lx, p[idx] %lx at %lx\n" , + __FUNCTION__, __LINE__, (long ) (head), + (long ) p, idx, (long ) (v), + (long )p[idx], (long )&p[idx]); +#endif +} +/* * These #defines present more convenient interfaces to * LSMs for using the security{g,d,s}et_value functions. */ -#define security_get_value_type (head, id, type) ( { \ - struct security_list *v = security_get_value((head), id); \ - v ? hlist_entry(v, type, lsm_list) : NULL; } ) - -#define security_set_value_type (head, id, value) \ - security_set_value((head), id, &(value)->lsm_list); - -#define security_add_value_type (head, id, value) \ - security_add_value((head), id, &(value)->lsm_list); - -#define security_del_value_type (head, id, type) ( { \ - struct security_list *v; \ - v = security_del_value((head), id); \ - v ? hlist_entry(v, type, lsm_list) : NULL; } ) +#define security_get_value_type (head, id, type, idx) (idx>=0) ? \ + (type *)__get_value((head), idx) \ + : ({ \ + struct security_list *v = security_get_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; \ + }) + +#define security_set_value_type (head, id, value, idx) \ + do { \ + if (idx>=0) { \ + __set_value((head), idx, (value)); \ + } else { \ + security_set_value((head), id, &(value)->lsm_list); \ + } \ + } while (0); + +#define security_add_value_type (head, id, value, idx) \ + do { \ + if (idx>=0) { \ + __set_value((head), idx, (value)); \ + } else { \ + security_add_value((head), id, &(value)->lsm_list); \ + } \ + } while (0); + +#define security_del_value_type (head, id, type, idx) (idx>=0) ? \ + (type *)__get_value((head), idx) \ + : ( { \ + struct security_list *v; \ + v = security_del_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; \ + } )/* security_disown_value is really only to be used by stacker */ extern void security_disown_value (struct hlist_head *);
@@ -2022,9 +2063,10 @@ static inline int security_netlink_recv(/* prototypes */ extern int security_init (void ); -extern int register_security (struct security_operations *ops); +extern int register_security (struct security_operations *ops,int *idx);extern int unregister_security (struct security_operations *ops); -extern int mod_reg_security (const char *name,struct security_operations *ops); +extern int mod_reg_security (const char *name, +struct security_operations *ops,int *idx);extern int mod_unreg_security (const char *name,struct security_operations *ops); extern struct dentry *securityfs_create_file(const char *name, mode_t mode, struct dentry *parent, void *data,
security/Kconfig +12 -0
@@ -112,5 +112,17 @@ config SECURITY_STACKER help Stack multiple LSMs. +config SECURITY_STACKER_NUMFIELDS + int "Number of security fields to reserve" + depends on SECURITY_STACKER + default 1 + help + This option reserves extra space in each kernel object + for security information. This may speed up modules which + make a lot of use of these fields, as these accesses can + be lock-free. However each kernel object requires one + extra byte for each field reserved her, which can slow + the system down. + endmenu
fs/inode.c +2 -0
@@ -134,6 +134,8 @@ static struct inode *alloc_inode(struct inode->i_cdev =NULL ; inode->i_rdev =0 ;INIT_HLIST_HEAD (&inode->i_security); +memset (&inode->i_security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *)); inode->dirtied_when =0 ;if (security_inode_alloc (inode)) {if (inode->i_sb->s_op->destroy_inode)
include/linux/binfmts.h +1 -0
@@ -30,6 +30,7 @@ struct linux_binprm{int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective;struct hlist_head security; +void * security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];int argc, envc;char * filename;/* Name of binary as seen by procps */ char * interp;/* Name of the binary really executed. Most
include/linux/fs.h +4 -0
@@ -486,6 +486,7 @@ struct inode {atomic_t i_writecount;struct hlist_head i_security; +void *i_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];union {void *generic_ip; } u;
@@ -560,6 +561,7 @@ struct fown_struct {int pid;/* pid or -pgrp where SIGIO should be sent */ uid_t uid, euid;/* uid/euid of process setting the owner */ struct hlist_head security; +void * security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];int signum;/* posix.1b rt signal to be delivered on IO */ };
@@ -597,6 +599,7 @@ struct file {size_t f_maxcount;unsigned long f_version;struct hlist_head f_security; +void *f_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];/* needed for tty driver, and maybe others */ void *private_data;
@@ -786,6 +789,7 @@ struct super_block {int s_need_sync_fs;atomic_t s_active;struct hlist_head s_security; +void *s_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];struct xattr_handler **s_xattr;struct list_head s_inodes;/* all inodes */
include/linux/ipc.h +1 -0
@@ -67,6 +67,7 @@ struct kern_ipc_permmode_t mode;unsigned long seq;struct hlist_head security; + void *security_p[CONFIG_SECURITY_STACKER_NUMFIELDS]; };#endif /* __KERNEL__ */
include/linux/msg.h +1 -0
@@ -71,6 +71,7 @@ struct msg_msg {int m_ts;/* message text size */ struct msg_msgseg * next;struct hlist_head security; +void * security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];/* the actual message follows immediately */ };
include/linux/sched.h +1 -0
@@ -722,6 +722,7 @@ struct task_struct {sigset_t *notifier_mask;struct hlist_head security; +void *security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];struct audit_context *audit_context;seccomp_t seccomp;
include/net/sock.h +1 -0
@@ -241,6 +241,7 @@ struct sock {__u32 sk_sndmsg_off;int sk_write_pending;struct hlist_head sk_security; +void *sk_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];void (*sk_state_change)(struct sock *sk);void (*sk_data_ready)(struct sock *sk,int bytes);void (*sk_write_space)(struct sock *sk);
ipc/msg.c +2 -0
@@ -100,6 +100,8 @@ static int newque (key_t key, int msgflg msq->q_perm.key = key;INIT_HLIST_HEAD (&msq->q_perm.security); +memset (&msq->q_perm.security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *)); retval =security_msg_queue_alloc (msq);if (retval) {ipc_rcu_putref (msq);
ipc/msgutil.c +2 -0
@@ -42,6 +42,8 @@ struct msg_msg *load_msg(const void __us msg->next =NULL ;INIT_HLIST_HEAD (&msg->security); +memset (&msg->security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *));if (copy_from_user (msg +1 , src, alen)) { err = -EFAULT ;
ipc/sem.c +2 -0
@@ -179,6 +179,8 @@ static int newary (key_t key, int nsems, sma->sem_perm.key = key;INIT_HLIST_HEAD (&sma->sem_perm.security); +memset (&sma->sem_perm.security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *)); retval =security_sem_alloc (sma);if (retval) {ipc_rcu_putref (sma);
ipc/shm.c +2 -0
@@ -200,6 +200,8 @@ static int newseg (key_t key, int shmflg shp->mlock_user =NULL ;INIT_HLIST_HEAD (&shp->shm_perm.security); +memset (&shp->shm_perm.security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *)); error =security_shm_alloc (shp);if (error) {ipc_rcu_putref (shp);
kernel/fork.c +2 -0
@@ -942,6 +942,8 @@ static task_t *copy_process(unsigned lon p->lock_depth =-1 ;/* -1 = no lock */ do_posix_clock_monotonic_gettime (&p->start_time);INIT_HLIST_HEAD (&p->security); +memset (&p->security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *)); p->io_context =NULL ; p->io_wait =NULL ; p->audit_context =NULL ;
security/security.c +73 -6
159 lines not on this page · raw message
security/selinux/hooks.c +249 -126
925 lines not on this page · raw message
security/selinux/selinuxfs.c +8 -3
@@ -35,6 +35,8 @@#include "objsec.h" #include "conditional.h" +extern int selinux_secidx; +unsigned int selinux_checkreqprot =CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE ;static int __init checkreqprot_setup (char *str)
@@ -61,7 +63,8 @@ static int task_has_security(struct taskstruct task_security_struct *tsec; tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , - struct task_security_struct); + struct task_security_struct, + selinux_secidx);if (!tsec)return -EACCES ;
@@ -985,7 +988,8 @@ static int sel_make_bools(void) goto err; } isec =security_get_value_type (&inode->i_security, - SELINUX_LSM_ID, struct inode_security_struct); + SELINUX_LSM_ID, struct inode_security_struct, + selinux_secidx);if ((ret =security_genfs_sid ("selinuxfs" , page,SECCLASS_FILE , &sid))) goto err; isec->sid = sid;
@@ -1271,7 +1275,8 @@ static int sel_fill_super(struct super_bif (!inode) goto out; isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , - struct inode_security_struct); + struct inode_security_struct, + selinux_secidx); isec->sid =SECINITSID_DEVNULL ; isec->sclass =SECCLASS_CHR_FILE ; isec->initialized =1 ;
security/seclvl.c +14 -8
@@ -38,6 +38,8 @@#define SHA1_DIGEST_SIZE 20#define SECLVL_LSM_ID 0xF45 +static int seclvl_secidx; +/** * Module parameter that defines the initial secure level. *
@@ -506,7 +508,7 @@ static void seclvl_inode_free(struct inostruct seclvl_i_sec *isec; isec =security_del_value_type (&inode->i_security,SECLVL_LSM_ID , - struct seclvl_i_sec); + struct seclvl_i_sec, seclvl_secidx);if (isec) {spin_lock (&seclvl_ichain_lock);list_del (&isec->chain);
@@ -546,7 +548,8 @@ static void seclvl_bd_release(struct inoif (inode &&S_ISBLK (inode->i_mode)) { isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + SECLVL_LSM_ID, struct seclvl_i_sec, + seclvl_secidx);if (!isec)return ;spin_lock (&isec->spinlock);
@@ -574,12 +577,12 @@ seclvl_inode_get_or_alloc(struct inode *struct seclvl_i_sec *isec; isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + SECLVL_LSM_ID, struct seclvl_i_sec, seclvl_secidx);if (isec)return isec;spin_lock (&seclvl_ichain_lock); isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + SECLVL_LSM_ID, struct seclvl_i_sec, seclvl_secidx);if (isec) goto out; isec =kmalloc (sizeof (struct seclvl_i_sec ),GFP_KERNEL );
@@ -588,7 +591,8 @@ seclvl_inode_get_or_alloc(struct inode *spin_lock_init (&isec->spinlock);INIT_LIST_HEAD (&isec->chain);list_add (&isec->chain, &seclvl_ichain); -security_add_value_type (&inode->i_security,SECLVL_LSM_ID , isec); +security_add_value_type (&inode->i_security,SECLVL_LSM_ID , isec, + seclvl_secidx); out:spin_unlock (&seclvl_ichain_lock);
@@ -781,12 +785,13 @@ static int __init seclvl_init(void) goto exit; }/* register ourselves with the security framework */ -if (register_security (&seclvl_ops)) { + seclvl_secidx =1 ;/* yes we want to use a security field */ +if (register_security (&seclvl_ops, &seclvl_secidx)) {seclvl_printk (0 ,KERN_ERR ,"seclvl: Failure registering with the " "kernel.\n" );/* try registering with primary module */ - rc =mod_reg_security (MY_NAME , &seclvl_ops); + rc =mod_reg_security (MY_NAME , &seclvl_ops, &seclvl_secidx);if (rc) {seclvl_printk (0 ,KERN_ERR ,"seclvl: Failure " "registering with primary security "
@@ -795,6 +800,7 @@ static int __init seclvl_init(void) }/* if primary module registered */ secondary =1 ; }/* if we registered ourselves with the security framework */ +printk (KERN_NOTICE "got seclvl_secidx %d\n" , seclvl_secidx);if ((rc =doSysfsRegistrations ())) {seclvl_printk (0 ,KERN_ERR ,"Error registering with sysfs\n" ); goto exit;
@@ -821,7 +827,7 @@ static void free_ichain(void)struct seclvl_i_sec *isec, *n;list_for_each_entry_safe (isec, n, &seclvl_ichain, chain) { -security_unlink_value (&isec->lsm_list.list); +security_unlink_value (&isec->lsm_list.list, seclvl_secidx); }synchronize_rcu ();
security/capability.c +2 -2
@@ -66,9 +66,9 @@ static int __init capability_init (void)return 0 ; }/* register ourselves with the security framework */ -if (register_security (&capability_ops)) { +if (register_security (&capability_ops,NULL )) {/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &capability_ops)) { +if (mod_reg_security (MY_NAME , &capability_ops,NULL )) {printk (KERN_INFO "Failure registering capabilities " "with primary security module.\n" );return -EINVAL ;
security/root_plug.c +2 -2
@@ -104,11 +104,11 @@ static struct security_operations rootplstatic int __init rootplug_init (void ) {/* register ourselves with the security framework */ -if (register_security (&rootplug_security_ops)) { +if (register_security (&rootplug_security_ops,NULL )) {printk (KERN_INFO "Failure registering Root Plug module with the kernel\n" );/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &rootplug_security_ops)) { +if (mod_reg_security (MY_NAME , &rootplug_security_ops,NULL )) {printk (KERN_INFO "Failure registering Root Plug " " module with primary security module.\n" );return -EINVAL ;
security/cap_stack.c +2 -2
@@ -62,9 +62,9 @@ static int __init capability_init (void)return 0 ; }/* register ourselves with the security framework */ -if (register_security (&capability_ops)) { +if (register_security (&capability_ops,NULL )) {/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &capability_ops)) { +if (mod_reg_security (MY_NAME , &capability_ops,NULL )) {printk (KERN_INFO "Failure registering capabilities " "with primary security module.\n" );return -EINVAL ;
security/stacker.c +1 -1
@@ -1629,7 +1629,7 @@ static int __init stacker_init (void)INIT_LIST_HEAD (&default_module.lsm_list);list_add_tail (&default_module.lsm_list, &stacked_modules); -if (register_security (&stacker_ops)) { +if (register_security (&stacker_ops,NULL )) {/* * stacking stacker is just a stupid idea, so don't ask * the current module to load us.
include/linux/security-stack.h +1 -1
@@ -19,7 +19,7 @@ extern fastcall struct security_list *se extern fastcall struct security_list *security_add_value(struct hlist_head *head,int security_id,struct security_list *obj_node); -extern int security_unlink_value (struct hlist_node *n); +extern int security_unlink_value (struct hlist_node *n,int idx); extern fastcall struct security_list *security_del_value(struct hlist_head *head,int security_id);
Re: [PATCH] Stacker - single-use static slots
Quoted 6 lines · * [email protected] ([email protected]) wrote:
Index:
linux-2.6.12/include/linux/security.h
===================================================================include/linux/security.h +0
-0@@ -44,24 +44,65 @@ struct security_list { };
include/linux/security.h struct security_list { · line 54
Quoted 10 lines
include/linux/security.h +8
-0+static inline void *__get_value (void *head,int idx) +{ +void **p = head +sizeof (struct hlist_head ); +#if 0 +printk (KERN_NOTICE "__get_value: %s (%d): head %lx p %lx idx %d returning %lx at %lx\n" , + __FUNCTION__, __LINE__, (long )head, (long )p, idx, (long )p[idx], (long )&p[idx]); +#endif +return p[idx];
pr_debug
include/linux/security.h struct security_list { · line 67
Quoted 13 lines
include/linux/security.h +13
-0+} + +static inline void __set_value (void *head,int idx,void *v) +{ +void **p = head +sizeof (struct hlist_head ); + p[idx] = v; +#if 0 +printk (KERN_NOTICE "%s (%d): hd %lx, p %lx, idx %d," +"v %lx, p[idx] %lx at %lx\n" , + __FUNCTION__, __LINE__, (long ) (head), + (long ) p, idx, (long ) (v), + (long )p[idx], (long )&p[idx]); +#endif
pr_debug
security/Kconfig config SECURITY_STACKER · line 118
Quoted 12 lines
Index: linux-2.6.12/security/Kconfig
===================================================================security/Kconfig +4
-0@@ -112,5 +112,17 @@ config SECURITY_STACKER help Stack multiple LSMs. +config SECURITY_STACKER_NUMFIELDS + int "Number of security fields to reserve" + depends on SECURITY_STACKER + default 1
Not sure config is worth it, also, James had suggested smth like 3 slots.
security/Kconfig config SECURITY_STACKER · line 121
Quoted 3 lines
security/Kconfig +2
-0INIT_HLIST_HEAD(&inode->i_security); + memset(&inode->i_security_p, 0, + CONFIG_SECURITY_STACKER_NUMFIELDS*sizeof(void *));
This CONFIG... is a bit rough. Can we use a simple name, and if config is necessary, assign config to simple name?
Quoted 20 lines
security/Kconfig +0
-0inode->dirtied_when = 0; if (security_inode_alloc(inode)) { if (inode->i_sb->s_op->destroy_inode)Index:
linux-2.6.12/include/linux/binfmts.h
===================================================================include/linux/binfmts.h +1
-0@@ -30,6 +30,7 @@ struct linux_binprm{int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective;struct hlist_head security; +void * security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];int argc, envc;char * filename;/* Name of binary as seen by procps */ char * interp;/* Name of the binary really executed. Most Index:
linux-2.6.12/include/linux/fs.h
===================================================================
include/linux/fs.h struct inode { · line 489
Quoted 4 lines
include/linux/fs.h +1
-0@@ -486,6 +486,7 @@ struct inode {atomic_t i_writecount;struct hlist_head i_security; +void *i_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];
James had suggested to effectively stash the list in the last slot, so there's only the array with one reserved slot.
thanks,
-chris
Re: [PATCH] Stacker - single-use static slots
Quoted 8 lines · Chris Wright
include/linux/security.h struct security_list { · line 54
Quoted 5 lines · * [email protected] ([email protected]) wrote:
include/linux/security.h +5
-0+#if 0 +printk (KERN_NOTICE "__get_value: %s (%d): head %lx p %lx idx %d returning %lx at %lx\n" , + __FUNCTION__, __LINE__, (long )head, (long )p, idx, (long )p[idx], (long )&p[idx]); +#endif +return p[idx];
pr_debug
Thanks.
Quoted 7 lines
security/Kconfig config SECURITY_STACKER · line 118
Quoted 4 lines
security/Kconfig +4
-0+config SECURITY_STACKER_NUMFIELDS + int "Number of security fields to reserve" + depends on SECURITY_STACKER + default 1Not sure config is worth it, also, James had suggested smth like 3 slots.
I misread that. I'd latched onto the "selinux+capability" (again), which combined would need only one spot.
Quoted 6 lines
fs/inode.c static struct inode *alloc_inode(struct · line 138
Quoted 3 lines
fs/inode.c +2
-0INIT_HLIST_HEAD (&inode->i_security); +memset (&inode->i_security_p,0 , +CONFIG_SECURITY_STACKER_NUMFIELDS *sizeof (void *));This CONFIG... is a bit rough. Can we use a simple name, and if config is necessary, assign config to simple name?
Will do.
Quoted 6 lines
Quoted 6 lines
Index:
linux-2.6.12/include/linux/fs.h
===================================================================include/linux/fs.h +0
-0@@ -486,6 +486,7 @@ struct inode {
Quoted 6 lines
include/linux/fs.h struct inode { · line 489
Quoted 3 lines
include/linux/fs.h +1
-0atomic_t i_writecount;struct hlist_head i_security; +void *i_security_p[CONFIG_SECURITY_STACKER_NUMFIELDS ];James had suggested to effectively stash the list in the last slot, so there's only the array with one reserved slot.
Oh, I didn't catch that. I like it. Will do.
So you mean 3 slots total including the shared one?
Any comments on the added argument to register_security and mod_reg_security to request a static slot? Given the likelyhood of capability/cap_stack being registered, it seemed worthwhile not to have it waste a spot, but it is an API change...
thanks,
-serge
Re: [PATCH] Stacker - single-use static slots
Quoted 6 lines · * [email protected] ([email protected]) wrote:
Quoted 2 lines
James had suggested to effectively stash the list in the last slot, so there's only the array with one reserved slot.
Oh, I didn't catch that. I like it. Will do.
So you mean 3 slots total including the shared one?
Yeah, i.e. common case is $LSM and capabilities. Stack slot is last one, and gets put to use only if needed.
Quoted 2 lines
Any comments on the added argument to
register_securityandmod_reg_securityto request a static slot?
Why would you not request a static slot?
security/security.c int register_security(struct security_op · line 247
Quoted 5 lines
security/security.c +5
-0+spin_lock (&security_field_spinlock); +if (idx && *idx) { +int i; + + *idx =-1 ;
So, I guess this means you request one, but who knows which one you'll get?
Quoted 10 lines
security/security.c +9
-0+for (i=0 ; i<CONFIG_SECURITY_STACKER_NUMFIELDS ; i++) { +if (security_field_owners[i] ==NULL ) { + security_field_owners[i] = ops; + *idx = i; +break ; + } + } + } +spin_unlock (&security_field_spinlock);
Quoted 3 lines
Given the likelyhood of
capability/cap_stack being registered, it seemed worthwhile not to have it waste a spot, but it is an API change...
API change is no big deal. Seems useful to get index value so you can do optimized retrieve later. But, I don't see it useful to request that way. Just register, get index, if index == last slot, lookup hits list.
thanks,
-chris
[email protected]
maintainerRe: [PATCH] Stacker - single-use static slots
Quoted 8 lines · Chris Wright
Quoted 6 lines · * [email protected] ([email protected]) wrote:
Quoted 2 lines
James had suggested to effectively stash the list in the last slot, so there's only the array with one reserved slot.
Oh, I didn't catch that. I like it. Will do.
So you mean 3 slots total including the shared one?
Quoted 7 lines
Yeah, i.e. common case is $LSM and capabilities. Stack slot is last one, and gets put to use only if needed.
Quoted 2 lines
Any comments on the added argument to
register_securityandmod_reg_securityto request a static slot?Why would you not request a static slot?
Capability wouldn't use it, though, so that slot would be wasted. In my patch, capability, cap_stack, and root_plug don't ask for a slot.
Quoted 8 lines
security/security.c int register_security(struct security_op · line 247
Quoted 5 lines
security/security.c +5
-0+spin_lock (&security_field_spinlock); +if (idx && *idx) { +int i; + + *idx =-1 ;So, I guess this means you request one, but who knows which one you'll get?
If you get -1 back, you didn't get a static slot. But you don't have to care as a module writer, the security_*_value functions will default to using the shared slot if idx==-1.
Quoted 4 lines
security/security.c int register_security(struct security_op · line 251
Quoted 4 lines
security/security.c +4
-0+for (i=0 ; i<CONFIG_SECURITY_STACKER_NUMFIELDS ; i++) { +if (security_field_owners[i] ==NULL ) { + security_field_owners[i] = ops; + *idx = i;
This (idx != -1) means you got a static slot.
Of course this can now switch to idx==num_slots meaning you use the shared slot.
Quoted 7 lines
Quoted 3 lines
Given the likelyhood of
capability/cap_stack being registered, it seemed worthwhile not to have it waste a spot, but it is an API change...API change is no big deal. Seems useful to get index value so you can do optimized retrieve later. But, I don't see it useful to request that way. Just register, get index, if index == last slot, lookup hits list.
If we do switch to all LSMs getting a slot, should we just have the return value for register_security and mod_reg_security be the slot#, or -error?
thanks,
-serge
Re: [PATCH] Stacker - single-use static slots
In reply to [email protected]Quoted 6 lines · On Wed, 3 Aug 2005 [email protected] wrote:
The attached patch implements your idea on top of my previous patchset. Following is performance data on a 16-way ppc. dbench and tbench were run 50 times, kernbench and reaim 10 times each; results are mean +/- 95% confidence half-interval. The 'static slot' kernel had a single static slot for selinux, plus the (unused in this case) shared struct
hlist_headsecurity.
Can you also compare with no stacker at all (i.e. just SELinux with caps as secondary module) ?
- James
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH] Stacker - single-use static slots
Quoted 11 lines · James Morris
Quoted 6 lines · On Wed, 3 Aug 2005 [email protected] wrote:
The attached patch implements your idea on top of my previous patchset. Following is performance data on a 16-way ppc. dbench and tbench were run 50 times, kernbench and reaim 10 times each; results are mean +/- 95% confidence half-interval. The 'static slot' kernel had a single static slot for selinux, plus the (unused in this case) shared struct
hlist_headsecurity.Can you also compare with no stacker at all (i.e. just SELinux with caps as secondary module) ?
Will do.
I'll try to get a full set of numbers by next week, comparing:
no stacker
"original" stacker
stacker with one shared slot
stacker with two shared slots
thanks,
-serge
Re: [PATCH] Stacker - single-use static slots
Quoted 13 lines · Quoting [email protected] ([email protected]):
Quoted 11 lines · James Morris
Quoted 6 lines · On Wed, 3 Aug 2005 [email protected] wrote:
The attached patch implements your idea on top of my previous patchset. Following is performance data on a 16-way ppc. dbench and tbench were run 50 times, kernbench and reaim 10 times each; results are mean +/- 95% confidence half-interval. The 'static slot' kernel had a single static slot for selinux, plus the (unused in this case) shared struct
hlist_headsecurity.Can you also compare with no stacker at all (i.e. just SELinux with caps as secondary module) ?
Quoted 8 lines
Will do.
I'll try to get a full set of numbers by next week, comparing:
no stacker
"original" stacker
stacker with one shared slot
stacker with two shared slots
Obviously, I meant to say stacker with one static slot (and one shared slot), and stacker with two static slots (and one shared slot) :)
thanks,
-serge
Re: [PATCH] Stacker - single-use static slots
In reply to James MorrisQuoted 11 lines · James Morris
Quoted 6 lines · On Wed, 3 Aug 2005 [email protected] wrote:
The attached patch implements your idea on top of my previous patchset. Following is performance data on a 16-way ppc. dbench and tbench were run 50 times, kernbench and reaim 10 times each; results are mean +/- 95% confidence half-interval. The 'static slot' kernel had a single static slot for selinux, plus the (unused in this case) shared struct
hlist_headsecurity.Can you also compare with no stacker at all (i.e. just SELinux with caps as secondary module) ?
Attached is the patch taking into account Chris' comments. More of those annoying cache effects, I assume - 3 slots (the default) outperforms two slots, even though only one slot is being used. These tests were run on a 16-way power4+ system. I may try to re-run on some x86 hardware, though each run will probably take 24 hours.
As usual, this reflects 50 runs of dbench and tbench, 10 of reaim and 10 of kernbench, with numbers representing mean +/- 95% confidence half-interval. Reaim plots # children vs max # jobs/min. All tests were on an ext2fs.
dbench (Throughput, larger is better):
2slots: 1459.680400 +/- 11.841823
3slots: 1460.549600 +/- 9.623773
nostacker: 1484.219200 +/- 11.900471
tbench (Throughput, larger is better):
2slots: 141.181200 +/- 2.982634
3slots: 143.333940 +/- 3.163371
nostacker: 143.884120 +/- 2.260252
kernbench (time, smaller is better):
2slots: 53.064000 +/- 0.150592
3slots: 52.959000 +/- 0.138074
nostacker: 52.618000 +/- 0.164646
reaim (number workers vs max jobs/min, larger is better):
2slots:
1 100542.857000 3296.286475
3 279771.426000 16148.439818
5 459000.002000 25175.800349
7 652800.000000 37679.689215
9 813085.712000 39555.434680
11 937671.432000 36259.148959
13 1093950.001000 49092.813099
15 1109250.000000 44057.652338
3slots:
1 102000.000000 0.000000
3 292885.713000 15105.482283
5 480857.144000 26914.062669
7 663000.000000 38456.671768
9 799971.426000 29666.576010
11 949692.861000 27194.361719
13 1093950.001000 49092.813099
15 1122000.000000 38456.671768
nostacker:
1 108120.000000 7049.224374
3 297257.142000 13185.145899
5 473571.430000 27469.050185
7 693600.000000 30765.337414
9 852428.570000 49444.293350
11 961714.290000 0.000000
13 1065535.715000 53564.650500
15 1147500.000000 0.000000
This patch is on top of the previous set of stacker patches.
--
fs/compat.c | 4 fs/exec.c | 2 fs/inode.c | 3 include/linux/binfmts.h | 2 include/linux/fs.h | 8 include/linux/ipc.h | 2 include/linux/msg.h | 2 include/linux/sched.h | 2 include/linux/security-stack.h | 14 include/linux/security.h | 72 +++- include/net/sock.h | 2 ipc/msg.c | 3 ipc/msgutil.c | 3 ipc/sem.c | 3 ipc/shm.c | 3 kernel/fork.c | 3 security/Kconfig | 16 + security/cap_stack.c | 4 security/capability.c | 4 security/root_plug.c | 4 security/seclvl.c | 30 +- security/security.c | 105 ++++++- security/selinux/hooks.c | 607 ++++++++++++++++++++++++----------------- security/selinux/selinuxfs.c | 17 - security/stacker.c | 62 ++-- 25 files changed, 638 insertions(+), 339 deletions(-)
include/linux/security.h +56 -16
@@ -34,6 +34,8 @@struct ctl_table ;struct module ; +extern int sec_shared_slot; +/* * structure to be embedded at top of each LSM's security * objects.
@@ -44,24 +46,61 @@ struct security_list { }; +static inline void *__get_value (void *head,int idx) +{ +void **p = head; +pr_debug ("__get_value: %s (%d): head %lx p %lx idx %d returning %lx at %lx\n" , + __FUNCTION__, __LINE__, (long )head, (long )p, idx, (long )p[idx], (long )&p[idx]); +return p[idx]; +} + +static inline void __set_value (void *head,int idx,void *v) +{ +void **p = head; + p[idx] = v; +pr_debug ("%s (%d): hd %lx, p %lx, idx %d," +"v %lx, p[idx] %lx at %lx\n" , + __FUNCTION__, __LINE__, (long ) (head), + (long ) p, idx, (long ) (v), + (long )p[idx], (long )&p[idx]); +} +/* * These #defines present more convenient interfaces to * LSMs for using the security{g,d,s}et_value functions. */ -#define security_get_value_type (head, id, type) ( { \ - struct security_list *v = security_get_value((head), id); \ - v ? hlist_entry(v, type, lsm_list) : NULL; } ) - -#define security_set_value_type (head, id, value) \ - security_set_value((head), id, &(value)->lsm_list); - -#define security_add_value_type (head, id, value) \ - security_add_value((head), id, &(value)->lsm_list); - -#define security_del_value_type (head, id, type) ( { \ - struct security_list *v; \ - v = security_del_value((head), id); \ - v ? hlist_entry(v, type, lsm_list) : NULL; } ) +#define security_get_value_type (head, id, type, idx) (idx < sec_shared_slot) ? \ + (type *)__get_value((head), idx) \ + : ({ \ + struct security_list *v = security_get_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; \ + }) + +#define security_set_value_type (head, id, value, idx) \ + do { \ + if (idx < sec_shared_slot) { \ + __set_value((head), idx, (value)); \ + } else { \ + security_set_value((head), id, &(value)->lsm_list); \ + } \ + } while (0); + +#define security_add_value_type (head, id, value, idx) \ + do { \ + if (idx < sec_shared_slot) { \ + __set_value((head), idx, (value)); \ + } else { \ + security_add_value((head), id, &(value)->lsm_list); \ + } \ + } while (0); + +#define security_del_value_type (head, id, type, idx) (idx < sec_shared_slot) ? \ + (type *)__get_value((head), idx) \ + : ( { \ + struct security_list *v; \ + v = security_del_value((head), id); \ + v ? hlist_entry(v, type, lsm_list) : NULL; \ + } )/* security_disown_value is really only to be used by stacker */ extern void security_disown_value (struct hlist_head *);
@@ -2022,9 +2061,10 @@ static inline int security_netlink_recv(/* prototypes */ extern int security_init (void ); -extern int register_security (struct security_operations *ops); +extern int register_security (struct security_operations *ops,int *idx);extern int unregister_security (struct security_operations *ops); -extern int mod_reg_security (const char *name,struct security_operations *ops); +extern int mod_reg_security (const char *name, +struct security_operations *ops,int *idx);extern int mod_unreg_security (const char *name,struct security_operations *ops); extern struct dentry *securityfs_create_file(const char *name, mode_t mode, struct dentry *parent, void *data,
security/Kconfig +16 -0
@@ -112,5 +112,21 @@ config SECURITY_STACKER help Stack multiple LSMs. +config SECURITY_STACKER_NUMFIELDS + int "Number of security fields to reserve" + depends on SECURITY_STACKER + default 3 + help + This option reserves extra space in each kernel object + for security information. This may speed up modules which + make a lot of use of these fields, as these accesses can + be lock-free. However each kernel object requires one + extra byte for each field reserved her, which can slow + the system down. + + The actual number of static slots will be 1 greater than + this number, and this number must always be at least 1. + That one will be the shared slot for all LSMs to share. + endmenu
fs/inode.c +2 -1
@@ -133,7 +133,8 @@ static struct inode *alloc_inode(struct inode->i_bdev =NULL ; inode->i_cdev =NULL ; inode->i_rdev =0 ; -INIT_HLIST_HEAD (&inode->i_security); +memset (&inode->i_security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(inode->i_security[sec_shared_slot])); inode->dirtied_when =0 ;if (security_inode_alloc (inode)) {if (inode->i_sb->s_op->destroy_inode)
include/linux/binfmts.h +1 -1
@@ -29,7 +29,7 @@ struct linux_binprm{struct file * file;int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective; -struct hlist_head security; +void * security[CONFIG_SECURITY_STACKER_NUMFIELDS ];int argc, envc;char * filename;/* Name of binary as seen by procps */ char * interp;/* Name of the binary really executed. Most
include/linux/fs.h +4 -4
@@ -485,7 +485,7 @@ struct inode {unsigned int i_flags;atomic_t i_writecount; -struct hlist_head i_security; +void *i_security[CONFIG_SECURITY_STACKER_NUMFIELDS ];union {void *generic_ip; } u;
@@ -559,7 +559,7 @@ struct fown_struct {rwlock_t lock;/* protects pid, uid, euid fields */ int pid;/* pid or -pgrp where SIGIO should be sent */ uid_t uid, euid;/* uid/euid of process setting the owner */ -struct hlist_head security; +void * security[CONFIG_SECURITY_STACKER_NUMFIELDS ];int signum;/* posix.1b rt signal to be delivered on IO */ };
@@ -596,7 +596,7 @@ struct file {size_t f_maxcount;unsigned long f_version; -struct hlist_head f_security; +void *f_security[CONFIG_SECURITY_STACKER_NUMFIELDS ];/* needed for tty driver, and maybe others */ void *private_data;
@@ -785,7 +785,7 @@ struct super_block {int s_syncing;int s_need_sync_fs;atomic_t s_active; -struct hlist_head s_security; +void *s_security[CONFIG_SECURITY_STACKER_NUMFIELDS ];struct xattr_handler **s_xattr;struct list_head s_inodes;/* all inodes */
include/linux/ipc.h +1 -1
@@ -66,7 +66,7 @@ struct kern_ipc_permgid_t cgid;mode_t mode;unsigned long seq; - struct hlist_head security; + void *security[CONFIG_SECURITY_STACKER_NUMFIELDS]; };#endif /* __KERNEL__ */
include/linux/msg.h +1 -1
@@ -70,7 +70,7 @@ struct msg_msg {long m_type;int m_ts;/* message text size */ struct msg_msgseg * next; -struct hlist_head security; +void * security[CONFIG_SECURITY_STACKER_NUMFIELDS ];/* the actual message follows immediately */ };
include/linux/sched.h +1 -1
@@ -721,7 +721,7 @@ struct task_struct {void *notifier_data;sigset_t *notifier_mask; -struct hlist_head security; +void *security[CONFIG_SECURITY_STACKER_NUMFIELDS ];struct audit_context *audit_context;seccomp_t seccomp;
include/net/sock.h +1 -1
@@ -240,7 +240,7 @@ struct sock {struct sk_buff *sk_send_head;__u32 sk_sndmsg_off;int sk_write_pending; -struct hlist_head sk_security; +void *sk_security[CONFIG_SECURITY_STACKER_NUMFIELDS ];void (*sk_state_change)(struct sock *sk);void (*sk_data_ready)(struct sock *sk,int bytes);void (*sk_write_space)(struct sock *sk);
ipc/msg.c +2 -1
@@ -99,7 +99,8 @@ static int newque (key_t key, int msgflg msq->q_perm.mode = (msgflg &S_IRWXUGO ); msq->q_perm.key = key; -INIT_HLIST_HEAD (&msq->q_perm.security); +memset (&msq->q_perm.security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(msq->q_perm.security[sec_shared_slot])); retval =security_msg_queue_alloc (msq);if (retval) {ipc_rcu_putref (msq);
ipc/msgutil.c +2 -1
@@ -41,7 +41,8 @@ struct msg_msg *load_msg(const void __usreturn ERR_PTR (-ENOMEM ); msg->next =NULL ; -INIT_HLIST_HEAD (&msg->security); +memset (&msg->security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(msg->security[sec_shared_slot]));if (copy_from_user (msg +1 , src, alen)) { err = -EFAULT ;
ipc/sem.c +2 -1
@@ -178,7 +178,8 @@ static int newary (key_t key, int nsems, sma->sem_perm.mode = (semflg &S_IRWXUGO ); sma->sem_perm.key = key; -INIT_HLIST_HEAD (&sma->sem_perm.security); +memset (&sma->sem_perm.security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(sma->sem_perm.security[sec_shared_slot])); retval =security_sem_alloc (sma);if (retval) {ipc_rcu_putref (sma);
ipc/shm.c +2 -1
@@ -199,7 +199,8 @@ static int newseg (key_t key, int shmflg shp->shm_flags = (shmflg &S_IRWXUGO ); shp->mlock_user =NULL ; -INIT_HLIST_HEAD (&shp->shm_perm.security); +memset (&shp->shm_perm.security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(shp->shm_perm.security[sec_shared_slot])); error =security_shm_alloc (shp);if (error) {ipc_rcu_putref (shp);
kernel/fork.c +2 -1
@@ -941,7 +941,8 @@ static task_t *copy_process(unsigned lon p->lock_depth =-1 ;/* -1 = no lock */ do_posix_clock_monotonic_gettime (&p->start_time); -INIT_HLIST_HEAD (&p->security); +memset (&p->security,0 , (sec_shared_slot)*sizeof (void *)); +INIT_HLIST_HEAD ((struct hlist_head *)&(p->security[sec_shared_slot])); p->io_context =NULL ; p->io_wait =NULL ; p->audit_context =NULL ;
security/security.c +95 -10
219 lines not on this page · raw message
security/selinux/hooks.c +365 -242
1,111 lines not on this page · raw message
security/selinux/selinuxfs.c +11 -6
@@ -35,6 +35,8 @@#include "objsec.h" #include "conditional.h" +extern int selinux_secidx; +unsigned int selinux_checkreqprot =CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE ;static int __init checkreqprot_setup (char *str)
@@ -60,8 +62,9 @@ static int task_has_security(struct task {struct task_security_struct *tsec; - tsec =security_get_value_type (&tsk->security,SELINUX_LSM_ID , - struct task_security_struct); + tsec =security_get_value_type (tsk->security,SELINUX_LSM_ID , + struct task_security_struct, + selinux_secidx);if (!tsec)return -EACCES ;
@@ -984,8 +987,9 @@ static int sel_make_bools(void) ret = -ENAMETOOLONG ; goto err; } - isec =security_get_value_type (&inode->i_security, - SELINUX_LSM_ID, struct inode_security_struct); + isec =security_get_value_type (inode->i_security, + SELINUX_LSM_ID, struct inode_security_struct, + selinux_secidx);if ((ret =security_genfs_sid ("selinuxfs" , page,SECCLASS_FILE , &sid))) goto err; isec->sid = sid;
@@ -1270,8 +1274,9 @@ static int sel_fill_super(struct super_b inode =sel_make_inode (sb,S_IFCHR |S_IRUGO |S_IWUGO );if (!inode) goto out; - isec =security_get_value_type (&inode->i_security,SELINUX_LSM_ID , - struct inode_security_struct); + isec =security_get_value_type (inode->i_security,SELINUX_LSM_ID , + struct inode_security_struct, + selinux_secidx); isec->sid =SECINITSID_DEVNULL ; isec->sclass =SECCLASS_CHR_FILE ; isec->initialized =1 ;
security/seclvl.c +18 -12
@@ -38,6 +38,8 @@#define SHA1_DIGEST_SIZE 20#define SECLVL_LSM_ID 0xF45 +static int seclvl_secidx; +/** * Module parameter that defines the initial secure level. *
@@ -505,8 +507,8 @@ static void seclvl_inode_free(struct ino {struct seclvl_i_sec *isec; - isec =security_del_value_type (&inode->i_security,SECLVL_LSM_ID , - struct seclvl_i_sec); + isec =security_del_value_type (inode->i_security,SECLVL_LSM_ID , + struct seclvl_i_sec, seclvl_secidx);if (isec) {spin_lock (&seclvl_ichain_lock);list_del (&isec->chain);
@@ -545,8 +547,9 @@ static void seclvl_bd_release(struct inostruct seclvl_i_sec *isec;if (inode &&S_ISBLK (inode->i_mode)) { - isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + isec =security_get_value_type (inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec, + seclvl_secidx);if (!isec)return ;spin_lock (&isec->spinlock);
@@ -573,13 +576,13 @@ seclvl_inode_get_or_alloc(struct inode * {struct seclvl_i_sec *isec; - isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + isec =security_get_value_type (inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec, seclvl_secidx);if (isec)return isec;spin_lock (&seclvl_ichain_lock); - isec =security_get_value_type (&inode->i_security, - SECLVL_LSM_ID, struct seclvl_i_sec); + isec =security_get_value_type (inode->i_security, + SECLVL_LSM_ID, struct seclvl_i_sec, seclvl_secidx);if (isec) goto out; isec =kmalloc (sizeof (struct seclvl_i_sec ),GFP_KERNEL );
@@ -588,7 +591,8 @@ seclvl_inode_get_or_alloc(struct inode *spin_lock_init (&isec->spinlock);INIT_LIST_HEAD (&isec->chain);list_add (&isec->chain, &seclvl_ichain); -security_add_value_type (&inode->i_security,SECLVL_LSM_ID , isec); +security_add_value_type (inode->i_security,SECLVL_LSM_ID , isec, + seclvl_secidx); out:spin_unlock (&seclvl_ichain_lock);
@@ -781,12 +785,13 @@ static int __init seclvl_init(void) goto exit; }/* register ourselves with the security framework */ -if (register_security (&seclvl_ops)) { + seclvl_secidx =1 ;/* yes we want to use a security field */ +if (register_security (&seclvl_ops, &seclvl_secidx)) {seclvl_printk (0 ,KERN_ERR ,"seclvl: Failure registering with the " "kernel.\n" );/* try registering with primary module */ - rc =mod_reg_security (MY_NAME , &seclvl_ops); + rc =mod_reg_security (MY_NAME , &seclvl_ops, &seclvl_secidx);if (rc) {seclvl_printk (0 ,KERN_ERR ,"seclvl: Failure " "registering with primary security "
@@ -795,6 +800,7 @@ static int __init seclvl_init(void) }/* if primary module registered */ secondary =1 ; }/* if we registered ourselves with the security framework */ +printk (KERN_NOTICE "got seclvl_secidx %d\n" , seclvl_secidx);if ((rc =doSysfsRegistrations ())) {seclvl_printk (0 ,KERN_ERR ,"Error registering with sysfs\n" ); goto exit;
@@ -821,7 +827,7 @@ static void free_ichain(void)struct seclvl_i_sec *isec, *n;list_for_each_entry_safe (isec, n, &seclvl_ichain, chain) { -security_unlink_value (&isec->lsm_list.list); +security_unlink_value (&isec->lsm_list.list, seclvl_secidx); }synchronize_rcu ();
security/capability.c +2 -2
@@ -66,9 +66,9 @@ static int __init capability_init (void)return 0 ; }/* register ourselves with the security framework */ -if (register_security (&capability_ops)) { +if (register_security (&capability_ops,NULL )) {/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &capability_ops)) { +if (mod_reg_security (MY_NAME , &capability_ops,NULL )) {printk (KERN_INFO "Failure registering capabilities " "with primary security module.\n" );return -EINVAL ;
security/root_plug.c +2 -2
@@ -104,11 +104,11 @@ static struct security_operations rootplstatic int __init rootplug_init (void ) {/* register ourselves with the security framework */ -if (register_security (&rootplug_security_ops)) { +if (register_security (&rootplug_security_ops,NULL )) {printk (KERN_INFO "Failure registering Root Plug module with the kernel\n" );/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &rootplug_security_ops)) { +if (mod_reg_security (MY_NAME , &rootplug_security_ops,NULL )) {printk (KERN_INFO "Failure registering Root Plug " " module with primary security module.\n" );return -EINVAL ;
security/cap_stack.c +2 -2
@@ -62,9 +62,9 @@ static int __init capability_init (void)return 0 ; }/* register ourselves with the security framework */ -if (register_security (&capability_ops)) { +if (register_security (&capability_ops,NULL )) {/* try registering with primary module */ -if (mod_reg_security (MY_NAME , &capability_ops)) { +if (mod_reg_security (MY_NAME , &capability_ops,NULL )) {printk (KERN_INFO "Failure registering capabilities " "with primary security module.\n" );return -EINVAL ;
security/stacker.c +41 -21
138 lines not on this page · raw message
include/linux/security-stack.h +5 -9
@@ -10,16 +10,12 @@*/ extern fastcall struct security_list *security_get_value( -struct hlist_head *head, -int security_id); +void **sec,int security_id); extern fastcall struct security_list *security_set_value( -struct hlist_head *head, -int security_id,struct security_list *obj_node); +void **sec,int security_id,struct security_list *obj_node); extern fastcall struct security_list *security_add_value( -struct hlist_head *head, -int security_id,struct security_list *obj_node); -extern int security_unlink_value (struct hlist_node *n); +void **sec,int security_id,struct security_list *obj_node); +extern int security_unlink_value (struct hlist_node *n,int idx); extern fastcall struct security_list *security_del_value( -struct hlist_head *head, -int security_id); +void **sec,int security_id);
fs/compat.c +3 -1
@@ -51,6 +51,8 @@#include <asm/mmu_context.h> #include <asm/ioctls.h> +extern int sec_shared_slot; +/* * Not all architectures have sys_utime, so implement this in terms * of sys_utimes.
@@ -1523,7 +1525,7 @@ int compat_do_execve(char * filename, bprm->file = file; bprm->filename = filename; bprm->interp = filename; -INIT_HLIST_HEAD (&bprm->security); +INIT_HLIST_HEAD ((struct hlist_head *)&(bprm->security[sec_shared_slot])); bprm->mm =mm_alloc (); retval = -ENOMEM ;if (!bprm->mm)
fs/exec.c +1 -1
@@ -1166,7 +1166,7 @@ int do_execve(char * filename, bprm->file = file; bprm->filename = filename; bprm->interp = filename; -INIT_HLIST_HEAD (&bprm->security); +INIT_HLIST_HEAD ((struct hlist_head *)&(bprm->security[sec_shared_slot])); bprm->mm =mm_alloc (); retval = -ENOMEM ;if (!bprm->mm)
James Morris
maintainerRe: [PATCH] Stacker - single-use static slots
Quoted 4 lines · On Wed, 10 Aug 2005, [email protected] wrote:
those annoying cache effects, I assume - 3 slots (the default) outperforms two slots, even though only one slot is being used. These tests were run on a 16-way power4+ system. I may try to re-run on some x86 hardware, though each run will probably take 24 hours.
I've also run some benchmarks, comparing vanilla kernel with the two stacker approaches. Results below.
Results seem to be mixed, sometimes a bit better, sometimes a bit worse. The macro benchmarks tend to show better figures for the static slot model.
Overall, it seems that SELinux could expect to take a 1-2% performance hit with the stacker.
==============================================================================
Performance testing summary using the stacker patches, 11 Aug 2005.
Test system:
8-way 900Mhz PIII Xeon, 4GB RAM, FC4, current updates.
Test data was managed on an ext2 filesystem, using targeted policy. Kernel version 2.6.13-rc4.
The kernel was configured as follows:
control
Standard kernel with SELinux and secondarily stacked capabilities.
stacker_dynamic
Stacker with fully dynamic security fields, SELinux + caps.
stacker_static
Stacker with three static slots for security fields, SELinux + caps.
-----------------------------------------------------------------------------
Unixbench
-----------------------------------------------------------------------------
Six iterations.
Larger is better.
1) control
Execl Throughput 43.0 1159.7 269.7 File Copy 1024 bufsize 2000 maxblocks 3960.0 93041.0 235.0 File Copy 256 bufsize 500 maxblocks 1655.0 44393.0 268.2 File Copy 4096 bufsize 8000 maxblocks 5800.0 129172.0 222.7 Pipe Throughput 12440.0 217759.8 175.0 Process Creation 126.0 5687.4 451.4
Shell Scripts (8 concurrent) 6.0 750.9 1251.5
System Call Overhead 15000.0 752195.3 501.5
=========
FINAL SCORE 342.1
2) stacker_dynamic
Execl Throughput 43.0 1163.8 270.7 File Copy 1024 bufsize 2000 maxblocks 3960.0 92321.0 233.1 File Copy 256 bufsize 500 maxblocks 1655.0 44309.0 267.7 File Copy 4096 bufsize 8000 maxblocks 5800.0 128635.0 221.8 Pipe Throughput 12440.0 211583.8 170.1 Process Creation 126.0 5657.9 449.0
Shell Scripts (8 concurrent) 6.0 744.0 1240.0
System Call Overhead 15000.0 759228.4 506.2
=========
FINAL SCORE 340.2
3) stacker_static
Execl Throughput 43.0 1159.6 269.7 File Copy 1024 bufsize 2000 maxblocks 3960.0 88455.0 223.4 File Copy 256 bufsize 500 maxblocks 1655.0 40165.0 242.7 File Copy 4096 bufsize 8000 maxblocks 5800.0 125384.0 216.2 Pipe Throughput 12440.0 208970.6 168.0 Process Creation 126.0 5712.9 453.4
Shell Scripts (8 concurrent) 6.0 752.5 1254.2
System Call Overhead 15000.0 746153.0 497.4
=========
FINAL SCORE 332.7
-----------------------------------------------------------------------------
Apachebench
-----------------------------------------------------------------------------
Local webserver, logging to /dev/null.
100k requests of a 100k file.
---------------------------------------------------------
#clients 1 2 4 8
---------------------------------------------------------
control : 15627.93 18715.48 20377.54 21543.10stacker_dynamic : 15371.80 18049.45 20281.98 21037.24 stacker_static : 15247.48 18395.96 20579.46 21523.41
---------------------------------------------------------
----------------------------------------------------------------------------
dbench
-----------------------------------------------------------------------------
300s tests incl. 60s of warmup.
Throughput in MB/s.
Larger is better.
-----------------------------------------------------
# procs 2 4 8 16 ----------------------------------------------------- control : 200.264 351.135 514.327 483.085 stacker_dynamic : 192.805 336.097 511.713 474.047 stacker_static : 197.254 333.781 510.713 471.581 -----------------------------------------------------
----------------------------------------------------------------------------
lmbench
-----------------------------------------------------------------------------
Processor, Processes - times in microseconds - smaller is better
------------------------------------------------------------------------------
Host OS Mhz null null open slct sig sig fork exec sh
call I/O stat clos TCP inst hndl proc proc proc
--------- ------------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
control Linux 2.6.13- 900 0.24 0.85 5.29 6.83 23.6 1.01 3.98 215. 1054 3482 stack_dyn Linux 2.6.13- 900 0.24 0.91 5.72 7.17 23.6 1.01 4.25 211. 1046 3500 stack_sta Linux 2.6.13- 900 0.24 0.89 5.41 6.97 27.3 1.01 4.28 209. 1052 3450
Context switching - times in microseconds - smaller is better
-------------------------------------------------------------------------
Host OS 2p/0K 2p/16K 2p/64K 8p/16K 8p/64K 16p/16K 16p/64K
ctxsw ctxsw ctxsw ctxsw ctxsw ctxsw ctxsw
--------- ------------- ------ ------ ------ ------ ------ ------- -------
control Linux 2.6.13- 1.7800 5.3700 7.0500 12.0 6.1000 4.42000 11.6 stack_dyn Linux 2.6.13- 2.1100 3.9800 2.0400 10.2 12.5 8.44000 19.6 stack_sta Linux 2.6.13- 1.8800 4.2500 2.1700 10.2 20.5 9.56000 25.1
*Local* Communication latencies in microseconds - smaller is better
---------------------------------------------------------------------
Host OS 2p/0K Pipe AF UDP RPC/ TCP RPC/ TCP
ctxsw UNIX UDP TCP conn
--------- ------------- ----- ----- ---- ----- ----- ----- ----- ----
control Linux 2.6.13- 1.780 52.3 18.2 100.1 83.4 112.1 96.1 177. stack_dyn Linux 2.6.13- 2.110 30.4 25.3 101.7 83.7 112.8 98.4 180. stack_sta Linux 2.6.13- 1.880 52.5 20.6 102.6 84.2 112.7 97.1 180.
File & VM system latencies in microseconds - smaller is better
-------------------------------------------------------------------------------
Host OS 0K File 10K File Mmap Prot Page 100fd
Create Delete Create Delete Latency Fault Fault selct
--------- ------------- ------ ------ ------ ------ ------- ----- ------- -----
control Linux 2.6.13- 42.4 18.1 79.6 33.4 4066.0 0.341 2.73660 20.8
stack_dyn Linux 2.6.13- 44.2 18.5 77.7 34.2 4064.0 0.217 2.73910 18.5
stack_sta Linux 2.6.13- 44.2 18.4 77.6 34.5 4072.0 0.201 2.76820 18.4*Local* Communication bandwidths in MB/s - bigger is better
-----------------------------------------------------------------------------
Host OS Pipe AF TCP File Mmap Bcopy Bcopy Mem Mem
UNIX reread reread (libc) (hand) read write
--------- ------------- ---- ---- ---- ------ ------ ------ ------ ---- -----
control Linux 2.6.13- 105. 163. 106. 228.3 256.7 133.4 130.0 256. 201.4 stack_dyn Linux 2.6.13- 207. 295. 170. 228.1 256.7 133.7 130.2 257. 201.1 stack_sta Linux 2.6.13- 107. 162. 106. 227.6 256.6 133.4 130.4 257. 201.6
==============================================================================
Re: [PATCH] Stacker - single-use static slots
Quoted 10 lines · James Morris
Quoted 4 lines · On Wed, 10 Aug 2005, [email protected] wrote:
those annoying cache effects, I assume - 3 slots (the default) outperforms two slots, even though only one slot is being used. These tests were run on a 16-way power4+ system. I may try to re-run on some x86 hardware, though each run will probably take 24 hours.
I've also run some benchmarks, comparing vanilla kernel with the two stacker approaches. Results below.
Quoted 6 lines
Results seem to be mixed, sometimes a bit better, sometimes a bit worse. The macro benchmarks tend to show better figures for the static slot model.
Overall, it seems that SELinux could expect to take a 1-2% performance hit with the stacker.
Thanks, James.
I guess I should do some profiling runs - I'm surprised there would be this much of a hit with the static slots.
thanks,
-serge
James Morris
maintainerRe: [PATCH] Stacker - single-use static slots
Quoted 2 lines · On Thu, 11 Aug 2005, [email protected] wrote:
I guess I should do some profiling runs - I'm surprised there would be this much of a hit with the static slots.
Yes. It could be some cache effect, where the exact placement of the SELinux pointer might be critical, and also vary depending on the hook and subclass of SELinux security struct.
- James
Signature · 2 lines
James Morris <[email protected]>
Thanks, James. I'll give this a shot and send out performance results this weekend or next week.
thanks,
-serge
Quoted 26 lines · James Morris
Quoted 2 lines · On Wed, 27 Jul 2005 [email protected] wrote:
if interested in the performance results. I am certainly interested in ways to further speed up
security_get_value.What about having a small static array of security blob pointers for the common case (e.g. SELinux + capabilities + perhaps something else), the total number of which is compile-time configurable. Reserve one pointer at the end for the hlist.
When a module registers with stacker, if there's room in the array, it reserves a slot for the module. This slot value can be stored by stacker in a handle held by the module (along with the stacker ID etc. perhaps).
Calls to
security_get_value()etc. can then be very fast and simple for the common case, where the security blob is a pointer offset by an index in a small array. The arbitrarily sized hlist would then be a fallback with a higher performance hit.- James
Signature · 2 lines
James Morris <[email protected]>
On Wed, Jul 27, 2005 at 01:17:32PM -0500, [email protected] wrote:
Hi Serge.
A few trivial things I noticed whilst writing some internal documentation on Stacker. Nothing deep here, but thought I'd pass them along.
I'll try to actually try out the code next week.
I made these notes as I was going along, lmk if you need them annotated to the original patch and I'll go back and redo.
Thanks again
Tony
1) Documentation refers to /security/stacker/list_modules, code refers to "listmodules". list_modules is more consistent with other file names.
2) symbol_get(ops) still at the end of stacker_register.
3) struct module_entry{
struct list_head lsm_list; /* list of active lsms */ struct list_head all_lsms; /* list of active lsms */
fix comments
4) Would it be useful to change the struct elements lsm_list and all_lsms to be consistent with their list heads (stacked_modules and all_modules).
5) /*
* Workarounds for the fact that get and setprocattr are used only by
* selinux. (Maybe)
*/
No complaints on selinux getting to avoid the (module), they are intree. Just a FYI that SubDomain/AppArmor uses these hooks also.
6) stop_responding control file is misnamed, as stacker still continues to work it just removes the virtual file system
7) Does the lsm_list really need to be at the top of the struct? Good style but not sure it is required (must).
8) security-stack.h
* If stacker is compiled in, then we use the full functions as
* defined in security/security.c. Otherwise we use the #defines
* here.
I noticed the conditional CONFIG_SECURITY_STACKER code went away, previously it would look at the value chain head only for the !case. But this comment still remains.
Quoted 9 lines
Hi,
The set of patches to follow introduces support for stacking LSMs. This is its third posting to lkml. I am sending it out in the hopes of soliciting more widespread feedback and testing, with the obvious eventual goal of mainline adoption.
Any feedback from people actually using this patch is appreciated. Even better would be posts of (stackable) LSMs for upstream inclusion :)
[email protected]
maintainerQuoting Tony Jones ([email protected]):
Thanks, Tony. I'll address each of these in the next patchset. Just two things I wanted to actually converse about:
Quoted 7 lines
5) /*
* Workarounds for the fact that get and setprocattr are used only by
* selinux. (Maybe)
*/No complaints on selinux getting to avoid the (module), they are intree. Just a FYI that SubDomain/AppArmor uses these hooks also.
And is it ok with using the "some_data (apparmor)" convention?
The special handling of selinux is intended to be temporary, due to the large base of installed userspace which hasn't yet been updated. I would imagine that at some point that code would go away.
Quoted 3 lines
I noticed the conditional
CONFIG_SECURITY_STACKERcode went away, previously it would look at the value chain head only for the !case. But this comment still remains.
Yes, after I added the unlink function, it started to seem that the special cases for !CONFIG_SECURITY_STACKER wouldn't be any faster than the stacker versions. They still might be, but I'll have to think about it. If I just ditch those, then I can probably ditch the whole security-stack.h file, and move those declarations into security.h. They were just in their own file because Stephen had pointed out that switching between stacker and non-stacker would cause too much code to be recompiled.
thanks,
-serge
Hi Serge
Quoted 9 lines
Quoted 7 lines
5) /*
* Workarounds for the fact that get and setprocattr are used only by
* selinux. (Maybe)
*/No complaints on selinux getting to avoid the (module), they are intree. Just a FYI that SubDomain/AppArmor uses these hooks also.
And is it ok with using the "
some_data(apparmor)" convention?
Yes. Our use of setprocattr is thru a library fn so I just made the change there. We'll have to change our user tools (that read /proc/pid/attr/current but thats fine too).
Quoted 3 lines
The special handling of selinux is intended to be temporary, due to the large base of installed userspace which hasn't yet been updated. I would imagine that at some point that code would go away.
I assumed it was due to this. Doesn't inconvenience us any and it it helps SELinux it's fine w/ me.
Of more concern is ps -Z (pstools).
We had to have the pstools maintainer extend the set of characters that it
considered valid from the getprocattr. I forget the details but IIRC he
wanted to know (for ?documentation?) every character that could be returned by our getprocattr hook (which for us is pretty much any character thats valid in a pathname -- though IIRC we forgot one).
Anyway, I'm guessing (at least with pstools 3.2.5) that '(' is not one of the valid characters. IIRC ps gives up when it sees a "non-valid" character.
I wrote a trivial little lsm which just returns 'foobar' for any getprocattr.
# cat /proc/2322/attr/current unconstrained (subdomain) foobar (foobar)
# ps -Z -p 2322 LABEL PID TTY TIME CMD unconstrained 2322 ttyS0 00:00:00 bash
Even if ps did return them all, I think it could create a usability problem. There was another LSM (forget which) which wanted to return a large blob from getprocattr, I recall like a page? in size which obviously caused problems for ps -Z both in terms of content and especially length.
Quoted 8 lines
Quoted 3 lines
I noticed the conditional
CONFIG_SECURITY_STACKERcode went away, previously it would look at the value chain head only for the !case. But this comment still remains.Yes, after I added the unlink function, it started to seem that the special cases for !CONFIG_SECURITY_STACKER wouldn't be any faster than the stacker versions. They still might be, but I'll have to think about it. If I just ditch those, then I can probably ditch the whole
Esp since James' suggestion would impact it. I'd imagine you would always want array[0] for this case, no?
I was just pointing out the legacy comment. Thats all.
Thanks again
Tony
Quoted 13 lines · Tony Jones
Of more concern is ps -Z (pstools).
We had to have the pstools maintainer extend the set of characters that it
considered valid from the getprocattr. I forget the details but IIRC he
wanted to know (for ?documentation?) every character that could be returned by our getprocattr hook (which for us is pretty much any character thats valid in a pathname -- though IIRC we forgot one).Anyway, I'm guessing (at least with pstools 3.2.5) that '(' is not one of the valid characters. IIRC ps gives up when it sees a "non-valid" character.
I wrote a trivial little lsm which just returns 'foobar' for any getprocattr.
Quoted 7 lines
# cat /proc/2322/attr/current unconstrained (subdomain) foobar (foobar)# ps -Z -p 2322 LABEL PID TTY TIME CMD unconstrained 2322 ttyS0 00:00:00 bash
Actually, no, it is the space preceding the open paren that is invalid; see this patch for the expanded allowed character set in procps 3.2.5:
http://cvs.sourceforge.net/viewcvs.py/procps/procps/ps/output.c?r1=1.51&r2=1.52
When I discussed this with Albert Cahalan, he *strongly* objected to allowing whitespace in security contexts, as he felt it would break scripts that parsed 'ps -Z' output.
Signature · 4 lines
Steve Beattie SUSE Labs, Novell Inc. <[email protected]> http://NxNW.org/~steve/
[email protected]
maintainerQuoted 9 lines · Steve Beattie
Quoted 7 lines · Tony Jones
# cat /proc/2322/attr/current unconstrained (subdomain) foobar (foobar)# ps -Z -p 2322 LABEL PID TTY TIME CMD unconstrained 2322 ttyS0 00:00:00 bash
Quoted 8 lines
Actually, no, it is the space preceding the open paren that is invalid; see this patch for the expanded allowed character set in procps 3.2.5:
http://cvs.sourceforge.net/viewcvs.py/procps/procps/ps/output.c?r1=1.51&r2=1.52
When I discussed this with Albert Cahalan, he *strongly* objected to allowing whitespace in security contexts, as he felt it would break scripts that parsed 'ps -Z' output.
Right, I thought this was actually a feature :) This is how ps continues to show expected output under stacker. Given naturally limited space, showing output for multiple modules may not be a good idea. If you want more detail, you go to /proc/pid/attr/current...
Clearly this is limiting, but then so is the one line per process you get with ps - "fixing" that is obviously not acceptable. Is there another suggestion for how to handle this, in such a way that ps would show info for >1 module? Is there any example where the current behavior is actually a problem - two modules which it makes sense to stack, which both need to give output under ps?
thanks,
-serge
Quoted 8 lines · On Sat, Jul 30, 2005 at 10:44:09PM -0500, [email protected] wrote:
Quoted 3 lines
When I discussed this with Albert Cahalan, he *strongly* objected to allowing whitespace in security contexts, as he felt it would break scripts that parsed 'ps -Z' output.
Right, I thought this was actually a feature :) This is how ps continues to show expected output under stacker. Given naturally limited space, showing output for multiple modules may not be a good idea. If you want more detail, you go to
/proc/pid/attr/current...
OK. As long as you are aware of it, which it sounds like you are.
Serge, I think it should be documented as a known issue.
Quoted 2 lines
Clearly this is limiting, but then so is the one line per process you get with ps - "fixing" that is obviously not acceptable. Is there
Nothing jumps out at me.
Quoted 3 lines
Is there any example where the current
behavior is actually a problem - two modules which it makes sense to stack, which both need to give output under ps?
I don't know. Isn't this the big negative against stacker, controlling the composition? pstools has clearly cast it's vote :-)
Tony
[email protected]
maintainerQuoted 3 lines · Tony Jones
OK. As long as you are aware of it, which it sounds like you are.
Serge, I think it should be documented as a known issue.
Ok.
Quoted 11 lines
Quoted 2 lines
Clearly this is limiting, but then so is the one line per process you get with ps - "fixing" that is obviously not acceptable. Is there
Nothing jumps out at me.
Quoted 3 lines
Is there any example where the current
behavior is actually a problem - two modules which it makes sense to stack, which both need to give output under ps?I don't know. Isn't this the big negative against stacker, controlling the composition? pstools has clearly cast it's vote :-)
Well, pstools combined with existing userspace tools. I think the older version of stacker outputed comma-delimited output for each module. But that requires changes in the selinux userspace tools for things to work at all. That doesn't mean it's not the better way to solve the problem. So for instance we could output
staff_u:staff_r:serge_t(selinux),jail3(bsdjail)
-serge
[email protected]
maintainerQuoted 7 lines · Tony Jones
Quoted 4 lines
Yes, after I added the unlink function, it started to seem that the special cases for !CONFIG_SECURITY_STACKER wouldn't be any faster than the stacker versions. They still might be, but I'll have to think about it. If I just ditch those, then I can probably ditch the whole
Esp since James' suggestion would impact it. I'd imagine you would always want array[0] for this case, no?
Actually I don't think that's even needed - I just wasn't thinking right while addressing another bug.
thanks,
-serge