]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/ubi-check-for-too-small-leb-size-in-vtbl-code.patch
Fixes for 6.6
[thirdparty/kernel/stable-queue.git] / queue-6.6 / ubi-check-for-too-small-leb-size-in-vtbl-code.patch
1 From ae42121b0cffa26a09c4402d42710324e762c36c Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 24 Jan 2024 07:37:02 +0100
4 Subject: ubi: Check for too small LEB size in VTBL code
5
6 From: Richard Weinberger <richard@nod.at>
7
8 [ Upstream commit 68a24aba7c593eafa8fd00f2f76407b9b32b47a9 ]
9
10 If the LEB size is smaller than a volume table record we cannot
11 have volumes.
12 In this case abort attaching.
13
14 Cc: Chenyuan Yang <cy54@illinois.edu>
15 Cc: stable@vger.kernel.org
16 Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
17 Reported-by: Chenyuan Yang <cy54@illinois.edu>
18 Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/
19 Signed-off-by: Richard Weinberger <richard@nod.at>
20 Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
21 Signed-off-by: Sasha Levin <sashal@kernel.org>
22 ---
23 drivers/mtd/ubi/vtbl.c | 6 ++++++
24 1 file changed, 6 insertions(+)
25
26 diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
27 index f700f0e4f2ec4..6e5489e233dd2 100644
28 --- a/drivers/mtd/ubi/vtbl.c
29 +++ b/drivers/mtd/ubi/vtbl.c
30 @@ -791,6 +791,12 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
31 * The number of supported volumes is limited by the eraseblock size
32 * and by the UBI_MAX_VOLUMES constant.
33 */
34 +
35 + if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) {
36 + ubi_err(ubi, "LEB size too small for a volume record");
37 + return -EINVAL;
38 + }
39 +
40 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
41 if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
42 ubi->vtbl_slots = UBI_MAX_VOLUMES;
43 --
44 2.43.0
45