aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2014-05-05 06:11:54 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2014-07-28 11:52:13 -0400
commit4df38926f337ff4de49a8fb512aa4a55df0c502d (patch)
tree9679247b25fbc93fe8a80bad8f3fa2561e21193f
parent0a3d571bb8940a189322cc5f51466bdab044a48b (diff)
UBI: block: Avoid disk size integer overflow
This patch fixes the issue that on very large UBI volumes UBI block does not work correctly. Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
-rw-r--r--drivers/mtd/ubi/block.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 043919ad35e4..33c64955d4d7 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -378,9 +378,11 @@ int ubiblock_create(struct ubi_volume_info *vi)
378{ 378{
379 struct ubiblock *dev; 379 struct ubiblock *dev;
380 struct gendisk *gd; 380 struct gendisk *gd;
381 int disk_capacity = (vi->size * vi->usable_leb_size) >> 9; 381 u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9;
382 int ret; 382 int ret;
383 383
384 if ((sector_t)disk_capacity != disk_capacity)
385 return -EFBIG;
384 /* Check that the volume isn't already handled */ 386 /* Check that the volume isn't already handled */
385 mutex_lock(&devices_mutex); 387 mutex_lock(&devices_mutex);
386 if (find_dev_nolock(vi->ubi_num, vi->vol_id)) { 388 if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
@@ -500,8 +502,13 @@ int ubiblock_remove(struct ubi_volume_info *vi)
500static int ubiblock_resize(struct ubi_volume_info *vi) 502static int ubiblock_resize(struct ubi_volume_info *vi)
501{ 503{
502 struct ubiblock *dev; 504 struct ubiblock *dev;
503 int disk_capacity = (vi->size * vi->usable_leb_size) >> 9; 505 u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9;
504 506
507 if ((sector_t)disk_capacity != disk_capacity) {
508 ubi_warn("%s: the volume is too big, cannot resize (%d LEBs)",
509 dev->gd->disk_name, vi->size);
510 return -EFBIG;
511 }
505 /* 512 /*
506 * Need to lock the device list until we stop using the device, 513 * Need to lock the device list until we stop using the device,
507 * otherwise the device struct might get released in 514 * otherwise the device struct might get released in