Skip to content

Commit

Permalink
Smack:- Remove mutex lock "smk_lock" from inode_smack
Browse files Browse the repository at this point in the history
"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]>
  • Loading branch information
cschaufler committed May 6, 2020
1 parent 84e99e5 commit 921bb1c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
1 change: 0 additions & 1 deletion security/smack/smack.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ struct inode_smack {
struct smack_known *smk_inode; /* label of the fso */
struct smack_known *smk_task; /* label of the task */
struct smack_known *smk_mmap; /* label of the mmap domain */
struct mutex smk_lock; /* initialization lock */
int smk_flags; /* smack inode flags */
};

Expand Down
8 changes: 2 additions & 6 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ static void init_inode_smack(struct inode *inode, struct smack_known *skp)

isp->smk_inode = skp;
isp->smk_flags = 0;
mutex_init(&isp->smk_lock);
}

/**
Expand Down Expand Up @@ -3264,13 +3263,12 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)

isp = smack_inode(inode);

mutex_lock(&isp->smk_lock);
/*
* If the inode is already instantiated
* take the quick way out
*/
if (isp->smk_flags & SMK_INODE_INSTANT)
goto unlockandout;
return;

sbp = inode->i_sb;
sbsp = sbp->s_security;
Expand Down Expand Up @@ -3321,7 +3319,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
break;
}
isp->smk_flags |= SMK_INODE_INSTANT;
goto unlockandout;
return;
}

/*
Expand Down Expand Up @@ -3456,8 +3454,6 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)

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

unlockandout:
mutex_unlock(&isp->smk_lock);
return;
}

Expand Down

0 comments on commit 921bb1c

Please sign in to comment.