[prev in list] [next in list] [prev in thread] [next in thread] 

List:       selinux
Subject:    Re: [PATCH] SELinux: 2/3 change isec->sem to a mutex
From:       Stephen Smalley <sds () tycho ! nsa ! gov>
Date:       2006-07-27 18:36:24
Message-ID: 1154025384.27604.229.camel () moss-spartans ! epoch ! ncsc ! mil
[Download RAW message or body]

On Thu, 2006-07-27 at 13:29 -0400, Eric Paris wrote:
> 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.
> 
> Signed-off-by: Eric Paris <eparis@redhat.com>
> 
>  security/selinux/hooks.c          |   13 +++++++------
>  security/selinux/include/objsec.h |    2 +-
>  2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index a91c961..e03bada 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -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 i
>  		return -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 255
>  	char *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;
>  }

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).

-- 
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 majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic