Skip to content

Commit

Permalink
UBI: block: Avoid disk size integer overflow
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Richard Weinberger authored and Artem Bityutskiy committed Jul 28, 2014
1 parent 0a3d571 commit 4df3892
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/mtd/ubi/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ int ubiblock_create(struct ubi_volume_info *vi)
{
struct ubiblock *dev;
struct gendisk *gd;
int disk_capacity = (vi->size * vi->usable_leb_size) >> 9;
u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9;
int ret;

if ((sector_t)disk_capacity != disk_capacity)
return -EFBIG;
/* Check that the volume isn't already handled */
mutex_lock(&devices_mutex);
if (find_dev_nolock(vi->ubi_num, vi->vol_id)) {
Expand Down Expand Up @@ -500,8 +502,13 @@ int ubiblock_remove(struct ubi_volume_info *vi)
static int ubiblock_resize(struct ubi_volume_info *vi)
{
struct ubiblock *dev;
int disk_capacity = (vi->size * vi->usable_leb_size) >> 9;
u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9;

if ((sector_t)disk_capacity != disk_capacity) {
ubi_warn("%s: the volume is too big, cannot resize (%d LEBs)",
dev->gd->disk_name, vi->size);
return -EFBIG;
}
/*
* Need to lock the device list until we stop using the device,
* otherwise the device struct might get released in
Expand Down

0 comments on commit 4df3892

Please sign in to comment.