Skip to content

Commit 3ebacb0

Browse files
Mikulas Patockatorvalds
authored andcommitted
hpfs: better test for errors
The test if bitmap access is out of bound could errorneously pass if the device size is divisible by 16384 sectors and we are asking for one bitmap after the end. Check for invalid size in the superblock. Invalid size could cause integer overflows in the rest of the code. Signed-off-by: Mikulas Patocka <mpatocka@artax.karlin.mff.cuni.cz> Cc: stable@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8bb495e commit 3ebacb0

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎fs/hpfs/map.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ __le32 *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
1717
struct quad_buffer_head *qbh, char *id)
1818
{
1919
secno sec;
20-
if (hpfs_sb(s)->sb_chk) if (bmp_block * 16384 > hpfs_sb(s)->sb_fs_size) {
20+
unsigned n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
21+
if (hpfs_sb(s)->sb_chk) if (bmp_block >= n_bands) {
2122
hpfs_error(s, "hpfs_map_bitmap called with bad parameter: %08x at %s", bmp_block, id);
2223
return NULL;
2324
}

‎fs/hpfs/super.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,13 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
558558
sbi->sb_cp_table = NULL;
559559
sbi->sb_c_bitmap = -1;
560560
sbi->sb_max_fwd_alloc = 0xffffff;
561-
561+
562+
if (sbi->sb_fs_size >= 0x80000000) {
563+
hpfs_error(s, "invalid size in superblock: %08x",
564+
(unsigned)sbi->sb_fs_size);
565+
goto bail4;
566+
}
567+
562568
/* Load bitmap directory */
563569
if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
564570
goto bail4;

0 commit comments

Comments
 (0)