Skip to content

Commit 69204f6

Browse files
goongascschaufler
authored andcommitted
smack: always "instantiate" inode in smack_inode_init_security()
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>
1 parent 8e5d9f9 commit 69204f6

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

security/smack/smack_lsm.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
10151015
struct task_smack *tsp = smack_cred(current_cred());
10161016
struct inode_smack * const issp = smack_inode(inode);
10171017
struct smack_known *dsp = smk_of_inode(dir);
1018+
int rc = 0;
1019+
int transflag = 0;
10181020
bool trans_cred;
10191021
bool trans_rule;
10201022

@@ -1043,18 +1045,20 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
10431045
issp->smk_inode = dsp;
10441046

10451047
if (S_ISDIR(inode->i_mode)) {
1046-
issp->smk_flags |= SMK_INODE_TRANSMUTE;
1048+
transflag = SMK_INODE_TRANSMUTE;
10471049

10481050
if (xattr_dupval(xattrs, xattr_count,
10491051
XATTR_SMACK_TRANSMUTE,
10501052
TRANS_TRUE,
10511053
TRANS_TRUE_SIZE
10521054
))
1053-
return -ENOMEM;
1055+
rc = -ENOMEM;
10541056
}
10551057
}
10561058

1057-
issp->smk_flags |= SMK_INODE_INSTANT;
1059+
issp->smk_flags |= (SMK_INODE_INSTANT | transflag);
1060+
if (rc)
1061+
return rc;
10581062

10591063
return xattr_dupval(xattrs, xattr_count,
10601064
XATTR_SMACK_SUFFIX,

0 commit comments

Comments
 (0)