Commit 0b890629 authored by Richard Weinberger's avatar Richard Weinberger Committed by ZhaoLong Wang
Browse files

ubi: Check for too small LEB size in VTBL code

mainline inclusion
from mainline-v6.9-rc1
commit 68a24aba7c593eafa8fd00f2f76407b9b32b47a9
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I91L79
CVE: CVE-2024-25739

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=68a24aba7c593eafa8fd00f2f76407b9b32b47a9



--------------------------------

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: 801c135c ("UBI: Unsorted Block Images")
Reported-by: default avatarChenyuan Yang <cy54@illinois.edu>
Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/


Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: default avatarZhaoLong Wang <wangzhaolong1@huawei.com>
parent a474d353
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -791,6 +791,12 @@ 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.
	 */

	if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) {
		ubi_err(ubi, "LEB size too small for a volume record");
		return -EINVAL;
	}

	ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
	if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
		ubi->vtbl_slots = UBI_MAX_VOLUMES;