summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authorKonstantin Andreev <andreev@swemel.ru>2025-06-16 04:07:31 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-12-18 13:54:39 +0100
commitad396a05d9851c0198f6246377a52b56733800cc (patch)
treee5668dbf245db3c6d73b0affbbba85c7a40993de /security
parentabf20a13507fe15a3e10a9b119a55347a532b741 (diff)
smack: always "instantiate" inode in smack_inode_init_security()
[ Upstream commit 69204f6cdb90f56b7ca27966d1080841108fc5de ] If memory allocation for the SMACK64TRANSMUTE xattr value fails in smack_inode_init_security(), the SMK_INODE_INSTANT flag is not set in (struct inode_smack *issp)->smk_flags, leaving the inode as not "instantiated". It does not matter if fs frees the inode after failed smack_inode_init_security() call, but there is no guarantee for this. To be safe, mark the inode as "instantiated", even if allocation of xattr values fails. Signed-off-by: Konstantin Andreev <andreev@swemel.ru> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Stable-dep-of: 78fc6a94be25 ("smack: fix bug: invalid label of unix socket file") Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'security')
-rw-r--r--security/smack/smack_lsm.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 586ba83c6e1b..d0a062a20024 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1032,6 +1032,8 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
struct task_smack *tsp = smack_cred(current_cred());
struct inode_smack * const issp = smack_inode(inode);
struct smack_known *dsp = smk_of_inode(dir);
+ int rc = 0;
+ int transflag = 0;
bool trans_cred;
bool trans_rule;
@@ -1060,18 +1062,20 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
issp->smk_inode = dsp;
if (S_ISDIR(inode->i_mode)) {
- issp->smk_flags |= SMK_INODE_TRANSMUTE;
+ transflag = SMK_INODE_TRANSMUTE;
if (xattr_dupval(xattrs, xattr_count,
XATTR_SMACK_TRANSMUTE,
TRANS_TRUE,
TRANS_TRUE_SIZE
))
- return -ENOMEM;
+ rc = -ENOMEM;
}
}
- issp->smk_flags |= SMK_INODE_INSTANT;
+ issp->smk_flags |= (SMK_INODE_INSTANT | transflag);
+ if (rc)
+ return rc;
return xattr_dupval(xattrs, xattr_count,
XATTR_SMACK_SUFFIX,