mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] virtio: fix reference leak in register_virtio_device()
@ 2024-12-17  3:54 Ma Ke
  2024-12-17  4:22 ` Viresh Kumar
  2024-12-17  5:49 ` Xuan Zhuo
  0 siblings, 2 replies; 3+ messages in thread
From: Ma Ke @ 2024-12-17  3:54 UTC (permalink / raw)
  To: mst, jasowang, xuanzhuo, eperezma, arnd, viresh.kumar
  Cc: virtualization, linux-kernel, Ma Ke, stable

When device_add(&dev->dev) failed, calling put_device() to explicitly
release dev->dev. Otherwise, it could cause double free problem.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 694a1116b405 ("virtio: Bind virtio device to device-tree node")
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 drivers/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index b9095751e43b..ac721b5597e8 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -503,6 +503,7 @@ int register_virtio_device(struct virtio_device *dev)
 
 out_of_node_put:
 	of_node_put(dev->dev.of_node);
+	put_device(&dev->dev);
 out_ida_remove:
 	ida_free(&virtio_index_ida, dev->index);
 out:
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio: fix reference leak in register_virtio_device()
  2024-12-17  3:54 [PATCH] virtio: fix reference leak in register_virtio_device() Ma Ke
@ 2024-12-17  4:22 ` Viresh Kumar
  2024-12-17  5:49 ` Xuan Zhuo
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2024-12-17  4:22 UTC (permalink / raw)
  To: Ma Ke
  Cc: mst, jasowang, xuanzhuo, eperezma, arnd, virtualization,
	linux-kernel, stable

On 17-12-24, 11:54, Ma Ke wrote:
> When device_add(&dev->dev) failed, calling put_device() to explicitly
> release dev->dev. Otherwise, it could cause double free problem.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 694a1116b405 ("virtio: Bind virtio device to device-tree node")

The fixes tag looks incorrect as the problem must be present before this commit
too.

> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  drivers/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index b9095751e43b..ac721b5597e8 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -503,6 +503,7 @@ int register_virtio_device(struct virtio_device *dev)
>  
>  out_of_node_put:
>  	of_node_put(dev->dev.of_node);
> +	put_device(&dev->dev);
>  out_ida_remove:
>  	ida_free(&virtio_index_ida, dev->index);
>  out:
> -- 
> 2.25.1

-- 
viresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] virtio: fix reference leak in register_virtio_device()
  2024-12-17  3:54 [PATCH] virtio: fix reference leak in register_virtio_device() Ma Ke
  2024-12-17  4:22 ` Viresh Kumar
@ 2024-12-17  5:49 ` Xuan Zhuo
  1 sibling, 0 replies; 3+ messages in thread
From: Xuan Zhuo @ 2024-12-17  5:49 UTC (permalink / raw)
  To: Ma Ke
  Cc: virtualization, linux-kernel, Ma Ke, stable, mst, jasowang,
	eperezma, arnd, viresh.kumar

On Tue, 17 Dec 2024 11:54:32 +0800, Ma Ke <make_ruc2021@163.com> wrote:
> When device_add(&dev->dev) failed, calling put_device() to explicitly
> release dev->dev. Otherwise, it could cause double free problem.

Who frees it doublely?
If device_add() failed, the put_device is called inside device_add(),
why we need to call it again?

Maybe you need to say more?

Thanks.


>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 694a1116b405 ("virtio: Bind virtio device to device-tree node")
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  drivers/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index b9095751e43b..ac721b5597e8 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -503,6 +503,7 @@ int register_virtio_device(struct virtio_device *dev)
>
>  out_of_node_put:
>  	of_node_put(dev->dev.of_node);
> +	put_device(&dev->dev);
>  out_ida_remove:
>  	ida_free(&virtio_index_ida, dev->index);
>  out:
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-17  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17  3:54 [PATCH] virtio: fix reference leak in register_virtio_device() Ma Ke
2024-12-17  4:22 ` Viresh Kumar
2024-12-17  5: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

all inboxes | Powered by JetHome®