提交 1956f2c2 编写于 作者: P Paul Moore 提交者: Xie XiuQi

selinux: fix inode_doinit_with_dentry() LABEL_INVALID error handling

stable inclusion
from stable-5.10.4
commit 6e5ea342fc652573d29adcdeb805081dd7253e67
bugzilla: 46903

--------------------------------

[ Upstream commit 200ea5a2 ]

A previous fix, commit 83370b31 ("selinux: fix error initialization
in inode_doinit_with_dentry()"), changed how failures were handled
before a SELinux policy was loaded.  Unfortunately that patch was
potentially problematic for two reasons: it set the isec->initialized
state without holding a lock, and it didn't set the inode's SELinux
label to the "default" for the particular filesystem.  The later can
be a problem if/when a later attempt to revalidate the inode fails
and SELinux reverts to the existing inode label.

This patch should restore the default inode labeling that existed
before the original fix, without affecting the LABEL_INVALID marking
such that revalidation will still be attempted in the future.

Fixes: 83370b31 ("selinux: fix error initialization in inode_doinit_with_dentry()")
Reported-by: NSven Schnelle <svens@linux.ibm.com>
Tested-by: NSven Schnelle <svens@linux.ibm.com>
Reviewed-by: NOndrej Mosnacek <omosnace@redhat.com>
Signed-off-by: NPaul Moore <paul@paul-moore.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 9d2fda2c
...@@ -1451,13 +1451,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent ...@@ -1451,13 +1451,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
* inode_doinit with a dentry, before these inodes could * inode_doinit with a dentry, before these inodes could
* be used again by userspace. * be used again by userspace.
*/ */
isec->initialized = LABEL_INVALID; goto out_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, rc = inode_doinit_use_xattr(inode, dentry, sbsec->def_sid,
...@@ -1513,15 +1507,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent ...@@ -1513,15 +1507,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
* inode_doinit() with a dentry, before these inodes * inode_doinit() with a dentry, before these inodes
* could be used again by userspace. * could be used again by userspace.
*/ */
if (!dentry) { if (!dentry)
isec->initialized = LABEL_INVALID; goto out_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, rc = selinux_genfs_get_sid(dentry, sclass,
sbsec->flags, &sid); sbsec->flags, &sid);
if (rc) { if (rc) {
...@@ -1546,11 +1533,10 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent ...@@ -1546,11 +1533,10 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
out: out:
spin_lock(&isec->lock); spin_lock(&isec->lock);
if (isec->initialized == LABEL_PENDING) { if (isec->initialized == LABEL_PENDING) {
if (!sid || rc) { if (rc) {
isec->initialized = LABEL_INVALID; isec->initialized = LABEL_INVALID;
goto out_unlock; goto out_unlock;
} }
isec->initialized = LABEL_INITIALIZED; isec->initialized = LABEL_INITIALIZED;
isec->sid = sid; isec->sid = sid;
} }
...@@ -1558,6 +1544,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent ...@@ -1558,6 +1544,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
out_unlock: out_unlock:
spin_unlock(&isec->lock); spin_unlock(&isec->lock);
return rc; return rc;
out_invalid:
spin_lock(&isec->lock);
if (isec->initialized == LABEL_PENDING) {
isec->initialized = LABEL_INVALID;
isec->sid = sid;
}
spin_unlock(&isec->lock);
return 0;
} }
/* Convert a Linux signal to an access vector. */ /* Convert a Linux signal to an access vector. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册