selinux: Fix security_compute_av() to not return unknown class errors when in permissive mode
RFC PATCH v3 1/1 selinux: Fix security_compute_av() to not return unknown class errors when in permissive mode
It is possible security_compute_av() to return -EINVAL, even when in permissive mode, due to unknown object classes and SIDs. This patch fixes this by doing away with the return value for security_compute_av() and treating unknown classes and SIDs as permission denials.
NOTE: This patch has only been compile tested, and is only intended for review. However, if someone wants to give it a try I would appreciate it as my time is somewhat limited since I'm technically on "vacation" as of a few hours ago :)
--- security/selinux/avc.c | 14 ++-- security/selinux/include/security.h | 8 +- security/selinux/selinuxfs.c | 4 + security/selinux/ss/services.c | 113 +++++++++++++---------------------- 4 files changed, 54 insertions(+), 85 deletions(-)
security/selinux/avc.c +5 -9
@@ -731,7 +731,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,struct avc_node *node;struct av_decision avd_entry, *avd;int rc =0 ; -u32 denied;BUG_ON (!requested);
@@ -746,9 +745,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {
@@ -757,12 +754,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, avd = &node->ae.avd; } - denied = requested & ~(avd->allowed); - -if (denied) { +if (requested & ~(avd->allowed)) {if (flags &AVC_STRICT ) rc = -EACCES ; -else if (!selinux_enforcing || (avd->flags &AVD_FLAGS_PERMISSIVE )) +else if (!selinux_enforcing || + (avd->flags &AVD_FLAGS_PERMISSIVE ))avc_update_node (AVC_CALLBACK_GRANT , requested, ssid, tsid, tclass, avd->seqno);else
@@ -770,7 +766,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out: +return rc; }
security/selinux/include/security.h +3 -5
@@ -96,12 +96,10 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid,u16 tclass, +struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, +int security_compute_av_user (u32 ssid,u32 tsid,u16 tclass,struct av_decision *avd); int security_transition_sid(u32 ssid, u32 tsid,
security/selinux/selinuxfs.c +3 -1
@@ -511,6 +511,8 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (!tcon) goto out; +/* note: we don't currently use "req" anymore but we'll leave it here +* just to preserve/enforce the existing userspace API */ length = -EINVAL ;if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) goto out2;
@@ -522,7 +524,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); + length =security_compute_av_user (ssid, tsid, tclass, &avd);if (length <0 ) goto out2;
security/selinux/ss/services.c +43 -70
225 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.
Stephen Smalley
NAKQuoted 5 lines · Paul Moore
It is possible
security_compute_av()to return-EINVAL, even when in permissive mode, due to unknown object classes and SIDs. This patch fixes this by doing away with the return value forsecurity_compute_av()and treating unknown classes and SIDs as permission denials.
Quoted 7 lines
NOTE: This patch has only been compile tested, and is only intended for review. However, if someone wants to give it a try I would appreciate it as my time is somewhat limited since I'm technically on "vacation" as of a few hours ago :)
Reported-by Andrew Worsley <[email protected]>Signed-off-by Paul Moore <[email protected]>
NAK.
Sorry, but I think we need to reconsider this patch, as separating the initialization of the avd from the remainder of the computation inside of context_struct_compute_av is fragile, as is separating the printk error message from the actual error checking (and allow_unknown isn't relevant in that particular case - we have already covered it after we unmap the class).
Quoted 344 lines
--- security/selinux/avc.c | 14 ++-- security/selinux/include/security.h | 8 +- security/selinux/selinuxfs.c | 4 + security/selinux/ss/services.c | 113 +++++++++++++---------------------- 4 files changed, 54 insertions(+), 85 deletions(-)security/selinux/avc.c +5
-9@@ -731,7 +731,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,struct avc_node *node;struct av_decision avd_entry, *avd;int rc =0 ; -u32 denied;BUG_ON (!requested);@@ -746,9 +745,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {@@ -757,12 +754,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, avd = &node->ae.avd; } - denied = requested & ~(avd->allowed); - -if (denied) { +if (requested & ~(avd->allowed)) {if (flags &AVC_STRICT ) rc = -EACCES ; -else if (!selinux_enforcing || (avd->flags &AVD_FLAGS_PERMISSIVE )) +else if (!selinux_enforcing || + (avd->flags &AVD_FLAGS_PERMISSIVE ))avc_update_node (AVC_CALLBACK_GRANT , requested, ssid, tsid, tclass, avd->seqno);else @@ -770,7 +766,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out: +return rc; }security/selinux/include/security.h +3
-5@@ -96,12 +96,10 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid,u16 tclass, +struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, +int security_compute_av_user (u32 ssid,u32 tsid,u16 tclass,struct av_decision *avd); int security_transition_sid(u32 ssid, u32 tsid,security/selinux/selinuxfs.c +3
-1@@ -511,6 +511,8 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (!tcon) goto out; +/* note: we don't currently use "req" anymore but we'll leave it here +* just to preserve/enforce the existing userspace API */ length = -EINVAL ;if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) goto out2;@@ -522,7 +524,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); + length =security_compute_av_user (ssid, tsid, tclass, &avd);if (length <0 ) goto out2;security/selinux/ss/services.c +43
-71@@ -90,7 +90,6 @@ static int context_struct_to_string(struct context *context, char **scontext,static int context_struct_compute_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd);struct selinux_mapping {@@ -196,23 +195,6 @@ static u16 unmap_class(u16 tclass)return tclass; } -static u32 unmap_perm (u16 tclass,u32 tperm) -{ -if (tclass < current_mapping_size) { -unsigned i; -u32 kperm =0 ; - -for (i =0 ; i < current_mapping[tclass].num_perms; i++) -if (tperm & (1 <<i)) { - kperm |= current_mapping[tclass].perms[i]; - tperm &= ~(1 <<i); - } -return kperm; - } - -return tperm; -} -static void map_decision (u16 tclass,struct av_decision *avd,int allow_unknown) {@@ -532,7 +514,6 @@ out:static void type_attribute_bounds_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct context lo_scontext;@@ -553,7 +534,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -569,7 +549,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -586,7 +565,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -610,7 +588,6 @@ static void type_attribute_bounds_av(struct context *scontext,static int context_struct_compute_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct constraint_node *constraint;@@ -622,20 +599,8 @@ static int context_struct_compute_av(struct context *scontext,struct ebitmap_node *snode, *tnode;unsigned int i, j; -/* -* Initialize the access vectors to the default values. -*/ - avd->allowed =0 ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - -if (unlikely (!tclass || tclass > policydb.p_classes.nprim)) { -if (printk_ratelimit ()) -printk (KERN_WARNING "SELinux: Invalid class %hu\n" , tclass); +if (unlikely (!tclass || tclass > policydb.p_classes.nprim))return -EINVAL ; - } tclass_datum = policydb.class_val_to_struct[tclass -1 ];@@ -704,8 +669,7 @@ static int context_struct_compute_av(struct context *scontext,* constraint, lazy checks have to mask any violated * permission and notice it to userspace via audit. */ -type_attribute_bounds_av (scontext, tcontext, - tclass, requested, avd); +type_attribute_bounds_av (scontext, tcontext, tclass, avd);return 0 ; }@@ -890,11 +854,11 @@ out:static int security_compute_av_core (u32 ssid,u32 tsid,u16 tclass, -u32 requested, +int allow_unknown,struct av_decision *avd) {struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; +int rc; scontext =sidtab_search (&sidtab, ssid);if (!scontext) {@@ -909,8 +873,9 @@ static int security_compute_av_core(u32 ssid,return -EINVAL ; } - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); + rc =context_struct_compute_av (scontext, tcontext, tclass, avd); +if (rc == -EINVAL && !allow_unknown &&printk_ratelimit ()) +printk (KERN_WARNING "SELinux: Invalid class %hu\n" , tclass);/* permissive domain? */ if (ebitmap_get_bit (&policydb.permissive_map, scontext->type))@@ -924,70 +889,78 @@ static int security_compute_av_core(u32 ssid,* @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested;int rc;read_lock (&policy_rwlock); +/* Initialize the access vectors to the default values. */ + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized) goto allow; - requested =unmap_perm (orig_tclass, orig_requested); tclass =unmap_class (orig_tclass); -if (unlikely (orig_tclass && !tclass)) { -if (policydb.allow_unknown) - goto allow; - rc = -EINVAL ; - goto out; - } - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +if (unlikely (orig_tclass && !tclass)) + goto error; + rc =security_compute_av_core (ssid, tsid, tclass, + policydb.allow_unknown, avd); +if (unlikely (rc !=0 )) + goto error;map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; + goto out; +error: +if (policydb.allow_unknown) + goto allow; + avd->allowed =0 ; avd->auditallow =0 ; avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; }int security_compute_av_user (u32 ssid,u32 tsid,u16 tclass, -u32 requested,struct av_decision *avd) {int rc; +read_lock (&policy_rwlock); + +/* Initialize the access vectors to the default values. */ + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized) { avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; -return 0 ; + rc =0 ; + goto out; } -read_lock (&policy_rwlock); - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); + rc =security_compute_av_core (ssid, tsid, tclass,0 , avd); +out:read_unlock (&policy_rwlock);return rc; } --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.
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 14 lines · Stephen Smalley
Quoted 5 lines · Paul Moore
It is possible
security_compute_av()to return-EINVAL, even when in permissive mode, due to unknown object classes and SIDs. This patch fixes this by doing away with the return value forsecurity_compute_av()and treating unknown classes and SIDs as permission denials.Quoted 7 lines
NOTE: This patch has only been compile tested, and is only intended for review. However, if someone wants to give it a try I would appreciate it as my time is somewhat limited since I'm technically on "vacation" as of a few hours ago :)
Reported-by Andrew Worsley <[email protected]>Signed-off-by Paul Moore <[email protected]>
Quoted 8 lines
NAK.
Sorry, but I think we need to reconsider this patch, as separating the initialization of the avd from the remainder of the computation inside of
context_struct_compute_avis fragile, as is separating the printk error message from the actual error checking (andallow_unknownisn't relevant in that particular case - we have already covered it after we unmap the class).
Okay, no problem, you know these bits of code far better than I do.
However, since I seem to keep missing the mark here some very explicit directions on the fix you would like to see would be helpful (I thought I had followed your previous suggestions but evidently I was off) or feel free to cobble something up yourself ... ;)
Quoted 35 lines
Quoted 35 lines
--- security/selinux/avc.c | 14 ++-- security/selinux/include/security.h | 8 +- security/selinux/selinuxfs.c | 4 + security/selinux/ss/services.c | 113+++++++++++++---------------------- 4 files changed, 54 insertions(+), 85 deletions(-)
security/selinux/avc.c +1
-4@@ -731,7 +731,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,struct avc_node *node;struct av_decision avd_entry, *avd;int rc =0 ; -u32 denied;BUG_ON (!requested);@@ -746,9 +745,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {@@ -757,12 +754,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, avd = &node->ae.avd; }
Quoted 7 lines
security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid,
Quoted 7 lines
security/selinux/avc.c +1
-4- denied = requested & ~(avd->allowed); - -if (denied) { +if (requested & ~(avd->allowed)) {if (flags &AVC_STRICT ) rc = -EACCES ; - else if (!selinux_enforcing || (avd->flags &
AVD_FLAGS_PERMISSIVE))
Quoted 137 lines
Quoted 137 lines
security/selinux/avc.c +3
-1+else if (!selinux_enforcing || + (avd->flags &AVD_FLAGS_PERMISSIVE ))avc_update_node (AVC_CALLBACK_GRANT , requested, ssid, tsid, tclass, avd->seqno);else @@ -770,7 +766,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out: +return rc; }(quoted diff) +0
-0
b/security/selinux/include/security.hindex 2553266..609334d 100644security/selinux/include/security.h +3
-5@@ -96,12 +96,10 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid,u16 tclass, +struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, +int security_compute_av_user (u32 ssid,u32 tsid,u16 tclass,struct av_decision *avd); int security_transition_sid(u32 ssid, u32 tsid,security/selinux/selinuxfs.c +3
-1@@ -511,6 +511,8 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) if (!tcon) goto out; +/* note: we don't currently use "req" anymore but we'll leave it here +* just to preserve/enforce the existing userspace API */ length = -EINVAL ;if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) goto out2;@@ -522,7 +524,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) if (length < 0) goto out2; - length = security_compute_av_user(ssid, tsid, tclass, req, &avd); + length = security_compute_av_user(ssid, tsid, tclass, &avd);if (length <0 ) goto out2;(quoted diff) +0
-0
b/security/selinux/ss/services.cindex b3efae2..e789b34 100644security/selinux/ss/services.c +0
-1@@ -90,7 +90,6 @@ static int context_struct_to_string(struct context *context, char **scontext, static int context_struct_compute_av(structcontext *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd);struct
selinux_mapping{security/selinux/ss/services.c +0
-22@@ -196,23 +195,6 @@ static u16 unmap_class(u16 tclass)return tclass; } -static u32 unmap_perm (u16 tclass,u32 tperm) -{ -if (tclass < current_mapping_size) { -unsigned i; -u32 kperm =0 ; - -for (i =0 ; i < current_mapping[tclass].num_perms; i++) -if (tperm & (1 <<i)) { - kperm |= current_mapping[tclass].perms[i]; - tperm &= ~(1 <<i); - } -return kperm; - } - -return tperm; -} -static void map_decision (u16 tclass,struct av_decision *avd,int allow_unknown) {@@ -532,7 +514,6 @@ out:static void type_attribute_bounds_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct context lo_scontext;@@ -553,7 +534,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -569,7 +549,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -586,7 +565,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -610,7 +588,6 @@ static void type_attribute_bounds_av(struct context *scontext, static int context_struct_compute_av(struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct constraint_node *constraint;@@ -622,20 +599,8 @@ static int context_struct_compute_av(struct context *scontext, struct ebitmap_node *snode, *tnode;unsigned int i, j;
Quoted 12 lines
security/selinux/ss/services.c static int context_struct_compute_av(struct context *scontext,
Quoted 12 lines
security/selinux/ss/services.c +0
-12-/* -* Initialize the access vectors to the default values. -*/ - avd->allowed =0 ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - -if (unlikely (!tclass || tclass > policydb.p_classes.nprim)) { -if (printk_ratelimit ()) - printk(KERN_WARNING "SELinux: Invalid class %hu\n",
tclass);
Quoted 156 lines
Quoted 155 lines
security/selinux/ss/services.c +43
-36+if (unlikely (!tclass || tclass > policydb.p_classes.nprim))return -EINVAL ; - } tclass_datum = policydb.class_val_to_struct[tclass -1 ];@@ -704,8 +669,7 @@ static int context_struct_compute_av(struct context*scontext, * constraint, lazy checks have to mask any violated * permission and notice it to userspace via audit. */ -type_attribute_bounds_av (scontext, tcontext, - tclass, requested, avd); +type_attribute_bounds_av (scontext, tcontext, tclass, avd);return 0 ; }@@ -890,11 +854,11 @@ out:static int security_compute_av_core (u32 ssid,u32 tsid,u16 tclass, -u32 requested, +int allow_unknown,struct av_decision *avd) {struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; +int rc; scontext =sidtab_search (&sidtab, ssid);if (!scontext) {@@ -909,8 +873,9 @@ static int security_compute_av_core(u32 ssid,return -EINVAL ; } - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); + rc =context_struct_compute_av (scontext, tcontext, tclass, avd); +if (rc == -EINVAL && !allow_unknown &&printk_ratelimit ()) +printk (KERN_WARNING "SELinux: Invalid class %hu\n" , tclass);/* permissive domain? */ if (ebitmap_get_bit (&policydb.permissive_map, scontext->type))@@ -924,70 +889,78 @@ static int security_compute_av_core(u32 ssid,* @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested;int rc;read_lock (&policy_rwlock); +/* Initialize the access vectors to the default values. */ + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized) goto allow; - requested =unmap_perm (orig_tclass, orig_requested); tclass =unmap_class (orig_tclass); -if (unlikely (orig_tclass && !tclass)) { -if (policydb.allow_unknown) - goto allow; - rc = -EINVAL ; - goto out; - } - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +if (unlikely (orig_tclass && !tclass)) + goto error; + rc =security_compute_av_core (ssid, tsid, tclass, + policydb.allow_unknown, avd); +if (unlikely (rc !=0 )) + goto error;map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; + goto out; +error: +if (policydb.allow_unknown) + goto allow; + avd->allowed =0 ; avd->auditallow =0 ; avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; }int security_compute_av_user (u32 ssid,u32 tsid,u16 tclass, -u32 requested,struct av_decision *avd) {int rc; +read_lock (&policy_rwlock); + +/* Initialize the access vectors to the default values. */ + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized) { avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; -return 0 ; + rc =0 ; + goto out; } -read_lock (&policy_rwlock); - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); + rc =security_compute_av_core (ssid, tsid, tclass,0 , avd); +out:read_unlock (&policy_rwlock);return rc; } --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.
Signature · 7 lines
paul moore linux @ hp -- 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.
RFC PATCH 1/1 selinux: change the handling of unknown classes
In reply to Paul MooreIf allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode logic. This change only affects the kernel permission checking; userspace requests for access computations will still return errors upon invalid classes, since the userspace AVC handles mapping of classes and permissions for userspace object managers.
Also drop the 'requested' argument from security_compute_av() and helpers as it is a legacy of the original security server interface and is unused.
Based in part on a patch by Paul Moore <[email protected]>.
---
security/selinux/avc.c | 5 -- security/selinux/include/security.h | 8 +--- security/selinux/selinuxfs.c | 5 +- security/selinux/ss/services.c | 63 ++++++++---------------------------- 4 files changed, 21 insertions(+), 60 deletions(-)
security/selinux/avc.c +1 -4
@@ -746,9 +746,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {
@@ -770,7 +768,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out:return rc; }
security/selinux/include/security.h +3 -5
@@ -96,13 +96,11 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd);int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +u16 tclass,struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);
security/selinux/selinuxfs.c +2 -3
@@ -494,7 +494,6 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)char *scon, *tcon;u32 ssid, tsid;u16 tclass; -u32 req;struct av_decision avd;ssize_t length;
@@ -512,7 +511,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) goto out; length = -EINVAL ; -if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) +if (sscanf (buf,"%s %s %hu" , scon, tcon, &tclass) !=3 ) goto out2; length =security_context_to_sid (scon,strlen (scon)+1 , &ssid);
@@ -522,7 +521,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); + length =security_compute_av_user (ssid, tsid, tclass, &avd);if (length <0 ) goto out2;
security/selinux/ss/services.c +15 -48
165 lines not on this page · raw message
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.
Re: [RFC][PATCH] selinux: change the handling of unknown classes
Quoted 10 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode logic. This change only affects the kernel permission checking; userspace requests for access computations will still return errors upon invalid classes, since the userspace AVC handles mapping of classes and permissions for userspace object managers.
Quoted 8 lines
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>
Thanks :) I do have one question (below) ...
Quoted 35 lines
security/selinux/ss/services.c +10
-10@@ -924,56 +899,48 @@ static int security_compute_av_core(u32 ssid,* @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested; -int rc;read_lock (&policy_rwlock); + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized)
security/selinux/ss/services.c static int security_compute_av_core(u32 ssid, · line 930
Quoted 10 lines
security/selinux/ss/services.c +0
-2goto allow; - requested =unmap_perm (orig_tclass, orig_requested); tclass =unmap_class (orig_tclass);if (unlikely (orig_tclass && !tclass)) {if (policydb.allow_unknown) goto allow; - rc = -EINVAL ; goto out; }
Since we don't check for a permissive domain until security_compute_av_core() I assume this means that an unknown class will still cause problems for permissive domains when the system as a whole is in enforcing mode - or am I missing something?
Quoted 16 lines
security/selinux/ss/services.c +2
-7- rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); + (void )security_compute_av_core (ssid, tsid, tclass, avd);map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; }
Signature · 7 lines
paul moore linux @ hp -- 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.
Re: [RFC][PATCH] selinux: change the handling of unknown classes
Quoted 59 lines · Paul Moore
Quoted 10 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode logic. This change only affects the kernel permission checking; userspace requests for access computations will still return errors upon invalid classes, since the userspace AVC handles mapping of classes and permissions for userspace object managers.
Quoted 8 lines
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>Thanks :) I do have one question (below) ...
Quoted 37 lines
security/selinux/ss/services.c +10
-10@@ -924,56 +899,48 @@ static int security_compute_av_core(u32 ssid,* @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested; -int rc;read_lock (&policy_rwlock); + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; +if (!ss_initialized) goto allow;
Quoted 13 lines
security/selinux/ss/services.c static int security_compute_av_core(u32 ssid, · line 930
Quoted 8 lines
security/selinux/ss/services.c +0
-2- requested =unmap_perm (orig_tclass, orig_requested); tclass =unmap_class (orig_tclass);if (unlikely (orig_tclass && !tclass)) {if (policydb.allow_unknown) goto allow; - rc = -EINVAL ; goto out; }Since we don't check for a permissive domain until
security_compute_av_core()I assume this means that an unknown class will still cause problems for permissive domains when the system as a whole is in enforcing mode - or am I missing something?
That sounds correct. To address that, we'd have to move the processing required to set AVD_FLAGS_PERMISSIVE to the entry of security_compute_av(), which means we'd have to perform the lookup of the ssid and the ebitmap_get_bit() test in security_compute_av() [and security_compute_av_user()]. At which point we might as well inline all of security_compute_av_core() into its two callers.
Quoted 19 lines
Quoted 17 lines
security/selinux/ss/services.c +2
-7- rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); + (void )security_compute_av_core (ssid, tsid, tclass, avd);map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; }
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.
RFC PATCH v2 1/1 selinux: change the handling of unknown classes
In reply to Paul MooreIf allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from security_compute_av() and helpers as it is a legacy of the original security server interface and is unused.
Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Make security_compute_av_user() consistent with security_compute_av(); the only difference now is that security_compute_av() performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.
Based in part on a patch by Paul Moore <[email protected]>.
---
security/selinux/avc.c | 5 security/selinux/include/security.h | 10 - security/selinux/selinuxfs.c | 7 - security/selinux/ss/services.c | 186 +++++++++++++++--------------------- 4 files changed, 89 insertions(+), 119 deletions(-)
security/selinux/avc.c +1 -4
@@ -746,9 +746,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {
@@ -770,7 +768,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out:return rc; }
security/selinux/include/security.h +4 -6
@@ -96,13 +96,11 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av_user (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);
security/selinux/selinuxfs.c +2 -5
@@ -494,7 +494,6 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)char *scon, *tcon;u32 ssid, tsid;u16 tclass; -u32 req;struct av_decision avd;ssize_t length;
@@ -512,7 +511,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) goto out; length = -EINVAL ; -if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) +if (sscanf (buf,"%s %s %hu" , scon, tcon, &tclass) !=3 ) goto out2; length =security_context_to_sid (scon,strlen (scon)+1 , &ssid);
@@ -522,9 +521,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); -if (length <0 ) - goto out2; +security_compute_av_user (ssid, tsid, tclass, &avd); length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%x %x %x %x %u %x",
security/selinux/ss/services.c +82 -104
293 lines not on this page · raw message
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.
Re: [RFC][PATCH v2] selinux: change the handling of unknown classes
Quoted 19 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Makesecurity_compute_av_user()consistent withsecurity_compute_av(); the only difference now is thatsecurity_compute_av()performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.
Quoted 1 line
Based in part on a patch by Paul Moore <[email protected]>.
Ping?
Quoted 406 lines
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>---
security/selinux/avc.c | 5 security/selinux/include/security.h | 10 - security/selinux/selinuxfs.c | 7 - security/selinux/ss/services.c | 186 +++++++++++++++--------------------- 4 files changed, 89 insertions(+), 119 deletions(-)security/selinux/avc.c +1
-4@@ -746,9 +746,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {@@ -770,7 +768,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out:return rc; }security/selinux/include/security.h +4
-6@@ -96,13 +96,11 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av_user (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);security/selinux/selinuxfs.c +2
-5@@ -494,7 +494,6 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)char *scon, *tcon;u32 ssid, tsid;u16 tclass; -u32 req;struct av_decision avd;ssize_t length;@@ -512,7 +511,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) goto out; length = -EINVAL ; -if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) +if (sscanf (buf,"%s %s %hu" , scon, tcon, &tclass) !=3 ) goto out2; length =security_context_to_sid (scon,strlen (scon)+1 , &ssid);@@ -522,9 +521,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); -if (length <0 ) - goto out2; +security_compute_av_user (ssid, tsid, tclass, &avd); length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%x %x %x %x %u %x",security/selinux/ss/services.c +82
-104@@ -87,11 +87,10 @@ static u32 latest_granting;static int context_struct_to_string (struct context *context,char **scontext,u32 *scontext_len); -static int context_struct_compute_av (struct context *scontext, -struct context *tcontext, -u16 tclass, -u32 requested, -struct av_decision *avd); +static void context_struct_compute_av (struct context *scontext, +struct context *tcontext, +u16 tclass, +struct av_decision *avd);struct selinux_mapping {u16 value;/* policy value */ @@ -196,23 +195,6 @@ static u16 unmap_class(u16 tclass)return tclass; } -static u32 unmap_perm (u16 tclass,u32 tperm) -{ -if (tclass < current_mapping_size) { -unsigned i; -u32 kperm =0 ; - -for (i =0 ; i < current_mapping[tclass].num_perms; i++) -if (tperm & (1 <<i)) { - kperm |= current_mapping[tclass].perms[i]; - tperm &= ~(1 <<i); - } -return kperm; - } - -return tperm; -} -static void map_decision (u16 tclass,struct av_decision *avd,int allow_unknown) {@@ -532,7 +514,6 @@ out:static void type_attribute_bounds_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct context lo_scontext;@@ -553,7 +534,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -569,7 +549,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -586,7 +565,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -607,11 +585,10 @@ static void type_attribute_bounds_av(struct context *scontext,* Compute access vectors based on a context structure pair for * the permissions in a particular class. */ -static int context_struct_compute_av (struct context *scontext, -struct context *tcontext, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void context_struct_compute_av (struct context *scontext, +struct context *tcontext, +u16 tclass, +struct av_decision *avd) {struct constraint_node *constraint;struct role_allow *ra;@@ -622,19 +599,14 @@ static int context_struct_compute_av(struct context *scontext,struct ebitmap_node *snode, *tnode;unsigned int i, j; -/* -* Initialize the access vectors to the default values. -*/ avd->allowed =0 ; avd->auditallow =0 ; avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ;if (unlikely (!tclass || tclass > policydb.p_classes.nprim)) {if (printk_ratelimit ())printk (KERN_WARNING "SELinux: Invalid class %hu\n" , tclass); -return -EINVAL ; +return ; } tclass_datum = policydb.class_val_to_struct[tclass -1 ];@@ -705,9 +677,7 @@ static int context_struct_compute_av(struct context *scontext,* permission and notice it to userspace via audit. */ type_attribute_bounds_av (scontext, tcontext, - tclass, requested, avd); - -return 0 ; + tclass, avd); } static int security_validtrans_handle_fail(struct context *ocontext,@@ -886,110 +856,118 @@ out:return rc; } - -static int security_compute_av_core (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void avd_init (struct av_decision *avd) { -struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; - - scontext =sidtab_search (&sidtab, ssid); -if (!scontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, ssid); -return -EINVAL ; - } - tcontext =sidtab_search (&sidtab, tsid); -if (!tcontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, tsid); -return -EINVAL ; - } - - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); - -/* permissive domain? */ -if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) - avd->flags |=AVD_FLAGS_PERMISSIVE ; - -return rc; + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; } +/** * security_compute_av - Compute access vector decisions. * @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested; -int rc; +struct context *scontext =NULL , *tcontext =NULL ; +avd_init (avd);read_lock (&policy_rwlock);if (!ss_initialized) goto allow; - requested =unmap_perm (orig_tclass, orig_requested); + scontext =sidtab_search (&sidtab, ssid); +if (!scontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, ssid); + goto out; + } + +/* permissive domain? */ +if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) + avd->flags |=AVD_FLAGS_PERMISSIVE ; + + tcontext =sidtab_search (&sidtab, tsid); +if (!tcontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, tsid); + goto out; + } + tclass =unmap_class (orig_tclass);if (unlikely (orig_tclass && !tclass)) {if (policydb.allow_unknown) goto allow; - rc = -EINVAL ; goto out; } - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +context_struct_compute_av (scontext, tcontext, tclass, avd);map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; } -int security_compute_av_user (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +void security_compute_av_user (u32 ssid, +u32 tsid, +u16 tclass, +struct av_decision *avd) { -int rc; +struct context *scontext =NULL , *tcontext =NULL ; -if (!ss_initialized) { - avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; -return 0 ; +avd_init (avd); +read_lock (&policy_rwlock); + +if (!ss_initialized) + goto allow; + + scontext =sidtab_search (&sidtab, ssid); +if (!scontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, ssid); + goto out; } -read_lock (&policy_rwlock); - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +/* permissive domain? */ +if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) + avd->flags |=AVD_FLAGS_PERMISSIVE ; + + tcontext =sidtab_search (&sidtab, tsid); +if (!tcontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, tsid); + goto out; + } + +if (unlikely (!tclass)) { +if (policydb.allow_unknown) + goto allow; + goto out; + } + +context_struct_compute_av (scontext, tcontext, tclass, avd); + out:read_unlock (&policy_rwlock); -return rc; +return ; +allow: + avd->allowed =0xffffffff ; + goto out; }/* Signature · 9 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.
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.
Re: [RFC][PATCH v2] selinux: change the handling of unknown classes
In reply to Stephen SmalleyQuoted 23 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Makesecurity_compute_av_user()consistent withsecurity_compute_av(); the only difference now is thatsecurity_compute_av()performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>
...
Quoted 59 lines
security/selinux/ss/services.c +9
-37-static int security_compute_av_core (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void avd_init (struct av_decision *avd) { -struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; - - scontext =sidtab_search (&sidtab, ssid); -if (!scontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, ssid); -return -EINVAL ; - } - tcontext =sidtab_search (&sidtab, tsid); -if (!tcontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, tsid); -return -EINVAL ; - } - - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); - -/* permissive domain? */ -if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) - avd->flags |=AVD_FLAGS_PERMISSIVE ; - -return rc; + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; } +/** * security_compute_av - Compute access vector decisions. * @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av(u32 ssid, + u32 tsid,
security/selinux/ss/services.c out: · line 888
Quoted 10 lines
security/selinux/ss/services.c +4
-2+u16 orig_tclass, + struct av_decision *avd) { u16 tclass; -u32 requested; -int rc; +struct context *scontext =NULL , *tcontext =NULL ; +avd_init (avd);read_lock (&policy_rwlock);
The only thing that is jumping out at me right now is that you are calling avd_init() outside the policy lock and 'latest_granting' appears to be protected by the lock. Maybe not a huge deal since it is just a scalar but thought I would mention it; the same applies below in security_compute_av_user().
Signature · 7 lines
paul moore linux @ hp -- 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.
Re: [RFC][PATCH v2] selinux: change the handling of unknown classes
Quoted 94 lines · Paul Moore
Quoted 23 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Makesecurity_compute_av_user()consistent withsecurity_compute_av(); the only difference now is thatsecurity_compute_av()performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>...
Quoted 67 lines
security/selinux/ss/services.c +12
-39-static int security_compute_av_core (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void avd_init (struct av_decision *avd) { -struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; - - scontext =sidtab_search (&sidtab, ssid); -if (!scontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, ssid); -return -EINVAL ; - } - tcontext =sidtab_search (&sidtab, tsid); -if (!tcontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, tsid); -return -EINVAL ; - } - - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); - -/* permissive domain? */ -if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) - avd->flags |=AVD_FLAGS_PERMISSIVE ; - -return rc; + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; } +/** * security_compute_av - Compute access vector decisions. * @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested; -int rc; +struct context *scontext =NULL , *tcontext =NULL ;
Quoted 8 lines
security/selinux/ss/services.c out: · line 888
Quoted 2 lines
security/selinux/ss/services.c +1
-0+avd_init (avd);read_lock (&policy_rwlock);The only thing that is jumping out at me right now is that you are calling
avd_init()outside the policy lock and 'latest_granting' appears to be protected by the lock. Maybe not a huge deal since it is just a scalar but thought I would mention it; the same applies below insecurity_compute_av_user().
Good catch, I'll move it inside the lock.
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.
RFC PATCH v3 1/1 selinux: change the handling of unknown classes
In reply to Stephen SmalleyIf allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from security_compute_av() and helpers as it is a legacy of the original security server interface and is unused.
Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Make security_compute_av_user() consistent with security_compute_av(); the only difference now is that security_compute_av() performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.
- Moved avd_init inside the policy lock.
Based in part on a patch by Paul Moore <[email protected]>.
---
security/selinux/avc.c | 5 security/selinux/include/security.h | 10 - security/selinux/selinuxfs.c | 7 - security/selinux/ss/services.c | 186 +++++++++++++++--------------------- 4 files changed, 88 insertions(+), 120 deletions(-)
security/selinux/avc.c +1 -4
@@ -746,9 +746,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {
@@ -770,7 +768,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out:return rc; }
security/selinux/include/security.h +4 -6
@@ -96,13 +96,11 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av_user (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);
security/selinux/selinuxfs.c +2 -5
@@ -494,7 +494,6 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)char *scon, *tcon;u32 ssid, tsid;u16 tclass; -u32 req;struct av_decision avd;ssize_t length;
@@ -512,7 +511,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size) goto out; length = -EINVAL ; -if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) +if (sscanf (buf,"%s %s %hu" , scon, tcon, &tclass) !=3 ) goto out2; length =security_context_to_sid (scon,strlen (scon)+1 , &ssid);
@@ -522,9 +521,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); -if (length <0 ) - goto out2; +security_compute_av_user (ssid, tsid, tclass, &avd); length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%x %x %x %x %u %x",
security/selinux/ss/services.c +81 -105
292 lines not on this page · raw message
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.
Re: [RFC][PATCH v3] selinux: change the handling of unknown classes
Quoted 20 lines · Stephen Smalley
If allow_unknown==deny, SELinux treats an undefined kernel security class as an error condition rather than as a typical permission denial and thus does not allow permissions on undefined classes even when in permissive mode. Change the SELinux logic so that this case is handled as a typical permission denial, subject to the usual permissive mode and permissive domain handling.
Also drop the 'requested' argument from
security_compute_av()and helpers as it is a legacy of the original security server interface and is unused.Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Makesecurity_compute_av_user()consistent withsecurity_compute_av(); the only difference now is thatsecurity_compute_av()performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.
- Movedavd_initinside the policy lock.
Quoted 4 lines
Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>
Looks good to me ... pick whichever seems most appropriate :)
security/selinux/selinuxfs.c static ssize_t sel_write_access(struct file *file,
Quoted 59 lines
---
security/selinux/avc.c | 5 security/selinux/include/security.h | 10 - security/selinux/selinuxfs.c | 7 - security/selinux/ss/services.c | 186+++++++++++++++--------------------- 4 files changed, 88 insertions(+), 120 deletions(-)
security/selinux/avc.c +1
-4@@ -746,9 +746,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,else avd = &avd_entry; - rc =security_compute_av (ssid, tsid, tclass, requested, avd); -if (rc) - goto out; +security_compute_av (ssid, tsid, tclass, avd);rcu_read_lock (); node =avc_insert (ssid, tsid, tclass, avd); }else {@@ -770,7 +768,6 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, }rcu_read_unlock (); -out:return rc; }(quoted diff) +0
-0b/security/selinux/include/security.h index 2553266..022cf06 100644security/selinux/include/security.h +4
-6@@ -96,13 +96,11 @@ struct av_decision {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 -int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd); -int security_compute_av_user (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +void security_compute_av_user (u32 ssid,u32 tsid, +u16 tclass,struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);security/selinux/selinuxfs.c +0
-0@@ -494,7 +494,6 @@ static ssize_t sel_write_access(struct file *file,
char
security/selinux/selinuxfs.c static ssize_t sel_write_access(struct file *file,
Quoted 8 lines
security/selinux/selinuxfs.c +0
-1*buf, size_t size) char *scon, *tcon;u32 ssid, tsid;u16 tclass; -u32 req;struct av_decision avd;ssize_t length;@@ -512,7 +511,7 @@ static ssize_t sel_write_access(struct file *file,
char
security/selinux/selinuxfs.c static ssize_t sel_write_access(struct file *file,
Quoted 9 lines
security/selinux/selinuxfs.c +1
-1*buf, size_t size) goto out; length = -EINVAL ; -if (sscanf (buf,"%s %s %hu %x" , scon, tcon, &tclass, &req) !=4 ) +if (sscanf (buf,"%s %s %hu" , scon, tcon, &tclass) !=3 ) goto out2; length =security_context_to_sid (scon,strlen (scon)+1 , &ssid);@@ -522,9 +521,7 @@ static ssize_t sel_write_access(struct file *file,
char
Quoted 317 lines
security/selinux/selinuxfs.c +1
-3*buf, size_t size) if (length < 0) goto out2; - length =security_compute_av_user (ssid, tsid, tclass, req, &avd); -if (length <0 ) - goto out2; +security_compute_av_user (ssid, tsid, tclass, &avd); length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%x %x %x %x %u %x",(quoted diff) +0
-0b/security/selinux/ss/services.c index b3efae2..99e6e9d 100644security/selinux/ss/services.c +81
-105@@ -87,11 +87,10 @@ static u32 latest_granting;static int context_struct_to_string (struct context *context,char **scontext,u32 *scontext_len); -static int context_struct_compute_av (struct context *scontext, -struct context *tcontext, -u16 tclass, -u32 requested, -struct av_decision *avd); +static void context_struct_compute_av (struct context *scontext, +struct context *tcontext, +u16 tclass, +struct av_decision *avd);struct selinux_mapping {u16 value;/* policy value */ @@ -196,23 +195,6 @@ static u16 unmap_class(u16 tclass)return tclass; } -static u32 unmap_perm (u16 tclass,u32 tperm) -{ -if (tclass < current_mapping_size) { -unsigned i; -u32 kperm =0 ; - -for (i =0 ; i < current_mapping[tclass].num_perms; i++) -if (tperm & (1 <<i)) { - kperm |= current_mapping[tclass].perms[i]; - tperm &= ~(1 <<i); - } -return kperm; - } - -return tperm; -} -static void map_decision (u16 tclass,struct av_decision *avd,int allow_unknown) {@@ -532,7 +514,6 @@ out:static void type_attribute_bounds_av (struct context *scontext,struct context *tcontext,u16 tclass, -u32 requested,struct av_decision *avd) {struct context lo_scontext;@@ -553,7 +534,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -569,7 +549,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -586,7 +565,6 @@ static void type_attribute_bounds_av(struct context *scontext,context_struct_compute_av (&lo_scontext, &lo_tcontext, tclass, - requested, &lo_avd);if ((lo_avd.allowed & avd->allowed) == avd->allowed)return ;/* no masked permission */ @@ -607,11 +585,10 @@ static void type_attribute_bounds_av(struct context*scontext, * Compute access vectors based on a context structure pair for * the permissions in a particular class. */ -static int context_struct_compute_av (struct context *scontext, -struct context *tcontext, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void context_struct_compute_av (struct context *scontext, +struct context *tcontext, +u16 tclass, +struct av_decision *avd) {struct constraint_node *constraint;struct role_allow *ra;@@ -622,19 +599,14 @@ static int context_struct_compute_av(struct context *scontext, struct ebitmap_node *snode, *tnode;unsigned int i, j; -/* -* Initialize the access vectors to the default values. -*/ avd->allowed =0 ; avd->auditallow =0 ; avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ;if (unlikely (!tclass || tclass > policydb.p_classes.nprim)) {if (printk_ratelimit ())printk (KERN_WARNING "SELinux: Invalid class %hu\n" , tclass); -return -EINVAL ; +return ; } tclass_datum = policydb.class_val_to_struct[tclass -1 ];@@ -705,9 +677,7 @@ static int context_struct_compute_av(struct context*scontext, * permission and notice it to userspace via audit. */ type_attribute_bounds_av (scontext, tcontext, - tclass, requested, avd); - -return 0 ; + tclass, avd); } static int security_validtrans_handle_fail(struct context *ocontext,@@ -886,110 +856,116 @@ out:return rc; } - -static int security_compute_av_core (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +static void avd_init (struct av_decision *avd) { -struct context *scontext =NULL , *tcontext =NULL ; -int rc =0 ; - - scontext =sidtab_search (&sidtab, ssid); -if (!scontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, ssid); -return -EINVAL ; - } - tcontext =sidtab_search (&sidtab, tsid); -if (!tcontext) { -printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , - __func__, tsid); -return -EINVAL ; - } - - rc =context_struct_compute_av (scontext, tcontext, tclass, - requested, avd); - -/* permissive domain? */ -if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) - avd->flags |=AVD_FLAGS_PERMISSIVE ; - -return rc; + avd->allowed =0 ; + avd->auditallow =0 ; + avd->auditdeny =0xffffffff ; + avd->seqno = latest_granting; + avd->flags =0 ; } +/** * security_compute_av - Compute access vector decisions. * @ssid: source security identifier * @tsid: target security identifier * @tclass: target security class -* @requested: requested permissions * @avd: access vector decisions * * Compute a set of access vector decisions based on the * SID pair (@ssid, @tsid) for the permissions in @tclass. -* Return -%EINVAL if any of the parameters are invalid or %0 -* if the access vector decisions were computed successfully. */ -int security_compute_av (u32 ssid, -u32 tsid, -u16 orig_tclass, -u32 orig_requested, -struct av_decision *avd) +void security_compute_av (u32 ssid, +u32 tsid, +u16 orig_tclass, +struct av_decision *avd) {u16 tclass; -u32 requested; -int rc; +struct context *scontext =NULL , *tcontext =NULL ;read_lock (&policy_rwlock); - +avd_init (avd);if (!ss_initialized) goto allow; - requested =unmap_perm (orig_tclass, orig_requested); + scontext =sidtab_search (&sidtab, ssid); +if (!scontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, ssid); + goto out; + } + +/* permissive domain? */ +if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) + avd->flags |=AVD_FLAGS_PERMISSIVE ; + + tcontext =sidtab_search (&sidtab, tsid); +if (!tcontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, tsid); + goto out; + } + tclass =unmap_class (orig_tclass);if (unlikely (orig_tclass && !tclass)) {if (policydb.allow_unknown) goto allow; - rc = -EINVAL ; goto out; } - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +context_struct_compute_av (scontext, tcontext, tclass, avd);map_decision (orig_tclass, avd, policydb.allow_unknown); out:read_unlock (&policy_rwlock); -return rc; +return ; allow: avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; - avd->flags =0 ; - rc =0 ; goto out; } -int security_compute_av_user (u32 ssid, -u32 tsid, -u16 tclass, -u32 requested, -struct av_decision *avd) +void security_compute_av_user (u32 ssid, +u32 tsid, +u16 tclass, +struct av_decision *avd) { -int rc; +struct context *scontext =NULL , *tcontext =NULL ; -if (!ss_initialized) { - avd->allowed =0xffffffff ; - avd->auditallow =0 ; - avd->auditdeny =0xffffffff ; - avd->seqno = latest_granting; -return 0 ; +read_lock (&policy_rwlock); +avd_init (avd); +if (!ss_initialized) + goto allow; + + scontext =sidtab_search (&sidtab, ssid); +if (!scontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, ssid); + goto out; } -read_lock (&policy_rwlock); - rc =security_compute_av_core (ssid, tsid, tclass, requested, avd); +/* permissive domain? */ +if (ebitmap_get_bit (&policydb.permissive_map, scontext->type)) + avd->flags |=AVD_FLAGS_PERMISSIVE ; + + tcontext =sidtab_search (&sidtab, tsid); +if (!tcontext) { +printk (KERN_ERR "SELinux: %s: unrecognized SID %d\n" , + __func__, tsid); + goto out; + } + +if (unlikely (!tclass)) { +if (policydb.allow_unknown) + goto allow; + goto out; + } + +context_struct_compute_av (scontext, tcontext, tclass, avd); + out:read_unlock (&policy_rwlock); -return rc; +return ; +allow: + avd->allowed =0xffffffff ; + goto out; }/*
Signature · 7 lines
paul moore linux @ hp -- 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.
Re: [RFC][PATCH v3] selinux: change the handling of unknown classes
In reply to Stephen SmalleyQuoted 9 lines · Stephen Smalley
Changes:
- Handle permissive domains consistently by moving up the test for a permissive domain.
- Makesecurity_compute_av_user()consistent withsecurity_compute_av(); the only difference now is thatsecurity_compute_av()performs mapping between the kernel-private class and permission indices and the policy values. In the userspace case, this mapping is handled by libselinux.
- Movedavd_initinside the policy lock.
Quoted 4 lines
Based in part on a patch by Paul Moore <[email protected]>.
Reported-by Andrew Worsley <[email protected]>Signed-off-by Stephen D. Smalley <[email protected]>
Applied togit://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
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.