Skip to content

Commit 51b15e7

Browse files
robertosassucschaufler
authored andcommitted
smack: Always determine inode labels in smack_inode_init_security()
The inode_init_security hook is already a good place to initialize the in-memory inode. And that is also what SELinux does. In preparation for this, move the existing smack_inode_init_security() code outside the 'if (xattr)' condition, and set the xattr, if provided. This change does not have any impact on the current code, since every time security_inode_init_security() is called, the initxattr() callback is passed and, thus, xattr is non-NULL. Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent ac02f00 commit 51b15e7

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

security/smack/smack_lsm.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,51 +1000,51 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
10001000
struct xattr *xattr = lsm_get_xattr_slot(xattrs, xattr_count);
10011001
int may;
10021002

1003-
if (xattr) {
1004-
/*
1005-
* If equal, transmuting already occurred in
1006-
* smack_dentry_create_files_as(). No need to check again.
1007-
*/
1008-
if (tsp->smk_task != tsp->smk_transmuted) {
1009-
rcu_read_lock();
1010-
may = smk_access_entry(skp->smk_known, dsp->smk_known,
1011-
&skp->smk_rules);
1012-
rcu_read_unlock();
1013-
}
1003+
/*
1004+
* If equal, transmuting already occurred in
1005+
* smack_dentry_create_files_as(). No need to check again.
1006+
*/
1007+
if (tsp->smk_task != tsp->smk_transmuted) {
1008+
rcu_read_lock();
1009+
may = smk_access_entry(skp->smk_known, dsp->smk_known,
1010+
&skp->smk_rules);
1011+
rcu_read_unlock();
1012+
}
1013+
1014+
/*
1015+
* In addition to having smk_task equal to smk_transmuted,
1016+
* if the access rule allows transmutation and the directory
1017+
* requests transmutation then by all means transmute.
1018+
* Mark the inode as changed.
1019+
*/
1020+
if ((tsp->smk_task == tsp->smk_transmuted) ||
1021+
(may > 0 && ((may & MAY_TRANSMUTE) != 0) &&
1022+
smk_inode_transmutable(dir))) {
1023+
struct xattr *xattr_transmute;
10141024

10151025
/*
1016-
* In addition to having smk_task equal to smk_transmuted,
1017-
* if the access rule allows transmutation and the directory
1018-
* requests transmutation then by all means transmute.
1019-
* Mark the inode as changed.
1026+
* The caller of smack_dentry_create_files_as()
1027+
* should have overridden the current cred, so the
1028+
* inode label was already set correctly in
1029+
* smack_inode_alloc_security().
10201030
*/
1021-
if ((tsp->smk_task == tsp->smk_transmuted) ||
1022-
(may > 0 && ((may & MAY_TRANSMUTE) != 0) &&
1023-
smk_inode_transmutable(dir))) {
1024-
struct xattr *xattr_transmute;
1031+
if (tsp->smk_task != tsp->smk_transmuted)
1032+
isp = dsp;
1033+
xattr_transmute = lsm_get_xattr_slot(xattrs,
1034+
xattr_count);
1035+
if (xattr_transmute) {
1036+
xattr_transmute->value = kmemdup(TRANS_TRUE,
1037+
TRANS_TRUE_SIZE,
1038+
GFP_NOFS);
1039+
if (!xattr_transmute->value)
1040+
return -ENOMEM;
10251041

1026-
/*
1027-
* The caller of smack_dentry_create_files_as()
1028-
* should have overridden the current cred, so the
1029-
* inode label was already set correctly in
1030-
* smack_inode_alloc_security().
1031-
*/
1032-
if (tsp->smk_task != tsp->smk_transmuted)
1033-
isp = dsp;
1034-
xattr_transmute = lsm_get_xattr_slot(xattrs,
1035-
xattr_count);
1036-
if (xattr_transmute) {
1037-
xattr_transmute->value = kmemdup(TRANS_TRUE,
1038-
TRANS_TRUE_SIZE,
1039-
GFP_NOFS);
1040-
if (!xattr_transmute->value)
1041-
return -ENOMEM;
1042-
1043-
xattr_transmute->value_len = TRANS_TRUE_SIZE;
1044-
xattr_transmute->name = XATTR_SMACK_TRANSMUTE;
1045-
}
1042+
xattr_transmute->value_len = TRANS_TRUE_SIZE;
1043+
xattr_transmute->name = XATTR_SMACK_TRANSMUTE;
10461044
}
1045+
}
10471046

1047+
if (xattr) {
10481048
xattr->value = kstrdup(isp->smk_known, GFP_NOFS);
10491049
if (!xattr->value)
10501050
return -ENOMEM;

0 commit comments

Comments
 (0)