]> git.karo-electronics.de Git - linux-beck.git/commitdiff
selinux: Clean up initialization of isec->sclass
authorAndreas Gruenbacher <agruenba@redhat.com>
Thu, 10 Nov 2016 21:18:29 +0000 (22:18 +0100)
committerPaul Moore <paul@paul-moore.com>
Mon, 14 Nov 2016 20:53:04 +0000 (15:53 -0500)
Now that isec->initialized == LABEL_INITIALIZED implies that
isec->sclass is valid, skip such inodes immediately in
inode_doinit_with_dentry.

For the remaining inodes, initialize isec->sclass at the beginning of
inode_doinit_with_dentry to simplify the code.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/hooks.c

index 32beac817bf5ec76129af4528a011740d0e2277f..2a506861a772d5d2ba89ec10684d5fa124b3086d 100644 (file)
@@ -1390,12 +1390,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
        int rc = 0;
 
        if (isec->initialized == LABEL_INITIALIZED)
-               goto out;
+               return 0;
 
        mutex_lock(&isec->lock);
        if (isec->initialized == LABEL_INITIALIZED)
                goto out_unlock;
 
+       if (isec->sclass == SECCLASS_FILE)
+               isec->sclass = inode_mode_to_security_class(inode->i_mode);
+
        sbsec = inode->i_sb->s_security;
        if (!(sbsec->flags & SE_SBINITIALIZED)) {
                /* Defer initialization until selinux_complete_init,
@@ -1513,7 +1516,6 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
                isec->sid = sbsec->sid;
 
                /* Try to obtain a transition SID. */
-               isec->sclass = inode_mode_to_security_class(inode->i_mode);
                rc = security_transition_sid(isec->task_sid, sbsec->sid,
                                             isec->sclass, NULL, &sid);
                if (rc)
@@ -1549,7 +1551,6 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
                         */
                        if (!dentry)
                                goto out_unlock;
-                       isec->sclass = inode_mode_to_security_class(inode->i_mode);
                        rc = selinux_genfs_get_sid(dentry, isec->sclass,
                                                   sbsec->flags, &sid);
                        dput(dentry);
@@ -1564,9 +1565,6 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
 
 out_unlock:
        mutex_unlock(&isec->lock);
-out:
-       if (isec->sclass == SECCLASS_FILE)
-               isec->sclass = inode_mode_to_security_class(inode->i_mode);
        return rc;
 }