Commit 0d606e2c authored by Theodore Ts'o's avatar Theodore Ts'o

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: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 3f8a6411
...@@ -4011,13 +4011,14 @@ static int __ext4_get_inode_loc(struct inode *inode, ...@@ -4011,13 +4011,14 @@ static int __ext4_get_inode_loc(struct inode *inode,
if (EXT4_SB(sb)->s_inode_readahead_blks) { if (EXT4_SB(sb)->s_inode_readahead_blks) {
ext4_fsblk_t b, end, table; ext4_fsblk_t b, end, table;
unsigned num; unsigned num;
__u32 ra_blks = EXT4_SB(sb)->s_inode_readahead_blks;
table = ext4_inode_table(sb, gdp); table = ext4_inode_table(sb, gdp);
/* s_inode_readahead_blks is always a power of 2 */ /* s_inode_readahead_blks is always a power of 2 */
b = block & ~(EXT4_SB(sb)->s_inode_readahead_blks-1); b = block & ~((ext4_fsblk_t) ra_blks - 1);
if (table > b) if (table > b)
b = table; b = table;
end = b + EXT4_SB(sb)->s_inode_readahead_blks; end = b + ra_blks;
num = EXT4_INODES_PER_GROUP(sb); num = EXT4_INODES_PER_GROUP(sb);
if (ext4_has_group_desc_csum(sb)) if (ext4_has_group_desc_csum(sb))
num -= ext4_itable_unused_count(sb, gdp); num -= ext4_itable_unused_count(sb, gdp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment