]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smack: Set SMACK64TRANSMUTE only for dirs in smack_inode_setxattr()
authorRoberto Sassu <roberto.sassu@huawei.com>
Thu, 16 Nov 2023 09:01:21 +0000 (10:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Apr 2024 13:11:07 +0000 (15:11 +0200)
[ Upstream commit 9c82169208dde516510aaba6bbd8b13976690c5d ]

Since the SMACK64TRANSMUTE xattr makes sense only for directories, enforce
this restriction in smack_inode_setxattr().

Cc: stable@vger.kernel.org
Fixes: 5c6d1125f8db ("Smack: Transmute labels on specified directories") # v2.6.38.x
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/smack/smack_lsm.c

index 1f1ea8529421fd949c0c85f4bdf0e5f0d4d26b21..0fe3ccec62a52d7f5a24130bbde5f6220574f378 100644 (file)
@@ -1312,7 +1312,8 @@ static int smack_inode_setxattr(struct mnt_idmap *idmap,
                check_star = 1;
        } else if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
                check_priv = 1;
-               if (size != TRANS_TRUE_SIZE ||
+               if (!S_ISDIR(d_backing_inode(dentry)->i_mode) ||
+                   size != TRANS_TRUE_SIZE ||
                    strncmp(value, TRANS_TRUE, TRANS_TRUE_SIZE) != 0)
                        rc = -EINVAL;
        } else