Skip to content

Commit

Permalink
btrfs: avoid overflow when sector_t is 32 bit
Browse files Browse the repository at this point in the history
Jean-Denis Girard noticed commit c821e7f "pass bytes to
btrfs_bio_alloc" (https://patchwork.kernel.org/patch/9763081/)
introduces a regression on 32 bit machines.
When CONFIG_LBDAF is _not_ defined (CONFIG_LBDAF == Support for large
(2TB+) block devices and files) sector_t is 32 bit on 32bit machines.

In the function submit_extent_page, 'sector' (which is sector_t type) is
multiplied by 512 to convert it from sectors to bytes, leading to an
overflow when the disk is bigger than 4GB (!).

I added a cast to u64 to avoid overflow.

Fixes: c821e7f ("btrfs: pass bytes to btrfs_bio_alloc")
CC: [email protected] # 4.13+
Signed-off-by: Goffredo Baroncelli <[email protected]>
Tested-by: Jean-Denis Girard <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kreijack authored and kdave committed Oct 4, 2017
1 parent 8c6c592 commit 2d8ce70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2801,7 +2801,7 @@ static int submit_extent_page(unsigned int opf, struct extent_io_tree *tree,
}
}

bio = btrfs_bio_alloc(bdev, sector << 9);
bio = btrfs_bio_alloc(bdev, (u64)sector << 9);
bio_add_page(bio, page, page_size, offset);
bio->bi_end_io = end_io_func;
bio->bi_private = tree;
Expand Down

0 comments on commit 2d8ce70

Please sign in to comment.