Re: [syzbot] [mtd?] WARNING: zero-size vmalloc in ubi_read_volume_table

From: Edward Adam Davis
Date: Tue Apr 02 2024 - 00:16:18 EST


please test zs in ubi_read_volume_table

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index f700f0e4f2ec..e3b337afdb4f 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -791,7 +791,8 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
* The number of supported volumes is limited by the eraseblock size
* and by the UBI_MAX_VOLUMES constant.
*/
- ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
+ ubi->vtbl_slots = ubi->leb_size > UBI_VTBL_RECORD_SIZE ?
+ ubi->leb_size / UBI_VTBL_RECORD_SIZE : 1;
if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
ubi->vtbl_slots = UBI_MAX_VOLUMES;