diff mbox series

[SRU,M,1/1] ubi: Check for too small LEB size in VTBL code

Message ID 20240607194157.18188-2-bethany.jamison@canonical.com
State New
Headers show
Series CVE-2024-25739 | expand

Commit Message

Bethany Jamison June 7, 2024, 7:41 p.m. UTC
From: Richard Weinberger <richard@nod.at>

[ Upstream commit 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: 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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit d1b505c988b711673d6a2de35222028be081d0d1 linux-6.6.y)
CVE-2024-25739
Signed-off-by: Bethany Jamison <bethany.jamison@canonical.com>
---
 drivers/mtd/ubi/vtbl.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Andrei Gherzan June 14, 2024, 9:38 a.m. UTC | #1
On 24/06/07 02:41pm, Bethany Jamison wrote:
> From: Richard Weinberger <richard@nod.at>
> 
> [ Upstream commit 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: 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>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> (cherry picked from commit d1b505c988b711673d6a2de35222028be081d0d1 linux-6.6.y)
> CVE-2024-25739
> Signed-off-by: Bethany Jamison <bethany.jamison@canonical.com>
> ---
>  drivers/mtd/ubi/vtbl.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
> index f700f0e4f2ec4..6e5489e233dd2 100644
> --- a/drivers/mtd/ubi/vtbl.c
> +++ b/drivers/mtd/ubi/vtbl.c
> @@ -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;

Acked-by: Andrei Gherzan <andrei.gherzan@canonical.com>
diff mbox series

Patch

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index f700f0e4f2ec4..6e5489e233dd2 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -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;