[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241125132354.16188-1-arefev@swemel.ru>
Date: Mon, 25 Nov 2024 16:23:54 +0300
From: Denis Arefev <arefev@...mel.ru>
To: Richard Weinberger <richard@....at>
Cc: Zhihao Cheng <chengzhihao1@...wei.com>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Vignesh Raghavendra <vigneshr@...com>,
Artem Bityutskiy <Artem.Bityutskiy@...ia.com>,
linux-mtd@...ts.infradead.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] mtd: ubi: Added a check for ubi_num
Added a check for ubi_num for negative numbers
If the variable ubi_num takes negative values then we get:
qemu-system-arm ... -append "ubi.mtd=0,0,0,-22222345" ...
[ 0.745065] ubi_attach_mtd_dev from ubi_init+0x178/0x218
[ 0.745230] ubi_init from do_one_initcall+0x70/0x1ac
[ 0.745344] do_one_initcall from kernel_init_freeable+0x198/0x224
[ 0.745474] kernel_init_freeable from kernel_init+0x18/0x134
[ 0.745600] kernel_init from ret_from_fork+0x14/0x28
[ 0.745727] Exception stack(0x90015fb0 to 0x90015ff8)
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 897a316c9e6f ("UBI: handle attach ioctl")
Signed-off-by: Denis Arefev <arefev@...mel.ru>
---
drivers/mtd/ubi/build.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 30be4ed68fad..dae569f48b87 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -920,7 +920,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
return -ENFILE;
}
} else {
- if (ubi_num >= UBI_MAX_DEVICES)
+ if (ubi_num < UBI_DEV_NUM_AUTO || ubi_num >= UBI_MAX_DEVICES)
return -EINVAL;
/* Make sure ubi_num is not busy */
--
2.25.1
Powered by blists - more mailing lists