Skip to content

Commit 921bb1c

Browse files
committed
Smack:- Remove mutex lock "smk_lock" from inode_smack
"smk_lock" mutex is used during inode instantiation in smack_d_instantiate()function. It has been used to avoid simultaneous access on same inode security structure. Since smack related initialization is done only once i.e during inode creation. If the inode has already been instantiated then smack_d_instantiate() function just returns without doing anything. So it means mutex lock is required only during inode creation. But since 2 processes can't create same inodes or files simultaneously. Also linking or some other file operation can't be done simultaneously when the file is getting created since file lookup will fail before dentry inode linkup which is done after smack initialization. So no mutex lock is required in inode_smack structure. It will save memory as well as improve some performance. If 40000 inodes are created in system, it will save 1.5 MB on 32-bit systems & 2.8 MB on 64-bit systems. Signed-off-by: Vishal Goel <[email protected]> Signed-off-by: Amit Sahrawat <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 84e99e5 commit 921bb1c

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

security/smack/smack.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ struct inode_smack {
109109
struct smack_known *smk_inode; /* label of the fso */
110110
struct smack_known *smk_task; /* label of the task */
111111
struct smack_known *smk_mmap; /* label of the mmap domain */
112-
struct mutex smk_lock; /* initialization lock */
113112
int smk_flags; /* smack inode flags */
114113
};
115114

security/smack/smack_lsm.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ static void init_inode_smack(struct inode *inode, struct smack_known *skp)
314314

315315
isp->smk_inode = skp;
316316
isp->smk_flags = 0;
317-
mutex_init(&isp->smk_lock);
318317
}
319318

320319
/**
@@ -3264,13 +3263,12 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
32643263

32653264
isp = smack_inode(inode);
32663265

3267-
mutex_lock(&isp->smk_lock);
32683266
/*
32693267
* If the inode is already instantiated
32703268
* take the quick way out
32713269
*/
32723270
if (isp->smk_flags & SMK_INODE_INSTANT)
3273-
goto unlockandout;
3271+
return;
32743272

32753273
sbp = inode->i_sb;
32763274
sbsp = sbp->s_security;
@@ -3321,7 +3319,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
33213319
break;
33223320
}
33233321
isp->smk_flags |= SMK_INODE_INSTANT;
3324-
goto unlockandout;
3322+
return;
33253323
}
33263324

33273325
/*
@@ -3456,8 +3454,6 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
34563454

34573455
isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
34583456

3459-
unlockandout:
3460-
mutex_unlock(&isp->smk_lock);
34613457
return;
34623458
}
34633459

0 commit comments

Comments
 (0)