Skip to contentSkip to conversation

MFD: prevent null pointer dereference in mfd_add_device

PATCH In review Florian Fainelli 1 participant 2 messages May 15, 2010 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MFD: prevent null pointer dereference in mfd_add_device

If a driver calls mfd_add_device with a NULL argument for the mem_base resource we will end up dereferencing it without checking for its validity here:
res[r].start = mem_base->start cell->resources[r].start; (line 53 of mfd-core.c)

This patch adds the checking on the mem_base argument and bails out accordingly if it is NULL.

---

drivers/mfd/mfd-core.c +2 -0
index 8ffbb7a..f890b27 100644
@@ -49,6 +49,8 @@ static int mfd_add_device(struct device *parent, int id,
 
 		/* Find out base to use */
 		if (cell->resources[r].flags & IORESOURCE_MEM) {
+			if (!mem_base)
+				goto fail_res;
 			res[r].parent = mem_base;
 			res[r].start = mem_base->start +
 				cell->resources[r].start;
#1 lore raw

Hi Samuel,

I just saw that your for-next branch contains the proper fix, this patch can be discarded.

Quoted 25 lines · Florian Fainelli

If a driver calls mfd_add_device with a NULL argument for the mem_base
resource we will end up dereferencing it without checking for its validity
here: res[r].start = mem_base->start cell->resources[r].start; (line 53 of mfd-core.c)

This patch adds the checking on the mem_base argument and bails out
accordingly if it is NULL.

---

drivers/mfd/mfd-core.c +2 -0
index 8ffbb7a..f890b27 100644
@@ -49,6 +49,8 @@ static int mfd_add_device(struct device *parent, int id,
 
 		/* Find out base to use */
 		if (cell->resources[r].flags & IORESOURCE_MEM) {
+			if (!mem_base)
+				goto fail_res;
 			res[r].parent = mem_base;
 			res[r].start = mem_base->start +
 				cell->resources[r].start;