SELinux: 2/3 change isec->sem to a mutex
PATCH 1/1 SELinux: 2/3 change isec->sem to a mutex
This patch converts the remaining isec->sem into a mutex. The same locking is provided as before only in the faster smaller mutex rather than slower sem.
security/selinux/hooks.c | 13 +++++++------ security/selinux/include/objsec.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)
security/selinux/hooks.c +7 -6
@@ -69,6 +69,7 @@ #include <linux/sysctl.h>#include <linux/audit.h> #include <linux/string.h> #include <linux/selinux.h> +#include <linux/mutex.h> #include "avc.h" #include "objsec.h"
@@ -182,7 +183,7 @@ static int inode_alloc_security(struct ireturn -ENOMEM ;memset (isec,0 ,sizeof (*isec)); -init_MUTEX (&isec->sem); +mutex_init (&isec->lock);INIT_LIST_HEAD (&isec->list); isec->inode = inode; isec->sid =SECINITSID_UNLABELED ;
@@ -843,13 +844,13 @@ #define INITCONTEXTLEN 255char *context =NULL ;unsigned len =0 ;int rc =0 ; -int hold_sem =0 ; +int hold_lock =0 ;if (isec->initialized) goto out; -down (&isec->sem); - hold_sem =1 ; +mutex_lock (&isec->lock); + hold_lock =1 ;if (isec->initialized) goto out;
@@ -991,8 +992,8 @@ out:if (isec->sclass ==SECCLASS_FILE ) isec->sclass =inode_mode_to_security_class (inode->i_mode); -if (hold_sem) -up (&isec->sem); +if (hold_lock) +mutex_unlock (&isec->lock);return rc; }
security/selinux/include/objsec.h +1 -1
@@ -44,7 +44,7 @@ struct inode_security_struct {u32 sid;/* SID of this object */ u16 sclass;/* security class of this object */ unsigned char initialized;/* initialization flag */ -struct semaphore sem; +struct mutex lock;unsigned char inherit;/* inherit SID from parent entry */ };
--
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 49 lines · Eric Paris
This patch converts the remaining
isec->seminto a mutex. The same locking is provided as before only in the faster smaller mutex rather than slower sem.Signed-off-by Eric Paris <[email protected]>security/selinux/hooks.c | 13 +++++++------ security/selinux/include/objsec.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)security/selinux/hooks.c +5
-4@@ -69,6 +69,7 @@ #include <linux/sysctl.h>#include <linux/audit.h> #include <linux/string.h> #include <linux/selinux.h> +#include <linux/mutex.h> #include "avc.h" #include "objsec.h" @@ -182,7 +183,7 @@ static int inode_alloc_security(struct ireturn -ENOMEM ;memset (isec,0 ,sizeof (*isec)); -init_MUTEX (&isec->sem); +mutex_init (&isec->lock);INIT_LIST_HEAD (&isec->list); isec->inode = inode; isec->sid =SECINITSID_UNLABELED ;@@ -843,13 +844,13 @@ #define INITCONTEXTLEN 255char *context =NULL ;unsigned len =0 ;int rc =0 ; -int hold_sem =0 ; +int hold_lock =0 ;if (isec->initialized) goto out; -down (&isec->sem); - hold_sem =1 ; +mutex_lock (&isec->lock); + hold_lock =1 ;if (isec->initialized) goto out;
security/selinux/hooks.c out: · line 998
Quoted 9 lines
security/selinux/hooks.c +2
-2@@ -991,8 +992,8 @@ out:if (isec->sclass ==SECCLASS_FILE ) isec->sclass =inode_mode_to_security_class (inode->i_mode); -if (hold_sem) -up (&isec->sem); +if (hold_lock) +mutex_unlock (&isec->lock);return rc; }
You didn't introduce it, but it would be nice to clean this up so that instead of using the hold_sem/hold_lock flag, we just use an alternate exit path for the unlocked case. Conditional release of a lock is ugly (my fault).
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.