Skip to content

Commit e6e6ec4

Browse files
committed
Merge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt
Pull fscrypt fix from Eric Biggers: "Fix a bug where if userspace is writing to encrypted files while the FS_IOC_REMOVE_ENCRYPTION_KEY ioctl (introduced in v5.4) is running, dirty inodes could be evicted, causing writes could be lost or the filesystem to hang due to a use-after-free. This was encountered during real-world use, not just theoretical. Tested with the existing fscrypt xfstests, and with a new xfstest I wrote to reproduce this bug. This fix does expose an existing bug with '-o lazytime' that Ted is working on fixing, but this fix is more critical and needed anyway regardless of the lazytime fix" * tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt: fscrypt: don't evict dirty inodes after removing key
2 parents addcb1d + 2b4eae9 commit e6e6ec4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/crypto/keysetup.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,15 @@ int fscrypt_drop_inode(struct inode *inode)
538538
return 0;
539539
mk = ci->ci_master_key->payload.data[0];
540540

541+
/*
542+
* With proper, non-racy use of FS_IOC_REMOVE_ENCRYPTION_KEY, all inodes
543+
* protected by the key were cleaned by sync_filesystem(). But if
544+
* userspace is still using the files, inodes can be dirtied between
545+
* then and now. We mustn't lose any writes, so skip dirty inodes here.
546+
*/
547+
if (inode->i_state & I_DIRTY_ALL)
548+
return 0;
549+
541550
/*
542551
* Note: since we aren't holding ->mk_secret_sem, the result here can
543552
* immediately become outdated. But there's no correctness problem with

0 commit comments

Comments
 (0)