Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ubi: Check for too small LEB size in VTBL code

If the LEB size is smaller than a volume table record we cannot
have volumes.
In this case abort attaching.

Cc: Chenyuan Yang <cy54@illinois.edu>
Cc: stable@vger.kernel.org
Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
Reported-by: Chenyuan Yang <cy54@illinois.edu>
Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/
Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

+6
+6
drivers/mtd/ubi/vtbl.c
··· 791 791 * The number of supported volumes is limited by the eraseblock size 792 792 * and by the UBI_MAX_VOLUMES constant. 793 793 */ 794 + 795 + if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) { 796 + ubi_err(ubi, "LEB size too small for a volume record"); 797 + return -EINVAL; 798 + } 799 + 794 800 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE; 795 801 if (ubi->vtbl_slots > UBI_MAX_VOLUMES) 796 802 ubi->vtbl_slots = UBI_MAX_VOLUMES;