@@ -305,24 +305,18 @@ static struct smack_known *smk_fetch(const char *name, struct inode *ip,
305305}
306306
307307/**
308- * new_inode_smack - allocate an inode security blob
308+ * init_inode_smack - initialize an inode security blob
309+ * @isp: the blob to initialize
309310 * @skp: a pointer to the Smack label entry to use in the blob
310311 *
311- * Returns the new blob or NULL if there's no memory available
312312 */
313- static struct inode_smack * new_inode_smack ( struct smack_known * skp )
313+ static void init_inode_smack ( struct inode * inode , struct smack_known * skp )
314314{
315- struct inode_smack * isp ;
316-
317- isp = kmem_cache_zalloc (smack_inode_cache , GFP_NOFS );
318- if (isp == NULL )
319- return NULL ;
315+ struct inode_smack * isp = smack_inode (inode );
320316
321317 isp -> smk_inode = skp ;
322318 isp -> smk_flags = 0 ;
323319 mutex_init (& isp -> smk_lock );
324-
325- return isp ;
326320}
327321
328322/**
@@ -709,6 +703,13 @@ static int smack_set_mnt_opts(struct super_block *sb,
709703 if (sp -> smk_flags & SMK_SB_INITIALIZED )
710704 return 0 ;
711705
706+ if (inode -> i_security == NULL ) {
707+ int rc = lsm_inode_alloc (inode );
708+
709+ if (rc )
710+ return rc ;
711+ }
712+
712713 if (!smack_privileged (CAP_MAC_ADMIN )) {
713714 /*
714715 * Unprivileged mounts don't get to specify Smack values.
@@ -773,17 +774,12 @@ static int smack_set_mnt_opts(struct super_block *sb,
773774 /*
774775 * Initialize the root inode.
775776 */
776- isp = smack_inode (inode );
777- if (isp == NULL ) {
778- isp = new_inode_smack (sp -> smk_root );
779- if (isp == NULL )
780- return - ENOMEM ;
781- inode -> i_security = isp ;
782- } else
783- isp -> smk_inode = sp -> smk_root ;
777+ init_inode_smack (inode , sp -> smk_root );
784778
785- if (transmute )
779+ if (transmute ) {
780+ isp = smack_inode (inode );
786781 isp -> smk_flags |= SMK_INODE_TRANSMUTE ;
782+ }
787783
788784 return 0 ;
789785}
@@ -881,48 +877,10 @@ static int smack_inode_alloc_security(struct inode *inode)
881877{
882878 struct smack_known * skp = smk_of_current ();
883879
884- inode -> i_security = new_inode_smack (skp );
885- if (inode -> i_security == NULL )
886- return - ENOMEM ;
880+ init_inode_smack (inode , skp );
887881 return 0 ;
888882}
889883
890- /**
891- * smack_inode_free_rcu - Free inode_smack blob from cache
892- * @head: the rcu_head for getting inode_smack pointer
893- *
894- * Call back function called from call_rcu() to free
895- * the i_security blob pointer in inode
896- */
897- static void smack_inode_free_rcu (struct rcu_head * head )
898- {
899- struct inode_smack * issp ;
900-
901- issp = container_of (head , struct inode_smack , smk_rcu );
902- kmem_cache_free (smack_inode_cache , issp );
903- }
904-
905- /**
906- * smack_inode_free_security - free an inode blob using call_rcu()
907- * @inode: the inode with a blob
908- *
909- * Clears the blob pointer in inode using RCU
910- */
911- static void smack_inode_free_security (struct inode * inode )
912- {
913- struct inode_smack * issp = smack_inode (inode );
914-
915- /*
916- * The inode may still be referenced in a path walk and
917- * a call to smack_inode_permission() can be made
918- * after smack_inode_free_security() is called.
919- * To avoid race condition free the i_security via RCU
920- * and leave the current inode->i_security pointer intact.
921- * The inode will be freed after the RCU grace period too.
922- */
923- call_rcu (& issp -> smk_rcu , smack_inode_free_rcu );
924- }
925-
926884/**
927885 * smack_inode_init_security - copy out the smack from an inode
928886 * @inode: the newly created inode
@@ -4548,6 +4506,7 @@ static int smack_dentry_create_files_as(struct dentry *dentry, int mode,
45484506struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = {
45494507 .lbs_cred = sizeof (struct task_smack ),
45504508 .lbs_file = sizeof (struct smack_known * ),
4509+ .lbs_inode = sizeof (struct inode_smack ),
45514510};
45524511
45534512static struct security_hook_list smack_hooks [] __lsm_ro_after_init = {
@@ -4565,7 +4524,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
45654524 LSM_HOOK_INIT (bprm_set_creds , smack_bprm_set_creds ),
45664525
45674526 LSM_HOOK_INIT (inode_alloc_security , smack_inode_alloc_security ),
4568- LSM_HOOK_INIT (inode_free_security , smack_inode_free_security ),
45694527 LSM_HOOK_INIT (inode_init_security , smack_inode_init_security ),
45704528 LSM_HOOK_INIT (inode_link , smack_inode_link ),
45714529 LSM_HOOK_INIT (inode_unlink , smack_inode_unlink ),
0 commit comments