Add fix-inline-updates-with-csums-enabled and
[ext4-patch-queue.git] / recheck-verified-flag-under-lock-in-ext4_validate_inode_bitmap
blob8be40244d862b9485a48bfd6770721033bba1d04
1 ext4: check for allocation block validity with block group locked
3 With commit 044e6e3d74a3: "ext4: don't update checksum of new
4 initialized bitmaps" the buffer valid bit will get set without
5 actually setting up the checksum for the allocation bitmap, since the
6 checksum will get calculated once we actually allocate an inode or
7 block.
9 If we are doing this, then we need to (re-)check the verified bit
10 after we take the block group lock.  Otherwise, we could race with
11 another process reading and verifying the bitmap, which would then
12 complain about the checksum being invalid.
14 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1780137
16 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
17 Cc: stable@kernel.org
18 ---
19  fs/ext4/balloc.c | 3 +++
20  fs/ext4/ialloc.c | 3 +++
21  2 files changed, 6 insertions(+)
23 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
24 index e68cefe08261..aa52d87985aa 100644
25 --- a/fs/ext4/balloc.c
26 +++ b/fs/ext4/balloc.c
27 @@ -368,6 +368,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
28                 return -EFSCORRUPTED;
30         ext4_lock_group(sb, block_group);
31 +       if (buffer_verified(bh))
32 +               goto verified;
33         if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
34                         desc, bh))) {
35                 ext4_unlock_group(sb, block_group);
36 @@ -386,6 +388,7 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
37                 return -EFSCORRUPTED;
38         }
39         set_buffer_verified(bh);
40 +verified:
41         ext4_unlock_group(sb, block_group);
42         return 0;
43  }
44 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
45 index fb83750c1a14..e9d8e2667ab5 100644
46 --- a/fs/ext4/ialloc.c
47 +++ b/fs/ext4/ialloc.c
48 @@ -90,6 +90,8 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
49                 return -EFSCORRUPTED;
51         ext4_lock_group(sb, block_group);
52 +       if (buffer_verified(bh))
53 +               goto verified;
54         blk = ext4_inode_bitmap(sb, desc);
55         if (!ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh,
56                                            EXT4_INODES_PER_GROUP(sb) / 8)) {
57 @@ -101,6 +103,7 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
58                 return -EFSBADCRC;
59         }
60         set_buffer_verified(bh);
61 +verified:
62         ext4_unlock_group(sb, block_group);
63         return 0;
64  }