[PATCH] mci: avoid out of bounds partition access
Sascha Hauer
s.hauer at pengutronix.de
Tue Sep 3 04:34:33 PDT 2024
The mci->part array has MMC_NUM_PHY_PARTITION. Avoid creating more
partitions than we have entries in the array and print an error
message instead.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Reported-by: Florian Otte <fotte at uni-osnabrueck.de>
---
drivers/mci/mci-core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 0261f36d89..ec4a5c0749 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -651,7 +651,15 @@ static void mci_part_add(struct mci *mci, uint64_t size,
unsigned int part_cfg, char *name, char *partname, int idx, bool ro,
int area_type)
{
- struct mci_part *part = &mci->part[mci->nr_parts];
+ struct mci_part *part;
+
+ if (mci->nr_parts == MMC_NUM_PHY_PARTITION) {
+ dev_err(&mci->dev, "Out of physical partitions, cannot create partition %s\n",
+ name);
+ return;
+ }
+
+ part = &mci->part[mci->nr_parts];
part->mci = mci;
part->size = size;
--
2.39.2
More information about the barebox
mailing list