Skip to contentSkip to conversation

PCI: endpoint: Fix a double free in __pci_epc_create()

PATCH In review Ma Ke 2 participants 3 messages Jan 7, 2025 – Feb 20, 2025

Subsystems (3)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 PCI: endpoint: Fix a double free in __pci_epc_create()

The put_device(&epc->dev) call will trigger pci_epc_release() which frees "epc" so the kfree(epc) on the next line is a double free.

Found by code review.

Fixes 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")
---
 drivers/pci/endpoint/pci-epc-core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/endpoint/pci-epc-core.c +0 -1
index 46c9a5c3ca14..652350f054cf 100644
@@ -818,7 +818,6 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
 
 put_dev:
 	put_device(&epc->dev);
-	kfree(epc);
 
 err_ret:
 	return ERR_PTR(ret);
Signature · 1 line
2.25.1
#1 lore raw

Hello,

Quoted 8 lines

The put_device(&epc->dev) call will trigger pci_epc_release() which frees "epc" so the kfree(epc) on the next line is a double free.

Found by code review.

Fixes 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")

Which kernel release did you review? I don't see this kfree() when looking at the current code base per:

https://elixir.bootlin.com/linux/v6.13-rc1/source/drivers/pci/endpoint/pci-epc-core.c#L956-L1020

Krzysztof

#2 lore raw

Hello,

Quoted 4 lines
Quoted 4 lines

The put_device(&epc->dev) call will trigger pci_epc_release() which frees "epc" so the kfree(epc) on the next line is a double free.

Found by code review.

[...]

Quoted 4 lines

Which kernel release did you review? I don't see this kfree() when looking at the current code base per:

https://elixir.bootlin.com/linux/v6.13-rc1/source/drivers/pci/endpoint/pci-epc-core.c#L956-L1020

I will answer my own question. This surplus kfree() has already been removed as part of the following commit:

c9501d268944 ("PCI: endpoint: Fix double free in __pci_epc_create()")

Nevertheless, thank you for the patch.

Krzysztof