* [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory
@ 2026-02-26 1:16 Guangshuo Li
2026-02-26 1:38 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Guangshuo Li @ 2026-02-26 1:16 UTC (permalink / raw)
To: Greg Kroah-Hartman, Yaxing Guo, linux-kernel; +Cc: Guangshuo Li, stable
uio_pci_sva allocates struct uio_pci_sva_dev with devm_kzalloc() in
probe(), but then calls kfree(udev) both on the probe() error path
(label out_free) and again in remove().
Because devm_kzalloc() allocations are devres-managed and are freed
automatically when the device is detached (including after a failing
probe() and during driver unbind), the explicit kfree() can lead to a
double free.
If probe() fails after devm_kzalloc(), the error path frees udev and
devres cleanup will free it again when the core unwinds the partially
bound device. On normal driver removal, remove() frees udev and devres
will free it again when the device is detached.
Fix by removing the manual kfree() calls and dropping the now-unused
label.
Fixes: 3397c3cd859a2 ("uio: Add SVA support for PCI devices via uio_pci_generic_sva.c")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
v3:
- Add changelog below the --- line describing changes since v2.
v2:
- Reflow commit message to keep lines within 75 characters.
drivers/uio/uio_pci_generic_sva.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/uio/uio_pci_generic_sva.c b/drivers/uio/uio_pci_generic_sva.c
index 4a46acd994a8..152201047334 100644
--- a/drivers/uio/uio_pci_generic_sva.c
+++ b/drivers/uio/uio_pci_generic_sva.c
@@ -129,15 +129,13 @@ static int probe(struct pci_dev *pdev, const struct pci_device_id *id)
ret = devm_uio_register_device(&pdev->dev, &udev->info);
if (ret) {
dev_err(&pdev->dev, "Failed to register uio device\n");
- goto out_free;
+ goto out_disable;
}
pci_set_drvdata(pdev, udev);
return 0;
-out_free:
- kfree(udev);
out_disable:
pci_disable_device(pdev);
@@ -150,7 +148,6 @@ static void remove(struct pci_dev *pdev)
pci_release_regions(pdev);
pci_disable_device(pdev);
- kfree(udev);
}
static ssize_t pasid_show(struct device *dev,
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory
2026-02-26 1:16 [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory Guangshuo Li
@ 2026-02-26 1:38 ` Greg Kroah-Hartman
2026-02-26 10:14 ` Guangshuo Li
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-26 1:38 UTC (permalink / raw)
To: Guangshuo Li; +Cc: Yaxing Guo, linux-kernel, stable
On Thu, Feb 26, 2026 at 09:16:32AM +0800, Guangshuo Li wrote:
> uio_pci_sva allocates struct uio_pci_sva_dev with devm_kzalloc() in
> probe(), but then calls kfree(udev) both on the probe() error path
> (label out_free) and again in remove().
>
> Because devm_kzalloc() allocations are devres-managed and are freed
> automatically when the device is detached (including after a failing
> probe() and during driver unbind), the explicit kfree() can lead to a
> double free.
>
> If probe() fails after devm_kzalloc(), the error path frees udev and
> devres cleanup will free it again when the core unwinds the partially
> bound device. On normal driver removal, remove() frees udev and devres
> will free it again when the device is detached.
>
> Fix by removing the manual kfree() calls and dropping the now-unused
> label.
>
> Fixes: 3397c3cd859a2 ("uio: Add SVA support for PCI devices via uio_pci_generic_sva.c")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> v3:
> - Add changelog below the --- line describing changes since v2.
>
> v2:
> - Reflow commit message to keep lines within 75 characters.
You forgot my question of "how was this found and tested"?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory
2026-02-26 1:38 ` Greg Kroah-Hartman
@ 2026-02-26 10:14 ` Guangshuo Li
2026-02-26 14:32 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Guangshuo Li @ 2026-02-26 10:14 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Yaxing Guo, linux-kernel, stable
Hi Greg,
Thanks for the reminder.
This was found by a static analysis tool I designed. After a manual
review, I confirmed the issue and sent the fix.
Would you prefer that I include the “how it was found and tested”
information in the commit message?
Thanks,
Guangshuo
Greg Kroah-Hartman <gregkh@linuxfoundation.org> 于2026年2月26日周四 09:38写道:
>
> On Thu, Feb 26, 2026 at 09:16:32AM +0800, Guangshuo Li wrote:
> > uio_pci_sva allocates struct uio_pci_sva_dev with devm_kzalloc() in
> > probe(), but then calls kfree(udev) both on the probe() error path
> > (label out_free) and again in remove().
> >
> > Because devm_kzalloc() allocations are devres-managed and are freed
> > automatically when the device is detached (including after a failing
> > probe() and during driver unbind), the explicit kfree() can lead to a
> > double free.
> >
> > If probe() fails after devm_kzalloc(), the error path frees udev and
> > devres cleanup will free it again when the core unwinds the partially
> > bound device. On normal driver removal, remove() frees udev and devres
> > will free it again when the device is detached.
> >
> > Fix by removing the manual kfree() calls and dropping the now-unused
> > label.
> >
> > Fixes: 3397c3cd859a2 ("uio: Add SVA support for PCI devices via uio_pci_generic_sva.c")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> > ---
> > v3:
> > - Add changelog below the --- line describing changes since v2.
> >
> > v2:
> > - Reflow commit message to keep lines within 75 characters.
>
> You forgot my question of "how was this found and tested"?
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory
2026-02-26 10:14 ` Guangshuo Li
@ 2026-02-26 14:32 ` Greg Kroah-Hartman
2026-02-26 14:45 ` 郭亚星
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-26 14:32 UTC (permalink / raw)
To: Guangshuo Li; +Cc: Yaxing Guo, linux-kernel, stable
On Thu, Feb 26, 2026 at 06:14:54PM +0800, Guangshuo Li wrote:
> Hi Greg,
>
> Thanks for the reminder.
>
> This was found by a static analysis tool I designed. After a manual
> review, I confirmed the issue and sent the fix.
>
> Would you prefer that I include the “how it was found and tested”
> information in the commit message?
As per our documentation (please go read it again), it is required :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory
2026-02-26 14:32 ` Greg Kroah-Hartman
@ 2026-02-26 14:45 ` 郭亚星
0 siblings, 0 replies; 5+ messages in thread
From: 郭亚星 @ 2026-02-26 14:45 UTC (permalink / raw)
To: Greg Kroah-Hartman, Guangshuo Li; +Cc: linux-kernel, stable
On 2/26/2026 10:32 PM, Greg Kroah-Hartman wrote:
> On Thu, Feb 26, 2026 at 06:14:54PM +0800, Guangshuo Li wrote:
>> Hi Greg,
>>
>> Thanks for the reminder.
>>
>> This was found by a static analysis tool I designed. After a manual
>> review, I confirmed the issue and sent the fix.
>>
>> Would you prefer that I include the “how it was found and tested”
>> information in the commit message?
>
> As per our documentation (please go read it again), it is required :)
>
> thanks,
>
Hi Greg, Guangshuo
I’d be happy to help test this bug and the proposed patch.
(Well… to be honest, I probably should have fixed it myself earlier —
I’ve been meaning to, but got caught up with other things lately…)
Thanks for working on it!
Best regards,
Yaxing Guo
> greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-26 14:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 1:16 [PATCH v3] uio: uio_pci_generic_sva: fix double free of devm_kzalloc() memory Guangshuo Li
2026-02-26 1:38 ` Greg Kroah-Hartman
2026-02-26 10:14 ` Guangshuo Li
2026-02-26 14:32 ` Greg Kroah-Hartman
2026-02-26 14:45 ` 郭亚星
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox