Skip to content

Commit 4bcf6f8

Browse files
committed
fscrypt: check for NULL keyring in fscrypt_put_master_key_activeref()
It is a bug for fscrypt_put_master_key_activeref() to see a NULL keyring. But it used to be possible due to the bug, now fixed, where fscrypt_destroy_keyring() was called before security_sb_delete(). To be consistent with how fscrypt_destroy_keyring() uses WARN_ON for the same issue, WARN and leak the fscrypt_master_key if the keyring is NULL instead of dereferencing the NULL pointer. This is a robustness improvement, not a fix. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 43e5f1d commit 4bcf6f8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/crypto/keyring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ void fscrypt_put_master_key_activeref(struct super_block *sb,
9292
* destroying any subkeys embedded in it.
9393
*/
9494

95+
if (WARN_ON(!sb->s_master_keys))
96+
return;
9597
spin_lock(&sb->s_master_keys->lock);
9698
hlist_del_rcu(&mk->mk_node);
9799
spin_unlock(&sb->s_master_keys->lock);

0 commit comments

Comments
 (0)