* [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create()
@ 2025-01-02 9:30 Ma Ke
2025-01-03 10:28 ` Markus Elfring
0 siblings, 1 reply; 5+ messages in thread
From: Ma Ke @ 2025-01-02 9:30 UTC (permalink / raw)
To: lpieralisi, kw, mani, kishon, bhelgaas, jpinto
Cc: linux-pci, linux-kernel, Ma Ke, stable
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.
Cc: stable@vger.kernel.org
Fixes: 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
drivers/pci/endpoint/pci-epc-core.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 46c9a5c3ca14..652350f054cf 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create()
2025-01-02 9:30 Ma Ke
@ 2025-01-03 10:28 ` Markus Elfring
0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2025-01-03 10:28 UTC (permalink / raw)
To: make_ruc2021, linux-pci, Bjorn Helgaas, Joao Pinto,
Kishon Vijay Abraham I, Krzysztof Wilczyński,
Lorenzo Pieralisi, Manivannan Sadhasivam
Cc: stable, LKML, kernel-janitors
> 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.
See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13-rc5#n94
> Found by code review.
Would you become interested to check how many similar control flows
can still be detected by the means of automated advanced source code analyses?
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create()
@ 2025-01-07 7:46 Ma Ke
2025-01-14 0:57 ` Krzysztof Wilczyński
0 siblings, 1 reply; 5+ messages in thread
From: Ma Ke @ 2025-01-07 7:46 UTC (permalink / raw)
To: lpieralisi, kw, mani, kishon, bhelgaas, jpinto
Cc: linux-pci, linux-kernel, Ma Ke, stable
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.
Cc: stable@vger.kernel.org
Fixes: 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/pci/endpoint/pci-epc-core.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 46c9a5c3ca14..652350f054cf 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create()
2025-01-07 7:46 [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create() Ma Ke
@ 2025-01-14 0:57 ` Krzysztof Wilczyński
2025-02-20 16:23 ` Krzysztof Wilczyński
0 siblings, 1 reply; 5+ messages in thread
From: Krzysztof Wilczyński @ 2025-01-14 0:57 UTC (permalink / raw)
To: Ma Ke
Cc: lpieralisi, mani, kishon, bhelgaas, jpinto, linux-pci,
linux-kernel, stable
Hello,
> 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.
>
> Cc: stable@vger.kernel.org
> Fixes: 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create()
2025-01-14 0:57 ` Krzysztof Wilczyński
@ 2025-02-20 16:23 ` Krzysztof Wilczyński
0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Wilczyński @ 2025-02-20 16:23 UTC (permalink / raw)
To: Ma Ke
Cc: lpieralisi, mani, kishon, bhelgaas, jpinto, linux-pci,
linux-kernel, stable
Hello,
> > 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.
[...]
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-20 16:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07 7:46 [PATCH] PCI: endpoint: Fix a double free in __pci_epc_create() Ma Ke
2025-01-14 0:57 ` Krzysztof Wilczyński
2025-02-20 16:23 ` Krzysztof Wilczyński
-- strict thread matches above, loose matches on Subject: below --
2025-01-02 9:30 Ma Ke
2025-01-03 10:28 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).