]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.170/ext4-prohibit-fstrim-in-norecovery-mode.patch
Linux 4.9.170
[thirdparty/kernel/stable-queue.git] / releases / 4.9.170 / ext4-prohibit-fstrim-in-norecovery-mode.patch
1 From 92a88a05446bd66749f21ab2afd75e7e17183810 Mon Sep 17 00:00:00 2001
2 From: "Darrick J. Wong" <darrick.wong@oracle.com>
3 Date: Sat, 23 Mar 2019 12:10:29 -0400
4 Subject: ext4: prohibit fstrim in norecovery mode
5
6 [ Upstream commit 18915b5873f07e5030e6fb108a050fa7c71c59fb ]
7
8 The ext4 fstrim implementation uses the block bitmaps to find free space
9 that can be discarded. If we haven't replayed the journal, the bitmaps
10 will be stale and we absolutely *cannot* use stale metadata to zap the
11 underlying storage.
12
13 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 Signed-off-by: Sasha Levin <sashal@kernel.org>
16 ---
17 fs/ext4/ioctl.c | 7 +++++++
18 1 file changed, 7 insertions(+)
19
20 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
21 index 2880e017cd0a..2ce73287b53c 100644
22 --- a/fs/ext4/ioctl.c
23 +++ b/fs/ext4/ioctl.c
24 @@ -749,6 +749,13 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
25 if (!blk_queue_discard(q))
26 return -EOPNOTSUPP;
27
28 + /*
29 + * We haven't replayed the journal, so we cannot use our
30 + * block-bitmap-guided storage zapping commands.
31 + */
32 + if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb))
33 + return -EROFS;
34 +
35 if (copy_from_user(&range, (struct fstrim_range __user *)arg,
36 sizeof(range)))
37 return -EFAULT;
38 --
39 2.19.1
40