Skip to contentSkip to conversation

mips: cdmm: fix use-after-free in mips_cdmm_bus_discover

PATCH In review Qinglang Miao 3 participants 3 messages Nov 20, 2020 – Nov 27, 2020

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

PATCH 1/1 mips: cdmm: fix use-after-free in mips_cdmm_bus_discover

kfree(dev) has been called inside put_device so anther kfree would cause a use-after-free bug/

Fixes 8286ae03308c ("MIPS: Add CDMM bus support")
---
 drivers/bus/mips_cdmm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/bus/mips_cdmm.c +0 -1
index 9f7ed1fcd..e43786c67 100644
@@ -561,7 +561,6 @@ static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus)
 		ret = device_register(&dev->dev);
 		if (ret) {
 			put_device(&dev->dev);
-			kfree(dev);
 		}
 	}
 }
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw

Hello Qinglang

Thanks for the patch. Good catch. Please see a tiny nitpick below.

Quoted 15 lines · Qinglang Miao

kfree(dev) has been called inside put_device so anther kfree would cause a use-after-free bug/

Fixes 8286ae03308c ("MIPS: Add CDMM bus support")
---
 drivers/bus/mips_cdmm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/bus/mips_cdmm.c +0 -0
index 9f7ed1fcd..e43786c67 100644

drivers/bus/mips_cdmm.c static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus) · line 565

Quoted 6 lines
drivers/bus/mips_cdmm.c +0 -1
@@ -561,7 +561,6 @@ static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus)
 		ret = device_register(&dev->dev);
 
 		if (ret) {
 			put_device(&dev->dev);
-			kfree(dev);
 		}

After removing kfree() from here the braces around the if clause are no more needed in accordance with the kernel coding style. Please remove them too. Then feel free to add the tag

-Sergey

Quoted 5 lines
drivers/bus/mips_cdmm.c +0 -0
 	}

}

Signature · 1 line
2.23.0
#2 lore raw
In reply to Qinglang Miao
Quoted 9 lines · Qinglang Miao

kfree(dev) has been called inside put_device so anther kfree would cause a use-after-free bug/

Fixes 8286ae03308c ("MIPS: Add CDMM bus support")
---
 drivers/bus/mips_cdmm.c | 1 -
 1 file changed, 1 deletion(-)

applied with braces removal to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]