Skip to content

Commit ccb820d

Browse files
committed
fscrypt: destroy keyring after security_sb_delete()
fscrypt_destroy_keyring() must be called after all potentially-encrypted inodes were evicted; otherwise it cannot safely destroy the keyring. Since inodes that are in-use by the Landlock LSM don't get evicted until security_sb_delete(), this means that fscrypt_destroy_keyring() must be called *after* security_sb_delete(). This fixes a WARN_ON followed by a NULL dereference, only possible if Landlock was being used on encrypted files. Fixes: d7e7b9a ("fscrypt: stop using keyrings subsystem for fscrypt_master_key") Cc: [email protected] Reported-by: [email protected] Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent fe15c26 commit ccb820d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/super.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,22 @@ void generic_shutdown_super(struct super_block *sb)
475475

476476
cgroup_writeback_umount();
477477

478-
/* evict all inodes with zero refcount */
478+
/* Evict all inodes with zero refcount. */
479479
evict_inodes(sb);
480-
/* only nonzero refcount inodes can have marks */
480+
481+
/*
482+
* Clean up and evict any inodes that still have references due
483+
* to fsnotify or the security policy.
484+
*/
481485
fsnotify_sb_delete(sb);
482-
fscrypt_destroy_keyring(sb);
483486
security_sb_delete(sb);
484487

488+
/*
489+
* Now that all potentially-encrypted inodes have been evicted,
490+
* the fscrypt keyring can be destroyed.
491+
*/
492+
fscrypt_destroy_keyring(sb);
493+
485494
if (sb->s_dio_done_wq) {
486495
destroy_workqueue(sb->s_dio_done_wq);
487496
sb->s_dio_done_wq = NULL;

0 commit comments

Comments
 (0)