summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorTianyue Ren <rentianyue@kylinos.cn>2020-10-09 09:36:30 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-12-30 11:52:58 +0100
commitf0d7de09261b0dd076a470b77f38678e89362bed (patch)
treeb0fea8b02d41e006ba43f84314bc5ca56dccce65 /security
parentae3739fcfe3baf1595dac00ac8440fe4f1bd3a38 (diff)
downloadlinux-stable-f0d7de09261b0dd076a470b77f38678e89362bed.tar.gz
linux-stable-f0d7de09261b0dd076a470b77f38678e89362bed.tar.bz2
linux-stable-f0d7de09261b0dd076a470b77f38678e89362bed.zip
selinux: fix error initialization in inode_doinit_with_dentry()
[ Upstream commit 83370b31a915493231e5b9addc72e4bef69f8d31 ] Mark the inode security label as invalid if we cannot find a dentry so that we will retry later rather than marking it initialized with the unlabeled SID. Fixes: 9287aed2ad1f ("selinux: Convert isec->lock into a spinlock") Signed-off-by: Tianyue Ren <rentianyue@kylinos.cn> [PM: minor comment tweaks] Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'security')
-rw-r--r--security/selinux/hooks.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6b1826fc3658..158fc47d8620 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1451,7 +1451,13 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
* inode_doinit with a dentry, before these inodes could
* be used again by userspace.
*/
- goto out;
+ isec->initialized = LABEL_INVALID;
+ /*
+ * There is nothing useful to jump to the "out"
+ * label, except a needless spin lock/unlock
+ * cycle.
+ */
+ return 0;
}
rc = inode_doinit_use_xattr(inode, dentry, sbsec->def_sid,
@@ -1507,8 +1513,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
* inode_doinit() with a dentry, before these inodes
* could be used again by userspace.
*/
- if (!dentry)
- goto out;
+ if (!dentry) {
+ isec->initialized = LABEL_INVALID;
+ /*
+ * There is nothing useful to jump to the "out"
+ * label, except a needless spin lock/unlock
+ * cycle.
+ */
+ return 0;
+ }
rc = selinux_genfs_get_sid(dentry, sclass,
sbsec->flags, &sid);
if (rc) {