mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-24 19:40:21 +09:00
fat: fix possible overflow for fat_clusters
BugLink: http://bugs.launchpad.net/bugs/1191065
commit 7b92d03c32 upstream.
Intermediate value of fat_clusters can be overflowed on 32bits arch.
Reported-by: Krzysztof Strasburger <strasbur@chkw386.ch.pwr.wroc.pl>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[ kamal: backport to 3.8 ]
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Steve Conklin <sconklin@canonical.com>
This commit is contained in:
committed by
Steve Conklin
parent
9007538372
commit
8f6d9e64b8
@@ -1165,6 +1165,19 @@ static int fat_read_root(struct inode *inode)
|
||||
return 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.
|
||||
*/
|
||||
@@ -1363,7 +1376,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
|
||||
sbi->fat_bits = (total_clusters > MAX_FAT12) ? 16 : 12;
|
||||
|
||||
/* 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)
|
||||
|
||||
Reference in New Issue
Block a user