Merge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux

Pull fscrypt fix from Eric Biggers:
 "Fix a NULL dereference that was theoretically possible if
  FS_IOC_SETFLAGS was called to set the casefold flag on an
  encrypted directory concurrently with its encryption key
  being set up"

* tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/linux:
  fscrypt: Initialize ->ci_master_key before publication
This commit is contained in:
Linus Torvalds
2026-11-18 08:48:22 -08:00
+13 -1
View File
@@ -621,6 +621,13 @@ fscrypt_setup_encryption_info(struct inode *inode,
if (res)
goto out;
/*
* Preemptively initialize ->ci_master_key, even though we don't know
* whether we'll win the race below yet, because if we do win the race
* then other tasks can see it right away and need ->ci_master_key.
*/
crypt_info->ci_master_key = mk;
/*
* For existing inodes, multiple tasks may race to set the inode's
* fscrypt info pointer. So use cmpxchg_release(). This pairs with the
@@ -634,7 +641,6 @@ fscrypt_setup_encryption_info(struct inode *inode,
* crypt_info. Now link it into the master key's inode list.
*/
if (mk) {
crypt_info->ci_master_key = mk;
refcount_inc(&mk->mk_active_refs);
spin_lock(&mk->mk_decrypted_inodes_lock);
list_add(&crypt_info->ci_master_key_link,
@@ -642,6 +648,12 @@ fscrypt_setup_encryption_info(struct inode *inode,
spin_unlock(&mk->mk_decrypted_inodes_lock);
}
crypt_info = NULL;
} else {
/*
* Lost the race, so we won't be taking an active reference to
* the master key. Clear ->ci_master_key accordingly.
*/
crypt_info->ci_master_key = NULL;
}
res = 0;
out: