fat: Fix possible overflow for fat_clusters
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
OGAWA Hirofumi
maintainerPATCH 1/1 fat: Fix possible overflow for fat_clusters
Intermediate value of fat_clusters can be overflowed on 32bits arch.
Reported-by Krzysztof Strasburger <[email protected]>
Signed-off-by OGAWA Hirofumi <[email protected]>
---
fs/fat/inode.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
fs/fat/inode.c renamed from fs/fat/inode.c~fat-fat_clusters-overflow-fix +14 -1
@@ -1223,6 +1223,19 @@ static int fat_read_root(struct inode *ireturn 0 ; } +static unsigned long calc_fat_clusters (struct super_block *sb) +{ +struct msdos_sb_info *sbi =MSDOS_SB (sb); + +/* Divide first to avoid overflow */ +if (sbi->fat_bits !=12 ) { +unsigned long ent_per_sec = sb->s_blocksize *8 / sbi->fat_bits; +return ent_per_sec * sbi->fat_length; + } + +return sbi->fat_length * sb->s_blocksize *8 / sbi->fat_bits; +} +/* * Read the super block of an MS-DOS FS. */
@@ -1427,7 +1440,7 @@ int fat_fill_super(struct super_block *s sbi->dirty = b->fat16.state &FAT_STATE_DIRTY ;/* check that FAT table does not overflow */ - fat_clusters = sbi->fat_length * sb->s_blocksize *8 / sbi->fat_bits; + fat_clusters =calc_fat_clusters (sb); total_clusters =min (total_clusters, fat_clusters -FAT_START_ENT );if (total_clusters >MAX_FAT (sb)) {if (!silent)
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>