* Re: [PATCH v2] virtio-mmio: fix memory leak of vm_dev
[not found] <20230907141716.88863-1-mheyne@amazon.de>
@ 2023-09-07 16:28 ` Catalin Marinas
2023-09-08 11:38 ` Maximilian Heyne
2023-09-08 1:49 ` Xuan Zhuo
1 sibling, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2023-09-07 16:28 UTC (permalink / raw)
To: Maximilian Heyne
Cc: virtualization, stable, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Wolfram Sang, linux-kernel
On Thu, Sep 07, 2023 at 02:17:16PM +0000, Maximilian Heyne wrote:
> With the recent removal of vm_dev from devres its memory is only freed
> via the callback virtio_mmio_release_dev. However, this only takes
> effect after device_add is called by register_virtio_device. Until then
> it's an unmanaged resource and must be explicitly freed on error exit.
>
> This bug was discovered and resolved using Coverity Static Analysis
> Security Testing (SAST) by Synopsys, Inc.
>
> Cc: <stable@vger.kernel.org>
> Fixes: 55c91fedd03d ("virtio-mmio: don't break lifecycle of vm_dev")
> Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Catalin Marinas <catalin.marinas@arm.com>
Thanks.
--
Catalin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] virtio-mmio: fix memory leak of vm_dev
[not found] <20230907141716.88863-1-mheyne@amazon.de>
2023-09-07 16:28 ` [PATCH v2] virtio-mmio: fix memory leak of vm_dev Catalin Marinas
@ 2023-09-08 1:49 ` Xuan Zhuo
1 sibling, 0 replies; 4+ messages in thread
From: Xuan Zhuo @ 2023-09-08 1:49 UTC (permalink / raw)
To: Maximilian Heyne
Cc: Maximilian Heyne, stable, Michael S. Tsirkin, Jason Wang,
Wolfram Sang, linux-kernel, Catalin Marinas, virtualization
On Thu, 7 Sep 2023 14:17:16 +0000, Maximilian Heyne <mheyne@amazon.de> wrote:
> With the recent removal of vm_dev from devres its memory is only freed
> via the callback virtio_mmio_release_dev. However, this only takes
> effect after device_add is called by register_virtio_device. Until then
> it's an unmanaged resource and must be explicitly freed on error exit.
>
> This bug was discovered and resolved using Coverity Static Analysis
> Security Testing (SAST) by Synopsys, Inc.
>
> Cc: <stable@vger.kernel.org>
> Fixes: 55c91fedd03d ("virtio-mmio: don't break lifecycle of vm_dev")
> Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
> drivers/virtio/virtio_mmio.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 97760f611295..59892a31cf76 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -631,14 +631,17 @@ static int virtio_mmio_probe(struct platform_device *pdev)
> spin_lock_init(&vm_dev->lock);
>
> vm_dev->base = devm_platform_ioremap_resource(pdev, 0);
> - if (IS_ERR(vm_dev->base))
> - return PTR_ERR(vm_dev->base);
> + if (IS_ERR(vm_dev->base)) {
> + rc = PTR_ERR(vm_dev->base);
> + goto free_vm_dev;
> + }
>
> /* Check magic value */
> magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
> if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
> dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
> - return -ENODEV;
> + rc = -ENODEV;
> + goto free_vm_dev;
> }
>
> /* Check device version */
> @@ -646,7 +649,8 @@ static int virtio_mmio_probe(struct platform_device *pdev)
> if (vm_dev->version < 1 || vm_dev->version > 2) {
> dev_err(&pdev->dev, "Version %ld not supported!\n",
> vm_dev->version);
> - return -ENXIO;
> + rc = -ENXIO;
> + goto free_vm_dev;
> }
>
> vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
> @@ -655,7 +659,8 @@ static int virtio_mmio_probe(struct platform_device *pdev)
> * virtio-mmio device with an ID 0 is a (dummy) placeholder
> * with no function. End probing now with no error reported.
> */
> - return -ENODEV;
> + rc = -ENODEV;
> + goto free_vm_dev;
> }
> vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
>
> @@ -685,6 +690,10 @@ static int virtio_mmio_probe(struct platform_device *pdev)
> put_device(&vm_dev->vdev.dev);
>
> return rc;
> +
> +free_vm_dev:
> + kfree(vm_dev);
> + return rc;
> }
>
> static int virtio_mmio_remove(struct platform_device *pdev)
> --
> 2.40.1
>
>
>
>
> Amazon Development Center Germany GmbH
> Krausenstr. 38
> 10117 Berlin
> Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
> Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
> Sitz: Berlin
> Ust-ID: DE 289 237 879
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] virtio-mmio: fix memory leak of vm_dev
2023-09-07 16:28 ` [PATCH v2] virtio-mmio: fix memory leak of vm_dev Catalin Marinas
@ 2023-09-08 11:38 ` Maximilian Heyne
2023-09-08 15:41 ` Catalin Marinas
0 siblings, 1 reply; 4+ messages in thread
From: Maximilian Heyne @ 2023-09-08 11:38 UTC (permalink / raw)
To: Catalin Marinas
Cc: virtualization, stable, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Wolfram Sang, linux-kernel
On Thu, Sep 07, 2023 at 05:28:25PM +0100, Catalin Marinas wrote:
> On Thu, Sep 07, 2023 at 02:17:16PM +0000, Maximilian Heyne wrote:
> > With the recent removal of vm_dev from devres its memory is only freed
> > via the callback virtio_mmio_release_dev. However, this only takes
> > effect after device_add is called by register_virtio_device. Until then
> > it's an unmanaged resource and must be explicitly freed on error exit.
> >
> > This bug was discovered and resolved using Coverity Static Analysis
> > Security Testing (SAST) by Synopsys, Inc.
> >
> > Cc: <stable@vger.kernel.org>
> > Fixes: 55c91fedd03d ("virtio-mmio: don't break lifecycle of vm_dev")
> > Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
>
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> Tested-by: Catalin Marinas <catalin.marinas@arm.com>
>
> Thanks.
>
> --
> Catalin
Who would apply this patch? Something seems to have choked my patch so it didn't
reach lore.kernel.org (message couldn't be delivered due to timeout). Should I
try to send it again?
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] virtio-mmio: fix memory leak of vm_dev
2023-09-08 11:38 ` Maximilian Heyne
@ 2023-09-08 15:41 ` Catalin Marinas
0 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2023-09-08 15:41 UTC (permalink / raw)
To: Maximilian Heyne
Cc: virtualization, stable, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Wolfram Sang, linux-kernel
On Fri, Sep 08, 2023 at 11:38:40AM +0000, Maximilian Heyne wrote:
> On Thu, Sep 07, 2023 at 05:28:25PM +0100, Catalin Marinas wrote:
> > On Thu, Sep 07, 2023 at 02:17:16PM +0000, Maximilian Heyne wrote:
> > > With the recent removal of vm_dev from devres its memory is only freed
> > > via the callback virtio_mmio_release_dev. However, this only takes
> > > effect after device_add is called by register_virtio_device. Until then
> > > it's an unmanaged resource and must be explicitly freed on error exit.
> > >
> > > This bug was discovered and resolved using Coverity Static Analysis
> > > Security Testing (SAST) by Synopsys, Inc.
> > >
> > > Cc: <stable@vger.kernel.org>
> > > Fixes: 55c91fedd03d ("virtio-mmio: don't break lifecycle of vm_dev")
> > > Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
> >
> > Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> > Tested-by: Catalin Marinas <catalin.marinas@arm.com>
>
> Who would apply this patch?
The virtio maintainers (Michael, Jason).
> Something seems to have choked my patch so it didn't
> reach lore.kernel.org (message couldn't be delivered due to timeout). Should I
> try to send it again?
You can send a v3 with the added acks. It's strange that it didn't make
it to lore. I got it as I was cc'ed but checking the archives, it's not
there.
--
Catalin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-08 15:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230907141716.88863-1-mheyne@amazon.de>
2023-09-07 16:28 ` [PATCH v2] virtio-mmio: fix memory leak of vm_dev Catalin Marinas
2023-09-08 11:38 ` Maximilian Heyne
2023-09-08 15:41 ` Catalin Marinas
2023-09-08 1:49 ` Xuan Zhuo
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).