File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,14 +205,19 @@ static int allocate_filesystem_keyring(struct super_block *sb)
205205}
206206
207207/*
208- * This is called at unmount time to release all encryption keys that have been
209- * added to the filesystem, along with the keyring that contains them.
208+ * Release all encryption keys that have been added to the filesystem, along
209+ * with the keyring that contains them.
210210 *
211- * Note that besides clearing and freeing memory, this might need to evict keys
212- * from the keyslots of an inline crypto engine. Therefore, this must be called
213- * while the filesystem's underlying block device(s) are still available.
211+ * This is called at unmount time. The filesystem's underlying block device(s)
212+ * are still available at this time; this is important because after user file
213+ * accesses have been allowed, this function may need to evict keys from the
214+ * keyslots of an inline crypto engine, which requires the block device(s).
215+ *
216+ * This is also called when the super_block is being freed. This is needed to
217+ * avoid a memory leak if mounting fails after the "test_dummy_encryption"
218+ * option was processed, as in that case the unmount-time call isn't made.
214219 */
215- void fscrypt_sb_delete (struct super_block * sb )
220+ void fscrypt_destroy_keyring (struct super_block * sb )
216221{
217222 struct fscrypt_keyring * keyring = sb -> s_master_keys ;
218223 size_t i ;
Original file line number Diff line number Diff line change @@ -291,6 +291,7 @@ static void __put_super(struct super_block *s)
291291 WARN_ON (s -> s_inode_lru .node );
292292 WARN_ON (!list_empty (& s -> s_mounts ));
293293 security_sb_free (s );
294+ fscrypt_destroy_keyring (s );
294295 put_user_ns (s -> s_user_ns );
295296 kfree (s -> s_subtype );
296297 call_rcu (& s -> rcu , destroy_super_rcu );
@@ -479,7 +480,7 @@ void generic_shutdown_super(struct super_block *sb)
479480 evict_inodes (sb );
480481 /* only nonzero refcount inodes can have marks */
481482 fsnotify_sb_delete (sb );
482- fscrypt_sb_delete (sb );
483+ fscrypt_destroy_keyring (sb );
483484 security_sb_delete (sb );
484485
485486 if (sb -> s_dio_done_wq ) {
Original file line number Diff line number Diff line change @@ -307,7 +307,7 @@ fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
307307}
308308
309309/* keyring.c */
310- void fscrypt_sb_delete (struct super_block * sb );
310+ void fscrypt_destroy_keyring (struct super_block * sb );
311311int fscrypt_ioctl_add_key (struct file * filp , void __user * arg );
312312int fscrypt_add_test_dummy_key (struct super_block * sb ,
313313 const struct fscrypt_dummy_policy * dummy_policy );
@@ -521,7 +521,7 @@ fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
521521}
522522
523523/* keyring.c */
524- static inline void fscrypt_sb_delete (struct super_block * sb )
524+ static inline void fscrypt_destroy_keyring (struct super_block * sb )
525525{
526526}
527527
You can’t perform that action at this time.
0 commit comments