Skip to contentSkip to conversation

mtd/redboot: avoid null pointer deref

PATCH In review Jason A. Donenfeld 2 participants 2 messages Dec 21, 2016 – Jan 3, 2017 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd/redboot: avoid null pointer deref

By giving a bogus partition name, it's possible to trigger a null pointer dereference.

---
 drivers/mtd/redboot.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/redboot.c +4 -0
index 7623ac5fc586..53949ef80d36 100644
@@ -212,6 +212,10 @@ static int parse_redboot_partitions(struct mtd_info *master,
 
 		nrparts++;
 	}
+	if (!fl) {
+		ret = -EINVAL;
+		goto out;
+	}
 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
 	if (fl->img->flash_base) {
 		nrparts++;
Signature · 1 line
2.11.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jason A. Donenfeld

By giving a bogus partition name, it's possible to trigger a null pointer dereference.

Nice catch. It'd be great to have the condition which can be used to trigger this problem in the commit message. I presume this happens if buf[i].name[0] = 0xff for all $i, right ?

So please expand the explanation and add my Ack for V2:

Thanks

Quoted 20 lines
---
 drivers/mtd/redboot.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/redboot.c +4 -0
index 7623ac5fc586..53949ef80d36 100644
@@ -212,6 +212,10 @@ static int parse_redboot_partitions(struct mtd_info *master,
 
 		nrparts++;
 	}
+	if (!fl) {
+		ret = -EINVAL;
+		goto out;
+	}
 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
 	if (fl->img->flash_base) {
 		nrparts++;
Signature · 2 lines
Best regards,
Marek Vasut