Skip to content

Commit 5881fa8

Browse files
WOnder93gregkh
authored andcommitted
debugfs: fix security_locked_down() call for SELinux
When (ia->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) is zero, then the SELinux implementation of the locked_down hook might report a denial even though the operation would actually be allowed. To fix this, make sure that security_locked_down() is called only when the return value will be taken into account (i.e. when changing one of the problematic attributes). Note: this was introduced by commit 5496197 ("debugfs: Restrict debugfs when the kernel is locked down"), but it didn't matter at that time, as the SELinux support came in later. Fixes: 59438b4 ("security,lockdown,selinux: implement SELinux lockdown") Cc: stable <[email protected]> Signed-off-by: Ondrej Mosnacek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d07f6ca commit 5881fa8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/debugfs/inode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ static unsigned int debugfs_allow __ro_after_init = DEFAULT_DEBUGFS_ALLOW_BITS;
4545
static int debugfs_setattr(struct user_namespace *mnt_userns,
4646
struct dentry *dentry, struct iattr *ia)
4747
{
48-
int ret = security_locked_down(LOCKDOWN_DEBUGFS);
48+
int ret;
4949

50-
if (ret && (ia->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)))
51-
return ret;
50+
if (ia->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) {
51+
ret = security_locked_down(LOCKDOWN_DEBUGFS);
52+
if (ret)
53+
return ret;
54+
}
5255
return simple_setattr(&init_user_ns, dentry, ia);
5356
}
5457

0 commit comments

Comments
 (0)