Skip to contentSkip to conversation

rapidio: potential null deref in rio_setup_device()

PATCH In review Dan Carpenter 2 participants 2 messages Aug 27, 2011 – Aug 29, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rapidio: potential null deref in rio_setup_device()

The "goto cleanup" path can dereference "rswitch" which is NULL here.

---
This is sort of embarrassing, I've patched this function before but missed this. Hopefully it's right now.

drivers/rapidio/rio-scan.c +2 -2
index 0914f49..882cef9 100644
@@ -432,7 +432,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
 		/* Assign component tag to device */
 		if (next_comptag >= 0x10000) {
 			pr_err("RIO: Component Tag Counter Overflow\n");
-			goto cleanup;
+			goto out_rdev;
 		}
 		rio_mport_write_config_32(port, destid, hopcount,
 					  RIO_COMPONENT_TAG_CSR, next_comptag);
@@ -518,7 +518,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
 cleanup:
 	if (rio_is_switch(rdev))
 		kfree(rswitch->route_table);
-
+out_rdev:
 	kfree(rdev);
 	return NULL;
 }
#1 lore raw
Quoted 20 lines · Dan Carpenter

The "goto cleanup" path can dereference "rswitch" which is NULL here.

---
This is sort of embarrassing, I've patched this function before but missed this. Hopefully it's right now.

drivers/rapidio/rio-scan.c +1 -1
index 0914f49..882cef9 100644
@@ -432,7 +432,7 @@ static struct rio_dev __devinit
 *rio_setup_device(struct rio_net *net,
 		/* Assign component tag to device */
 		if (next_comptag >= 0x10000) {
 			pr_err("RIO: Component Tag Counter Overflow\n");
-			goto cleanup;
+			goto out_rdev;
 		}
 		rio_mport_write_config_32(port, destid, hopcount,
Quoted 1 line

RIO_COMPONENT_TAG_CSR,

next_comptag);

drivers/rapidio/rio-scan.c static struct rio_dev __devinit · line 521

Quoted 5 lines
drivers/rapidio/rio-scan.c +0 -0
@@ -518,7 +518,7 @@ static struct rio_dev __devinit
 *rio_setup_device(struct rio_net *net,
 cleanup:
 	if (rio_is_switch(rdev))
 		kfree(rswitch->route_table);

Because rswitch is set not-NULL only for switch devices the check below can make things simpler:
cleanup:
if (rswitch)
kfree(rswitch->route_table);

Quoted 5 lines
drivers/rapidio/rio-scan.c +1 -1
-
+out_rdev:
 	kfree(rdev);
 	return NULL;

}