Skip to content

Commit 0d606e2

Browse files
committed
ext4: fix type-widening bug in inode table readahead code
Due to a missing cast, the high 32-bits of a 64-bit block number used when calculating the readahead block for inode tables can get lost. This means we can end up fetching the wrong blocks for readahead for file systems > 16TB. Linus found this when experimenting with an enhacement to the sparse static code checker which checks for missing widening casts before binary "not" operators. Reported-by: Linus Torvalds <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]>
1 parent 3f8a641 commit 0d606e2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/ext4/inode.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,13 +4011,14 @@ static int __ext4_get_inode_loc(struct inode *inode,
40114011
if (EXT4_SB(sb)->s_inode_readahead_blks) {
40124012
ext4_fsblk_t b, end, table;
40134013
unsigned num;
4014+
__u32 ra_blks = EXT4_SB(sb)->s_inode_readahead_blks;
40144015

40154016
table = ext4_inode_table(sb, gdp);
40164017
/* s_inode_readahead_blks is always a power of 2 */
4017-
b = block & ~(EXT4_SB(sb)->s_inode_readahead_blks-1);
4018+
b = block & ~((ext4_fsblk_t) ra_blks - 1);
40184019
if (table > b)
40194020
b = table;
4020-
end = b + EXT4_SB(sb)->s_inode_readahead_blks;
4021+
end = b + ra_blks;
40214022
num = EXT4_INODES_PER_GROUP(sb);
40224023
if (ext4_has_group_desc_csum(sb))
40234024
num -= ext4_itable_unused_count(sb, gdp);

0 commit comments

Comments
 (0)