[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220823080035.044590894@linuxfoundation.org>
Date: Tue, 23 Aug 2022 10:02:45 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org, Andreas Gruenbacher <agruenba@...hat.com>,
Paul Moore <paul@...l-moore.com>,
Alexander Grund <theflamefire89@...il.com>
Subject: [PATCH 4.9 012/101] selinux: Clean up initialization of isec->sclass
From: Andreas Gruenbacher <agruenba@...hat.com>
commit 13457d073c29da92001f6ee809075eaa8757fb96 upstream.
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@...hat.com>
Signed-off-by: Paul Moore <paul@...l-moore.com>
Signed-off-by: Alexander Grund <theflamefire89@...il.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
security/selinux/hooks.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1395,12 +1395,15 @@ static int inode_doinit_with_dentry(stru
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,
@@ -1518,7 +1521,6 @@ static int inode_doinit_with_dentry(stru
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)
@@ -1554,7 +1556,6 @@ static int inode_doinit_with_dentry(stru
*/
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);
@@ -1569,9 +1570,6 @@ static int inode_doinit_with_dentry(stru
out_unlock:
mutex_unlock(&isec->lock);
-out:
- if (isec->sclass == SECCLASS_FILE)
- isec->sclass = inode_mode_to_security_class(inode->i_mode);
return rc;
}
Powered by blists - more mailing lists