Skip to content

Commit 195da3f

Browse files
goongascschaufler
authored andcommitted
smack: fix bug: SMACK64TRANSMUTE set on non-directory
When a new file system object is created and the conditions for label transmutation are met, the SMACK64TRANSMUTE extended attribute is set on the object regardless of its type: file, pipe, socket, symlink, or directory. However, SMACK64TRANSMUTE may only be set on directories. This bug is a combined effect of the commits [1] and [2] which both transfer functionality from smack_d_instantiate() to smack_inode_init_security(), but only in part. Commit [1] set blank SMACK64TRANSMUTE on improper object types. Commit [2] set "TRUE" SMACK64TRANSMUTE on improper object types. [1] 2023-06-10, Fixes: baed456 ("smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security()") Link: https://lore.kernel.org/linux-security-module/20230610075738.3273764-3-roberto.sassu@huaweicloud.com/ [2] 2023-11-16, Fixes: e63d86b ("smack: Initialize the in-memory inode in smack_inode_init_security()") Link: https://lore.kernel.org/linux-security-module/20231116090125.187209-5-roberto.sassu@huaweicloud.com/ Signed-off-by: Konstantin Andreev <andreev@swemel.ru> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 635a01d commit 195da3f

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

security/smack/smack_lsm.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,18 +1027,20 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
10271027
if (!trans_cred)
10281028
issp->smk_inode = dsp;
10291029

1030-
issp->smk_flags |= SMK_INODE_TRANSMUTE;
1031-
xattr_transmute = lsm_get_xattr_slot(xattrs,
1032-
xattr_count);
1033-
if (xattr_transmute) {
1034-
xattr_transmute->value = kmemdup(TRANS_TRUE,
1035-
TRANS_TRUE_SIZE,
1036-
GFP_NOFS);
1037-
if (!xattr_transmute->value)
1038-
return -ENOMEM;
1039-
1040-
xattr_transmute->value_len = TRANS_TRUE_SIZE;
1041-
xattr_transmute->name = XATTR_SMACK_TRANSMUTE;
1030+
if (S_ISDIR(inode->i_mode)) {
1031+
issp->smk_flags |= SMK_INODE_TRANSMUTE;
1032+
xattr_transmute = lsm_get_xattr_slot(xattrs,
1033+
xattr_count);
1034+
if (xattr_transmute) {
1035+
xattr_transmute->value = kmemdup(TRANS_TRUE,
1036+
TRANS_TRUE_SIZE,
1037+
GFP_NOFS);
1038+
if (!xattr_transmute->value)
1039+
return -ENOMEM;
1040+
1041+
xattr_transmute->value_len = TRANS_TRUE_SIZE;
1042+
xattr_transmute->name = XATTR_SMACK_TRANSMUTE;
1043+
}
10421044
}
10431045
}
10441046

0 commit comments

Comments
 (0)