Skip to content

Commit

Permalink
selinux: fix error initialization in inode_doinit_with_dentry()
Browse files Browse the repository at this point in the history
[ Upstream commit 83370b3 ]

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: 9287aed ("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>
  • Loading branch information
Tianyue Ren authored and gregkh committed Dec 30, 2020
1 parent de49a51 commit 4aae08a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions security/selinux/hooks.c
Expand Up @@ -1499,7 +1499,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,
Expand Down Expand Up @@ -1553,8 +1559,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) {
Expand Down

0 comments on commit 4aae08a

Please sign in to comment.