Skip to contentSkip to conversation

Bufferoverflow on eMMC partition handling

PATCH Applied Florian Otte 2 participants 5 messages Sep 2, 2024 – Sep 11, 2024 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi Everyone.

I tried to use all general purpose partitions on an eMMC storage device and ran into some trouble. In ./include/mci.h the number of partitions is limited to 6, but there might be 7 partitions. This results in a buffer overflow or access out of bound and causes a nasty bootloop when all general purpose-partitions are used. I created a simple patch and appended it to this mail.

Kind regards
fotte

[Edit]: Sorry. Clicked the wrong button to fast. Now with Attachment.

Quoted 1 line

From 0bae0df23bbc4a9e98f1bcac6c6fbe0c3b21bc78 Mon Sep 17 00:00:00 2001

From: Florian Otte <[email protected]>
Date: Mon, 2 Sep 2024 11:27:47 +0200
Subject: [PATCH] FIX: buffer overflow on MCI-partition enumeration

Memory for up to 6 partitions is reserved, however there can be up to 7 partitions on an mci storage (e.g. emmc). A user partition two boot partitions and up to four general pupose partitions.

---
 include/mci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/mci.h +4 -1
index 3bf1455a40..cd01e2f992 100644
@@ -600,7 +600,10 @@ struct mci_host {
 
 #define MMC_NUM_BOOT_PARTITION	2
 #define MMC_NUM_GP_PARTITION	4
-#define MMC_NUM_PHY_PARTITION	6
+#define MMC_NUM_USER_PARTITION	1
+#define MMC_NUM_PHY_PARTITION	(MMC_NUM_BOOT_PARTITION + \
+                                 MMC_NUM_GP_PARTITION + \
+                                 MMC_NUM_USER_PARTITION)
 
 struct mci_part {
 	struct block_device	blk;		/**< the blockdevice for the card */
Signature · 1 line
2.39.2
#2 lore raw
In reply to Florian Otte
Quoted 19 lines · Florian Otte

Hi Everyone.

I tried to use all general purpose partitions on an eMMC storage device and ran into some trouble. In ./include/mci.h the number of partitions is limited to 6, but there might be 7 partitions. This results in a buffer overflow or access out of bound and causes a nasty bootloop when all general purpose-partitions are used. I created a simple patch and appended it to this mail.

Kind regards
fotte

[Edit]: Sorry. Clicked the wrong button to fast. Now with Attachment.

From 0bae0df23bbc4a9e98f1bcac6c6fbe0c3b21bc78 Mon Sep 17 00:00:00 2001
From: Florian Otte <[email protected]>
Date: Mon, 2 Sep 2024 11:27:47 +0200
Subject: [PATCH] FIX: buffer overflow on MCI-partition enumeration

Quoted 6 lines

Memory for up to 6 partitions is reserved, however there can be up to 7 partitions on an mci storage (e.g. emmc). A user partition two boot partitions and up to four general pupose partitions.

---
 include/mci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Your patch lacks a Signed-off-by: line. Please respond with such a line.

Otherwise ok, thanks for fixing this. I additionally created a patch to check for the array boundaries.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

A message that is not in the archive (sent off-list or not yet received): 8f55-66daa100-d-4fcf7800@71062216

#4 lore raw
Quoted 4 lines · Florian Otte

Hey Sascha,

thank your for your reply. I am a little bit unfamiliar with the processes, so I hope this is what your are asking for.

Indeed, that's what I was asking for. All good now, patch applied, thanks

Sascha

Quoted 82 lines

Kind Regards,
Florian

Quoted 27 lines · Sascha Hauer
Quoted 19 lines · Florian Otte

Hi Everyone.

I tried to use all general purpose partitions on an eMMC storage device and ran into some trouble. In ./include/mci.h the number of partitions is limited to 6, but there might be 7 partitions. This results in a buffer overflow or access out of bound and causes a nasty bootloop when all general purpose-partitions are used. I created a simple patch and appended it to this mail.

Kind regards
fotte

[Edit]: Sorry. Clicked the wrong button to fast. Now with Attachment.

From 0bae0df23bbc4a9e98f1bcac6c6fbe0c3b21bc78 Mon Sep 17 00:00:00 2001
From: Florian Otte <[email protected]>
Date: Mon, 2 Sep 2024 11:27:47 +0200
Subject: [PATCH] FIX: buffer overflow on MCI-partition enumeration

Quoted 6 lines

Memory for up to 6 partitions is reserved, however there can be up to 7 partitions on an mci storage (e.g. emmc). A user partition two boot partitions and up to four general pupose partitions.

---
 include/mci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 12 lines

Your patch lacks a Signed-off-by: line. Please respond with such a line.

Otherwise ok, thanks for fixing this. I additionally created a patch to check for the array boundaries.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

From e5121cb2ae2a2d4294cafb93ec30abf6b7bcd0c1 Mon Sep 17 00:00:00 2001
From: Florian Otte <[email protected]>
Date: Mon, 2 Sep 2024 11:27:47 +0200
Subject: [PATCH] FIX: buffer overflow on MCI-partition enumeration

Memory for up to 6 partitions is reserved, however there can be up to 7 partitions on an mci storage (e.g. emmc). A user partition two boot partitions and up to four general pupose partitions.

---
 include/mci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/mci.h +4 -1
index 3bf1455a40..cd01e2f992 100644
@@ -600,7 +600,10 @@ struct mci_host {
 
 #define MMC_NUM_BOOT_PARTITION	2
 #define MMC_NUM_GP_PARTITION	4
-#define MMC_NUM_PHY_PARTITION	6
+#define MMC_NUM_USER_PARTITION	1
+#define MMC_NUM_PHY_PARTITION	(MMC_NUM_BOOT_PARTITION + \
+                                 MMC_NUM_GP_PARTITION + \
+                                 MMC_NUM_USER_PARTITION)
 
 struct mci_part {
 	struct block_device	blk;		/**< the blockdevice for the card */
Signature · 1 line
2.39.2
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Applied
#5 lore raw
In reply to Florian Otte
Quoted 5 lines · Florian Otte

Memory for up to 6 partitions is reserved, however there can be up to 7 partitions on an mci storage (e.g. emmc). A user partition two boot partitions and up to four general pupose partitions.

Applied, thanks!

[1/1] Bufferoverflow on eMMC partition handling
https://git.pengutronix.de/cgit/barebox/commit/?id=631f2de801e4 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>