Skip to content

Commit 948ca5f

Browse files
Eric Whitneytytso
authored andcommitted
ext4: enforce buffer head state assertion in ext4_da_map_blocks
Remove the code that re-initializes a buffer head with an invalid block number and BH_New and BH_Delay bits when a matching delayed and unwritten block has been found in the extent status cache. Replace it with assertions that verify the buffer head already has this state correctly set. The current code masked an inline data truncation bug that left stale entries in the extent status cache. With this change, generic/130 can be used to reproduce and detect that bug. Signed-off-by: Eric Whitney <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0add491 commit 948ca5f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

fs/ext4/inode.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,13 +1706,16 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
17061706
}
17071707

17081708
/*
1709-
* Delayed extent could be allocated by fallocate.
1710-
* So we need to check it.
1709+
* the buffer head associated with a delayed and not unwritten
1710+
* block found in the extent status cache must contain an
1711+
* invalid block number and have its BH_New and BH_Delay bits
1712+
* set, reflecting the state assigned when the block was
1713+
* initially delayed allocated
17111714
*/
1712-
if (ext4_es_is_delayed(&es) && !ext4_es_is_unwritten(&es)) {
1713-
map_bh(bh, inode->i_sb, invalid_block);
1714-
set_buffer_new(bh);
1715-
set_buffer_delay(bh);
1715+
if (ext4_es_is_delonly(&es)) {
1716+
BUG_ON(bh->b_blocknr != invalid_block);
1717+
BUG_ON(!buffer_new(bh));
1718+
BUG_ON(!buffer_delay(bh));
17161719
return 0;
17171720
}
17181721

0 commit comments

Comments
 (0)