mbedtls: update to version 2.7.5
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-4.4 / 005-ext4-fix-check-to-prevent-initializing-reserved-inod.patch
1 From 7cb53d379df849d843cfd658f351b79b41b09051 Mon Sep 17 00:00:00 2001
2 Message-Id: <7cb53d379df849d843cfd658f351b79b41b09051.1533837011.git.mschiffer@universe-factory.net>
3 From: Theodore Ts'o <tytso@mit.edu>
4 Date: Sat, 28 Jul 2018 08:12:04 -0400
5 Subject: [PATCH] ext4: fix check to prevent initializing reserved inodes
6
7 Commit 5012284700775a4e6e3fbe7eac4c543c4874b559 upstream.
8
9 Commit 8844618d8aa7: "ext4: only look at the bg_flags field if it is
10 valid" will complain if block group zero does not have the
11 EXT4_BG_INODE_ZEROED flag set. Unfortunately, this is not correct,
12 since a freshly created file system has this flag cleared. It gets
13 almost immediately after the file system is mounted read-write --- but
14 the following somewhat unlikely sequence will end up triggering a
15 false positive report of a corrupted file system:
16
17 mkfs.ext4 /dev/vdc
18 mount -o ro /dev/vdc /vdc
19 mount -o remount,rw /dev/vdc
20
21 Instead, when initializing the inode table for block group zero, test
22 to make sure that itable_unused count is not too large, since that is
23 the case that will result in some or all of the reserved inodes
24 getting cleared.
25
26 This fixes the failures reported by Eric Whiteney when running
27 generic/230 and generic/231 in the the nojournal test case.
28
29 Fixes: 8844618d8aa7 ("ext4: only look at the bg_flags field if it is valid")
30 Reported-by: Eric Whitney <enwlinux@gmail.com>
31 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
32 ---
33 fs/ext4/ialloc.c | 5 ++++-
34 fs/ext4/super.c | 8 +-------
35 2 files changed, 5 insertions(+), 8 deletions(-)
36
37 --- a/fs/ext4/ialloc.c
38 +++ b/fs/ext4/ialloc.c
39 @@ -1308,7 +1308,10 @@ int ext4_init_inode_table(struct super_b
40 ext4_itable_unused_count(sb, gdp)),
41 sbi->s_inodes_per_block);
42
43 - if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group)) {
44 + if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) ||
45 + ((group == 0) && ((EXT4_INODES_PER_GROUP(sb) -
46 + ext4_itable_unused_count(sb, gdp)) <
47 + EXT4_FIRST_INO(sb)))) {
48 ext4_error(sb, "Something is wrong with group %u: "
49 "used itable blocks: %d; "
50 "itable unused count: %u",
51 --- a/fs/ext4/super.c
52 +++ b/fs/ext4/super.c
53 @@ -2875,14 +2875,8 @@ static ext4_group_t ext4_has_uninit_itab
54 if (!gdp)
55 continue;
56
57 - if (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))
58 - continue;
59 - if (group != 0)
60 + if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
61 break;
62 - ext4_error(sb, "Inode table for bg 0 marked as "
63 - "needing zeroing");
64 - if (sb->s_flags & MS_RDONLY)
65 - return ngroups;
66 }
67
68 return group;