From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 3/4] partitions: dos: bound extended partition chain
Date: Mon, 24 Aug 2026 13:59:57 +0200 [thread overview]
Message-ID: <20260824120022.3299742-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260824120022.3299742-1-a.fatoum@pengutronix.de>
dos_extended_partition() follows the EBR chain by reading each logical
partition's link entry (the second entry in the EBR) to locate the next
EBR. The loop is an unbounded while (1) and thus could keep running
until barebox runs out of memory.
Bound it at MAX_PARTITION to fix this.
Fixes: 57392a862d40 ("partition: allocate struct partition in parser")
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/partitions/dos.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index e5286cb6eb1f..3d9e6e67c676 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -129,11 +129,11 @@ static void dos_extended_partition(struct block_device *blk, struct dos_partitio
uint8_t *buf = xmalloc(BLOCKSIZE(blk));
uint32_t ebr_sector = partition->first_sec;
struct partition_entry *table = (struct partition_entry *)&buf[0x1be];
- unsigned partno = 4;
+ unsigned partno;
struct dos_partition *dpart;
struct partition *pentry;
- while (1) {
+ for (partno = 4; partno < MAX_PARTITION; partno++) {
int rc, i;
dev_dbg(blk->dev, "expect EBR in sector 0x%x\n", ebr_sector);
@@ -176,8 +176,6 @@ static void dos_extended_partition(struct block_device *blk, struct dos_partitio
list_add_tail(&pentry->list, &dpd->pd.partitions);
- partno++;
-
/* the second entry defines the start of the next ebr if != 0 */
if (get_unaligned_le32(&table[1].partition_start))
ebr_sector = partition->first_sec +
@@ -186,6 +184,12 @@ static void dos_extended_partition(struct block_device *blk, struct dos_partitio
break;
}
+ /* bound the EBR chain: a cyclic link would loop forever */
+ if (partno == MAX_PARTITION) {
+ dev_err(blk->dev, "too many logical partitions\n");
+ goto out;
+ }
+
out:
free(buf);
return;
--
2.47.3
next prev parent reply other threads:[~2026-08-24 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 11:59 [PATCH master 1/4] of: only replace a device tree that is actually tentative Ahmad Fatoum
2026-08-24 11:59 ` [PATCH master 2/4] tlsf: unpoison whole block in malloc_usable_size() Ahmad Fatoum
2026-08-24 11:59 ` Ahmad Fatoum [this message]
2026-08-24 11:59 ` [PATCH master 4/4] of: fdt: bound node nesting depth in __of_unflatten_dtb Ahmad Fatoum
2026-08-24 12:58 ` [PATCH master 1/4] of: only replace a device tree that is actually tentative Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824120022.3299742-3-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox