Ability to allow undefined permissions and classes -v3
RFC 1/1 Ability to allow undefined permissions and classes -v3
After many months this RFC is back again! Still has the selinuxfs boolean to turn it on and off that will get changed to a policy option when the actual functionality seems reasonable to everyone. The only change between -v2 and -v3 is in context_struct_compute_av(). In wake of the last discussion I had to make the class checking more stringent so I wouldn't be allowing userspace classes. Previously the decision for an 'unknown class' was anything larger than the last defined in policy. Now it should be a bit more kernel specific and should check
less than policy
greater than policy but less than number of kernel classes greater than policy and greater than number of kernel classes
less than policy means it is defined in policy and so just deal with the permissions. greater than both means its invalid. So the case in the middle is interesting if the request is actually 'hole' in the kernel defs because of the removal of userspace classes. So that check makes it a little more complex. Until the userspace class definitions actually turn to NULL in kernel this isn't 'perfect' and might mistake a userspace class for a kernel class but that should only temporarily (until the classes are actually gone which will likely be the case when this patch is applied) affect selinuxfs answers.
I think what this means though is that I don't need a special call from selinuxfs to answer access questions. If the request from selinuxfs is asking about kernel permissions it will get exactly the answer the kernel would have made. If the check is about userspace permissions it will answer as best the policy knows but the 'allow unknown' stuff won't change that answer since it only mucks with things defined by the kdefs.
I do have a question if my method of storing an array of size kdefs->cts_len is going to work going forward. How is the policy going to grow? Will we have gaps of potentially hundreds of classes and then add a new kernel class? If so I will have a large waste in my array. Its already the case that this proposed array is wasting space for all of the userspace classes as it stands.
-Eric
security/selinux/hooks.c | 2 + security/selinux/include/avc.h | 2 + security/selinux/selinuxfs.c | 56 +++++++++++++++++++++++++++++++++ security/selinux/ss/policydb.c | 2 + security/selinux/ss/policydb.h | 2 + security/selinux/ss/services.c | 68 +++++++++++++++++++++++++++++++++------ 6 files changed, 121 insertions(+), 11 deletions(-)
security/selinux/ss/policydb.c +2 -0
@@ -670,6 +670,8 @@ void policydb_destroy(struct policydb *p) }kfree (p->type_attr_map); +kfree (p->undefined_perms); +return ; }
security/selinux/ss/policydb.h +2 -0
@@ -242,6 +242,8 @@ struct policydb {struct ebitmap *type_attr_map;unsigned int policyvers; + +u32 *undefined_perms; };extern void policydb_destroy (struct policydb *p);
security/selinux/ss/services.c +57 -11
128 lines not on this page · raw message
security/selinux/hooks.c +2 -0
@@ -86,6 +86,8 @@ extern unsigned int policydb_loaded_version;extern int selinux_nlmsg_lookup (u16 sclass,u16 nlmsg_type,u32 *perm);extern int selinux_compat_net; +int selinux_allow_unknown_sysctl_value =0 ; +#ifdef CONFIG_SECURITY_SELINUX_DEVELOP int selinux_enforcing =0 ;
security/selinux/include/avc.h +2 -0
@@ -18,6 +18,8 @@#include "av_permissions.h" #include "security.h" +extern int selinux_allow_unknown_sysctl_value; +#ifdef CONFIG_SECURITY_SELINUX_DEVELOP extern int selinux_enforcing;#else
security/selinux/selinuxfs.c +56 -0
85 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Eric Paris
add a new kernel class? If so I will have a large waste in my array. Its already the case that this proposed array is wasting space for all of the userspace classes as it stands.
Is this patch against my for-akpm branch?
security/selinux/ss/services.c static int validate_classes(struct policydb *p) · line 1081
Quoted 1 line
security/selinux/ss/services.c +1
-0+ p->undefined_perms =kzalloc (sizeof (u32)*num_classes,GFP_KERNEL );
Use kcalloc().
Otherwise looks ok to me.
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 13 lines · Eric Paris
After many months this RFC is back again! Still has the selinuxfs boolean to turn it on and off that will get changed to a policy option when the actual functionality seems reasonable to everyone. The only change between -v2 and -v3 is in
context_struct_compute_av(). In wake of the last discussion I had to make the class checking more stringent so I wouldn't be allowing userspace classes. Previously the decision for an 'unknown class' was anything larger than the last defined in policy. Now it should be a bit more kernel specific and should checkless than policy
greater than policy but less than number of kernel classes greater than policy and greater than number of kernel classes
Quoted 9 lines
less than policy means it is defined in policy and so just deal with the permissions. greater than both means its invalid. So the case in the middle is interesting if the request is actually 'hole' in the kernel defs because of the removal of userspace classes. So that check makes it a little more complex. Until the userspace class definitions actually turn to NULL in kernel this isn't 'perfect' and might mistake a userspace class for a kernel class but that should only temporarily (until the classes are actually gone which will likely be the case when this patch is applied) affect selinuxfs answers.
You can assume the userspace classes to be removed for your patch, as the removal patch has been submitted upstream.
Quoted 7 lines
I think what this means though is that I don't need a special call from selinuxfs to answer access questions. If the request from selinuxfs is asking about kernel permissions it will get exactly the answer the kernel would have made. If the check is about userspace permissions it will answer as best the policy knows but the 'allow unknown' stuff won't change that answer since it only mucks with things defined by the kdefs.
Quoted 6 lines
I do have a question if my method of storing an array of size
kdefs->cts_lenis going to work going forward. How is the policy going to grow? Will we have gaps of potentially hundreds of classes and then add a new kernel class? If so I will have a large waste in my array. Its already the case that this proposed array is wasting space for all of the userspace classes as it stands.
With the userspace class/perm discovery support (in progress by Chris, and libselinux already provides the interfaces for looking them up from string), we should be able to easily relocate userspace classes in the future to allow insertion of kernel classes before any further userspace classes.
security/selinux/ss/services.c line 62
Quoted 9 lines
security/selinux/ss/services.c +1
-0@@ -59,6 +59,7 @@extern void selnl_notify_policyload (u32 seqno);unsigned int policydb_loaded_version; +int selinux_allow_unknown =0 ;
Just to note, this will become a policydb flag rather than a global when you turn this behavior into a policy config option. And a tristate, right? reject-policy-at-load, accept-policy-but-deny-unknown, accept-policy-and-allow-unknown
security/selinux/ss/services.c static int context_struct_compute_av(struct context *scontext, · line 323
Quoted 7 lines
security/selinux/ss/services.c +3
-0@@ -323,6 +318,39 @@ static int context_struct_compute_av(struct context *scontext, avd->seqno = latest_granting;/* +* Check if the class in question is a kernel class and if it +* is defined in policy. If yes to both it will pad the allow +* for undefined perms if appropriete.
Spelling.
security/selinux/ss/services.c static int context_struct_compute_av(struct context *scontext, · line 334
Quoted 11 lines
security/selinux/ss/services.c +11
-0+*/ +if (unlikely (!tclass)) { +printk (KERN_ERR "security_compute_av: unrecognized class 0" ); +return -EINVAL ; + } +if (unlikely (tclass > policydb.p_classes.nprim)) { +if (tclass > kdefs->cts_len || !selinux_allow_unknown) { +printk (KERN_ERR "security_compute_av: unrecognized " , +"class %d\n" , tclass); +return -EINVAL ; + }else {
As the if clause always returns, no need for explicit else, just fall through.
security/selinux/ss/services.c static int context_struct_compute_av(struct context *scontext, · line 337
Quoted 3 lines
security/selinux/ss/services.c +3
-0+/* +* kernel class not in policy, but we +* allow uknown, so let everything through
Spelling.
security/selinux/ss/services.c static int context_struct_compute_av(struct context *scontext, · line 342
Quoted 5 lines
security/selinux/ss/services.c +5
-0+*/ + avd->allowed =0xffffffff ; +return 0 ; + } + }else
As both clauses of the if clause always return, no need for explicit else, just fall through.
Quoted 7 lines
security/selinux/ss/services.c +2
-0@@ -1079,14 +1114,18 @@ static int validate_classes(struct policydb *p)printk (KERN_INFO "security: permission %s in class %s not defined in policy\n" , def_perm, pol_class); +if (selinux_allow_unknown) + p->undefined_perms[class_val-1 ] |= perm_val;continue ;
security/selinux/ss/services.c static int validate_classes(struct policydb *p) · line 1127
Quoted 10 lines
security/selinux/ss/services.c +3
-2} perdatum =hashtab_search (perms->table, def_perm);if (perdatum ==NULL ) { -printk (KERN_ERR +printk (KERN_INFO "security: permission %s in class %s not found in policy\n" , def_perm, pol_class); -return -EINVAL ; +if (selinux_allow_unknown) + p->undefined_perms[class_val-1 ] |= perm_val;
In the reject-policy case, you'd want to still return -EINVAL here and reject policy at load time.
Quoted 11 lines
security/selinux/ss/services.c +3
-0+continue ; } pol_val =1 << (perdatum->value -1 );if (pol_val != perm_val) {@@ -1122,14 +1161,18 @@ static int validate_classes(struct policydb *p)printk (KERN_INFO "security: permission %s in class %s not defined in policy\n" , def_perm, pol_class); +if (selinux_allow_unknown) + p->undefined_perms[class_val-1 ] |= (1 << j);continue ;
security/selinux/ss/services.c static int validate_classes(struct policydb *p) · line 1174
Quoted 10 lines
security/selinux/ss/services.c +3
-2} perdatum =hashtab_search (perms->table, def_perm);if (perdatum ==NULL ) { -printk (KERN_ERR +printk (KERN_INFO "security: permission %s in class %s not found in policy\n" , def_perm, pol_class); -return -EINVAL ; +if (selinux_allow_unknown) + p->undefined_perms[class_val-1 ] |= (1 << j);
Ditto.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 6 lines · Stephen Smalley
Quoted 6 lines
security/selinux/ss/services.c +0
-0@@ -59,6 +59,7 @@
Quoted 8 lines
security/selinux/ss/services.c line 62
Quoted 3 lines
security/selinux/ss/services.c +1
-0extern void selnl_notify_policyload (u32 seqno);unsigned int policydb_loaded_version; +int selinux_allow_unknown =0 ;Just to note, this will become a policydb flag rather than a global when you turn this behavior into a policy config option. And a tristate, right? reject-policy-at-load, accept-policy-but-deny-unknown, accept-policy-and-allow-unknown
Here is my first stab at a completed kernel half. As I write this e-mail I have a thought, if it's set for rejecting policy should I promote the printk's about missing classes/perms to something higher than INFO?
I'm going to start working on how to make this new set of bits work in userspace so I can actually test that any of this works. Although I must admit seeing something like
int policydb_write(policydb_t * p, struct policy_file *fp)
makes me want to gouge my eyes out. to struct or to typedef? Why decide, just do both randomly! *smile*
-Eric
security/selinux/hooks.c +0 -0
security/selinux/include/avc.h +0 -0
security/selinux/selinuxfs.c +0 -0
security/selinux/ss/policydb.c +4 -0
@@ -670,6 +670,8 @@ void policydb_destroy(struct policydb *p) }kfree (p->type_attr_map); +kfree (p->undefined_perms); +return ; }
@@ -1523,6 +1525,8 @@ int policydb_read(struct policydb *p, void *fp) goto bad; } } + p->allow_unknown =le32_to_cpu (buf[1 ]) &POLICYDB_CONFIG_UNKNOWN_MASK ; + p->allow_unknown >>=POLICYDB_CONFIG_UNKNOWN_SHIFT ; info =policydb_lookup_compat (p->policyvers);if (!info) {
security/selinux/ss/policydb.h +13 -0
@@ -242,6 +242,9 @@ struct policydb {struct ebitmap *type_attr_map;unsigned int policyvers; + +int allow_unknown; +u32 *undefined_perms; };extern void policydb_destroy (struct policydb *p);
@@ -253,6 +256,16 @@ extern int policydb_read(struct policydb *p, void *fp);#define POLICYDB_CONFIG_MLS 1 +/* the config flags related to unknown classes/perms are bits 2 and 3 */ +#define POLICYDB_CONFIG_UNKNOWN_MASK 6 +#define POLICYDB_CONFIG_UNKNOWN_SHIFT 1 + +enum policy_with_unknown_perms { +DENY_UNKNOWN =0 , +REJECT_UNKNOWN =1 , +ALLOW_UNKNOWN =2 +}; +#define OBJECT_R "object_r"#define OBJECT_R_VAL 1
security/selinux/ss/services.c +68 -11
139 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.