Skip to contentSkip to conversation

mfd: core: Fix double-free in mfd_remove_devices_fn()

PATCH Applied Dmitry Osipenko 3 participants 4 messages Aug 17, 2020 – Aug 24, 2020 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: core: Fix double-free in mfd_remove_devices_fn()

The pdev.mfd_cell is released by platform_device_release(), which is invoked by platform_device_unregister(). Hence mfd_remove_devices_fn() shouldn't release the cell variable. The double-free bug is reported KASAN during of MFD driver module removal.

Fixes 466a62d7642f ("mfd: core: Make a best effort attempt to match devices with the correct of_nodes")
---
 drivers/mfd/mfd-core.c | 2 --
 1 file changed, 2 deletions(-)
drivers/mfd/mfd-core.c +0 -2
index c3651f06684f..c50718e3db58 100644
@@ -370,8 +370,6 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
 	regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
 					       cell->num_parent_supplies);
 
-	kfree(cell);
-
 	platform_device_unregister(pdev);
 	return 0;
 }
Signature · 1 line
2.27.0
Applied
#1 lore raw
Quoted 10 lines · Dmitry Osipenko

The pdev.mfd_cell is released by platform_device_release(), which is invoked by platform_device_unregister(). Hence mfd_remove_devices_fn() shouldn't release the cell variable. The double-free bug is reported KASAN during of MFD driver module removal.

Fixes 466a62d7642f ("mfd: core: Make a best effort attempt to match devices with the correct of_nodes")
---
 drivers/mfd/mfd-core.c | 2 --
 1 file changed, 2 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw
In reply to Marek Szyprowski
Quoted 15 lines · Marek Szyprowski

Hi

Quoted 8 lines · Dmitry Osipenko

The pdev.mfd_cell is released by platform_device_release(), which is invoked by platform_device_unregister(). Hence mfd_remove_devices_fn() shouldn't release the cell variable. The double-free bug is reported KASAN during of MFD driver module removal.

Fixes 466a62d7642f ("mfd: core: Make a best effort attempt to match devices with the correct of_nodes")

---

I've reported that almost a week earlier and got information that it will be dropped:

Quoted 6 lines

https://lore.kernel.org/lkml/[email protected]/

https://lore.kernel.org/lkml/20200813080100.GI4354@dell/

Sadly it finally landed in v5.9-rc1. Would be nice to mention this in the revert:

That's true. The patch was taken out but the change managed to get in via another commit. I will add your Reported-by to the revert.

Quoted 20 lines
Quoted 8 lines
  drivers/mfd/mfd-core.c | 2 --
  1 file changed, 2 deletions(-)
drivers/mfd/mfd-core.c +0 -0
index c3651f06684f..c50718e3db58 100644

drivers/mfd/mfd-core.c static int mfd_remove_devices_fn(struct device *dev, void *data) · line 375

Quoted 8 lines
drivers/mfd/mfd-core.c +0 -2
@@ -370,8 +370,6 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
  	regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
  					       cell->num_parent_supplies);
 
-	kfree(cell);
-
  	platform_device_unregister(pdev);
  	return 0;
  }

Best regards

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#2 lore raw
In reply to Dmitry Osipenko

Hi

Quoted 8 lines · Dmitry Osipenko

The pdev.mfd_cell is released by platform_device_release(), which is invoked by platform_device_unregister(). Hence mfd_remove_devices_fn() shouldn't release the cell variable. The double-free bug is reported KASAN during of MFD driver module removal.

Fixes 466a62d7642f ("mfd: core: Make a best effort attempt to match devices with the correct of_nodes")

---

I've reported that almost a week earlier and got information that it will be dropped:

https://lore.kernel.org/lkml/[email protected]/

https://lore.kernel.org/lkml/20200813080100.GI4354@dell/

Sadly it finally landed in v5.9-rc1. Would be nice to mention this in the revert:

Quoted 8 lines
  drivers/mfd/mfd-core.c | 2 --
  1 file changed, 2 deletions(-)
drivers/mfd/mfd-core.c +0 -0
index c3651f06684f..c50718e3db58 100644

drivers/mfd/mfd-core.c static int mfd_remove_devices_fn(struct device *dev, void *data) · line 375

Quoted 8 lines
drivers/mfd/mfd-core.c +0 -2
@@ -370,8 +370,6 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
  	regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
  					       cell->num_parent_supplies);
 
-	kfree(cell);
-
  	platform_device_unregister(pdev);
  	return 0;
  }

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland