Skip to content

Commit 0b57c55

Browse files
tytsoZhengShunQian
authored andcommitted
ext4: check for allocation block validity with block group locked
commit 8d5a803 upstream. With commit 044e6e3: "ext4: don't update checksum of new initialized bitmaps" the buffer valid bit will get set without actually setting up the checksum for the allocation bitmap, since the checksum will get calculated once we actually allocate an inode or block. If we are doing this, then we need to (re-)check the verified bit after we take the block group lock. Otherwise, we could race with another process reading and verifying the bitmap, which would then complain about the checksum being invalid. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1780137 Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 75738b7 commit 0b57c55

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

fs/ext4/balloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
378378
return -EFSCORRUPTED;
379379

380380
ext4_lock_group(sb, block_group);
381+
if (buffer_verified(bh))
382+
goto verified;
381383
if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
382384
desc, bh))) {
383385
ext4_unlock_group(sb, block_group);
@@ -400,6 +402,7 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
400402
return -EFSCORRUPTED;
401403
}
402404
set_buffer_verified(bh);
405+
verified:
403406
ext4_unlock_group(sb, block_group);
404407
return 0;
405408
}

fs/ext4/ialloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
8888
return -EFSCORRUPTED;
8989

9090
ext4_lock_group(sb, block_group);
91+
if (buffer_verified(bh))
92+
goto verified;
9193
blk = ext4_inode_bitmap(sb, desc);
9294
if (!ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh,
9395
EXT4_INODES_PER_GROUP(sb) / 8)) {
@@ -105,6 +107,7 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
105107
return -EFSBADCRC;
106108
}
107109
set_buffer_verified(bh);
110+
verified:
108111
ext4_unlock_group(sb, block_group);
109112
return 0;
110113
}

0 commit comments

Comments
 (0)