]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
fscrypt: check for NULL keyring in fscrypt_put_master_key_activeref()
authorEric Biggers <ebiggers@google.com>
Mon, 13 Mar 2023 22:12:31 +0000 (15:12 -0700)
committerEric Biggers <ebiggers@google.com>
Sun, 19 Mar 2023 04:08:03 +0000 (21:08 -0700)
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/20230313221231.272498-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
fs/crypto/keyring.c

index bb15709ac9a40ad5eba5ee8bfdbf554d29096980..13d336a6cc5da5675fa322d3d793c13a56291848 100644 (file)
@@ -92,6 +92,8 @@ void fscrypt_put_master_key_activeref(struct super_block *sb,
         * destroying any subkeys embedded in it.
         */
 
+       if (WARN_ON(!sb->s_master_keys))
+               return;
        spin_lock(&sb->s_master_keys->lock);
        hlist_del_rcu(&mk->mk_node);
        spin_unlock(&sb->s_master_keys->lock);