aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>2013-05-24 18:55:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-24 19:22:50 -0400
commit7b92d03c3239f43e5b86c9cc9630f026d36ee995 (patch)
tree230d35077a9c99203a86a7abc94ce8d6645e23fb /fs
parent5eeb929390de7d5219483a1ca10cce4a84066099 (diff)
fat: fix possible overflow for fat_clusters
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> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/inode.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index dfce656ddb33..5d4513cb1b3c 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1229,6 +1229,19 @@ static int fat_read_root(struct inode *inode)
1229 return 0; 1229 return 0;
1230} 1230}
1231 1231
1232static unsigned long calc_fat_clusters(struct super_block *sb)
1233{
1234 struct msdos_sb_info *sbi = MSDOS_SB(sb);
1235
1236 /* Divide first to avoid overflow */
1237 if (sbi->fat_bits != 12) {
1238 unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
1239 return ent_per_sec * sbi->fat_length;
1240 }
1241
1242 return sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits;
1243}
1244
1232/* 1245/*
1233 * Read the super block of an MS-DOS FS. 1246 * Read the super block of an MS-DOS FS.
1234 */ 1247 */
@@ -1434,7 +1447,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
1434 sbi->dirty = b->fat16.state & FAT_STATE_DIRTY; 1447 sbi->dirty = b->fat16.state & FAT_STATE_DIRTY;
1435 1448
1436 /* check that FAT table does not overflow */ 1449 /* check that FAT table does not overflow */
1437 fat_clusters = sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits; 1450 fat_clusters = calc_fat_clusters(sb);
1438 total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT); 1451 total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT);
1439 if (total_clusters > MAX_FAT(sb)) { 1452 if (total_clusters > MAX_FAT(sb)) {
1440 if (!silent) 1453 if (!silent)