Files
linux/fs
Eric Biggers 8eea426006 UPSTREAM: fscrypt: don't evict dirty inodes after removing key
After FS_IOC_REMOVE_ENCRYPTION_KEY removes a key, it syncs the
filesystem and tries to get and put all inodes that were unlocked by the
key so that unused inodes get evicted via fscrypt_drop_inode().
Normally, the inodes are all clean due to the sync.

However, after the filesystem is sync'ed, userspace can modify and close
one of the files.  (Userspace is *supposed* to close the files before
removing the key.  But it doesn't always happen, and the kernel can't
assume it.)  This causes the inode to be dirtied and have i_count == 0.
Then, fscrypt_drop_inode() failed to consider this case and indicated
that the inode can be dropped, causing the write to be lost.

On f2fs, other problems such as a filesystem freeze could occur due to
the inode being freed while still on f2fs's dirty inode list.

Fix this bug by making fscrypt_drop_inode() only drop clean inodes.

I've written an xfstest which detects this bug on ext4, f2fs, and ubifs.

Fixes: b1c0ec3599 ("fscrypt: add FS_IOC_REMOVE_ENCRYPTION_KEY ioctl")
Cc: <stable@vger.kernel.org> # v5.4+
Link: https://lore.kernel.org/r/20200305084138.653498-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

(cherry picked from commit 2b4eae95c7)
Bug: 150589360
Test: kvm-xfstests -c ext4,f2fs -g encrypt
Change-Id: Ia32db980c2fffb68caeaf9f38e5cfbe781b45011
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-03-11 14:05:28 -07:00
..
2019-08-06 19:06:51 +02:00
2019-12-13 08:52:23 +01:00
2020-03-05 17:40:55 +01:00
2019-12-13 08:52:36 +01:00
2020-02-11 04:34:07 -08:00
2018-08-17 16:20:28 -07:00
2019-05-22 08:00:39 +02:00
2019-12-13 10:01:10 +01:00
2019-12-13 08:51:59 +01:00
2020-02-24 09:13:25 +01:00
2020-01-12 12:29:19 +01:00
2018-08-17 16:20:27 -07:00
2019-12-18 09:03:30 +01:00
2020-02-13 15:14:20 -08:00
2020-01-09 16:14:43 +01:00
2018-06-05 19:23:26 +02:00
2020-03-05 16:42:12 +01:00
2019-08-04 09:37:11 +02:00
2019-05-31 08:14:29 -07:00
2020-03-05 17:40:55 +01:00
2019-07-31 08:03:42 +02:00
2019-12-01 09:53:43 +01:00
2020-01-04 19:29:03 +01:00