Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fat: use fat_fs_error() instead of BUG_ON() in __fat_get_block()

If file size and FAT cluster chain is not matched (corrupted image), we
can hit BUG_ON(!phys) in __fat_get_block().

So, use fat_fs_error() instead.

[hirofumi@mail.parknet.co.jp: fix printk warning]
Link: http://lkml.kernel.org/r/87po12aq5p.fsf@mail.parknet.co.jp
Link: http://lkml.kernel.org/r/874lilcu67.fsf@mail.parknet.co.jp
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reported-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Tested-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

OGAWA Hirofumi and committed by
Linus Torvalds
c2574aaa 26b95137

+7 -1
+7 -1
fs/fat/inode.c
··· 158 158 err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create, false); 159 159 if (err) 160 160 return err; 161 + if (!phys) { 162 + fat_fs_error(sb, 163 + "invalid FAT chain (i_pos %lld, last_block %llu)", 164 + MSDOS_I(inode)->i_pos, 165 + (unsigned long long)last_block); 166 + return -EIO; 167 + } 161 168 162 - BUG_ON(!phys); 163 169 BUG_ON(*max_blocks != mapped_blocks); 164 170 set_buffer_new(bh_result); 165 171 map_bh(bh_result, sb, phys);