SELinux: 3/3 convert sbsec semaphore to a mutex
PATCH 1/1 SELinux: 3/3 convert sbsec semaphore to a mutex
This patch converts the semaphore in the superblock security struct to a mutex. No locking changes or other code changes are done.
This is being targeted for 2.6.19
security/selinux/hooks.c | 7 +++---- security/selinux/include/objsec.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
security/selinux/include/objsec.h renamed from security/selinux/include/objsec.h.patch3 +1 -1
@@ -63,7 +63,7 @@ struct superblock_security_struct {unsigned int behavior;/* labeling behavior */ unsigned char initialized;/* initialization flag */ unsigned char proc;/* proc fs */ -struct semaphore sem; +struct mutex lock;struct list_head isec_head;spinlock_t isec_lock; };
security/selinux/hooks.c renamed from security/selinux/hooks.c.patch3 +3 -4
@@ -49,7 +49,6 @@#include <net/ip.h> /* for sysctl_local_port_range[] */ #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ #include <asm/uaccess.h> -#include <asm/semaphore.h> #include <asm/ioctls.h> #include <linux/bitops.h> #include <linux/interrupt.h>
@@ -240,7 +239,7 @@ static int superblock_alloc_security(strif (!sbsec)return -ENOMEM ; -init_MUTEX (&sbsec->sem); +mutex_init (&sbsec->lock);INIT_LIST_HEAD (&sbsec->list);INIT_LIST_HEAD (&sbsec->isec_head);spin_lock_init (&sbsec->isec_lock);
@@ -595,7 +594,7 @@ static int superblock_doinit(struct supestruct inode *inode = root->d_inode;int rc =0 ; -down (&sbsec->sem); +mutex_lock (&sbsec->lock);if (sbsec->initialized) goto out;
@@ -690,7 +689,7 @@ next_inode: }spin_unlock (&sbsec->isec_lock); out: -up (&sbsec->sem); +mutex_unlock (&sbsec->lock);return rc; }
Quoted 7 lines · Eric Paris
This patch converts the semaphore in the superblock security struct to a mutex. No locking changes or other code changes are done.
This is being targeted for 2.6.19
Signed-off-by Eric Paris <[email protected]>Acked-by Stephen Smalley <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
Quoted 53 lines · On Wed, 23 Aug 2006 15:50:37 -0400 Eric Paris <[email protected]> wrote:
This patch converts the semaphore in the superblock security struct to a mutex. No locking changes or other code changes are done.
This is being targeted for 2.6.19
Signed-off-by Eric Paris <[email protected]>Acked-by Stephen Smalley <[email protected]>security/selinux/hooks.c | 7 +++---- security/selinux/include/objsec.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)security/selinux/include/objsec.h renamed from security/selinux/include/objsec.h.patch3 +1
-1@@ -63,7 +63,7 @@ struct superblock_security_struct {unsigned int behavior;/* labeling behavior */ unsigned char initialized;/* initialization flag */ unsigned char proc;/* proc fs */ -struct semaphore sem; +struct mutex lock;struct list_head isec_head;spinlock_t isec_lock; };security/selinux/hooks.c renamed from security/selinux/hooks.c.patch3 +2
-3@@ -49,7 +49,6 @@#include <net/ip.h> /* for sysctl_local_port_range[] */ #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ #include <asm/uaccess.h> -#include <asm/semaphore.h> #include <asm/ioctls.h> #include <linux/bitops.h> #include <linux/interrupt.h> @@ -240,7 +239,7 @@ static int superblock_alloc_security(strif (!sbsec)return -ENOMEM ; -init_MUTEX (&sbsec->sem); +mutex_init (&sbsec->lock);INIT_LIST_HEAD (&sbsec->list);INIT_LIST_HEAD (&sbsec->isec_head);spin_lock_init (&sbsec->isec_lock);@@ -595,7 +594,7 @@ static int superblock_doinit(struct supestruct inode *inode = root->d_inode;int rc =0 ; -down (&sbsec->sem); +mutex_lock (&sbsec->lock);if (sbsec->initialized) goto out;
security/selinux/hooks.c next_inode: · line 695
Quoted 8 lines
security/selinux/hooks.c renamed from security/selinux/hooks.c.patch3 +1
-1@@ -690,7 +689,7 @@ next_inode: }spin_unlock (&sbsec->isec_lock); out: -up (&sbsec->sem); +mutex_unlock (&sbsec->lock);return rc; }
Does this lock actually do anything?
Quoted 54 lines · Andrew Morton
Quoted 51 lines · On Wed, 23 Aug 2006 15:50:37 -0400 Eric Paris <[email protected]> wrote:
This patch converts the semaphore in the superblock security struct to a mutex. No locking changes or other code changes are done.
This is being targeted for 2.6.19
Signed-off-by Eric Paris <[email protected]>Acked-by Stephen Smalley <[email protected]>security/selinux/hooks.c | 7 +++---- security/selinux/include/objsec.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)security/selinux/include/objsec.h renamed from security/selinux/include/objsec.h.patch3 +1
-1@@ -63,7 +63,7 @@ struct superblock_security_struct {unsigned int behavior;/* labeling behavior */ unsigned char initialized;/* initialization flag */ unsigned char proc;/* proc fs */ -struct semaphore sem; +struct mutex lock;struct list_head isec_head;spinlock_t isec_lock; };security/selinux/hooks.c renamed from security/selinux/hooks.c.patch3 +2
-3@@ -49,7 +49,6 @@#include <net/ip.h> /* for sysctl_local_port_range[] */ #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ #include <asm/uaccess.h> -#include <asm/semaphore.h> #include <asm/ioctls.h> #include <linux/bitops.h> #include <linux/interrupt.h> @@ -240,7 +239,7 @@ static int superblock_alloc_security(strif (!sbsec)return -ENOMEM ; -init_MUTEX (&sbsec->sem); +mutex_init (&sbsec->lock);INIT_LIST_HEAD (&sbsec->list);INIT_LIST_HEAD (&sbsec->isec_head);spin_lock_init (&sbsec->isec_lock);@@ -595,7 +594,7 @@ static int superblock_doinit(struct supestruct inode *inode = root->d_inode;int rc =0 ; -down (&sbsec->sem); +mutex_lock (&sbsec->lock);if (sbsec->initialized) goto out;
Quoted 12 lines
security/selinux/hooks.c next_inode: · line 695
Quoted 10 lines
security/selinux/hooks.c renamed from security/selinux/hooks.c.patch3 +1
-1@@ -690,7 +689,7 @@ next_inode: }spin_unlock (&sbsec->isec_lock); out: -up (&sbsec->sem); +mutex_unlock (&sbsec->lock);return rc; }Does this lock actually do anything?
The function is called from vfs_kern_mount normally, and from selinux_complete_init just for the initial setup after initial policy load. The lock is for the initialization of the superblock security struct. Strictly speaking, we can't race from vfs_kern_mount since the caller holds s_umount write lock already, but I didn't think we should rely on that here. Eric noticed that as well when he was preparing the sem->mutex conversion patch and was originally going to drop the lock altogether.
Signature · 2 lines
Stephen Smalley National Security Agency