Skip to content

Commit 4df3892

Browse files
richardweinbergerdedekind
authored andcommitted
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>
1 parent 0a3d571 commit 4df3892

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎drivers/mtd/ubi/block.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,11 @@ int ubiblock_create(struct ubi_volume_info *vi)
378378
{
379379
struct ubiblock *dev;
380380
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;
382382
int ret;
383383

384+
if ((sector_t)disk_capacity != disk_capacity)
385+
return -EFBIG;
384386
/* Check that the volume isn't already handled */
385387
mutex_lock(&devices_mutex);
386388
if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
@@ -500,8 +502,13 @@ int ubiblock_remove(struct ubi_volume_info *vi)
500502
static int ubiblock_resize(struct ubi_volume_info *vi)
501503
{
502504
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;
504506

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+
}
505512
/*
506513
* Need to lock the device list until we stop using the device,
507514
* otherwise the device struct might get released in

0 commit comments

Comments
 (0)