Skip to content

Commit

Permalink
md: avoid overflow in raid0 calculation with large components
Browse files Browse the repository at this point in the history
If a raid0 has a component device larger than 4TB, and is accessed on a 32bit
machines, then as 'chunk' is unsigned long,

   chunk << chunksize_bits

can overflow (this can be as high as the size of the device in KB).  chunk
itself will not overflow (without triggering a BUG).

So change 'chunk' to be 'sector_t, and get rid of the 'BUG' as it becomes
impossible to hit.

Cc: "Jeff Zheng" <Jeff.Zheng@endace.com>
Signed-off-by: Neil Brown <neilb@suse.de>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
NeilBrown authored and Linus Torvalds committed May 24, 2007
1 parent 1dbf37e commit 787f17f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/md/raid0.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static int raid0_make_request (request_queue_t *q, struct bio *bio)
raid0_conf_t *conf = mddev_to_conf(mddev);
struct strip_zone *zone;
mdk_rdev_t *tmp_dev;
unsigned long chunk;
sector_t chunk;
sector_t block, rsect;
const int rw = bio_data_dir(bio);

Expand Down Expand Up @@ -470,7 +470,6 @@ static int raid0_make_request (request_queue_t *q, struct bio *bio)

sector_div(x, zone->nb_dev);
chunk = x;
BUG_ON(x != (sector_t)chunk);

x = block >> chunksize_bits;
tmp_dev = zone->dev[sector_div(x, zone->nb_dev)];
Expand Down

0 comments on commit 787f17f

Please sign in to comment.