All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio_console: prevent double free in init_vqs()
@ 2026-12-03 12:51 Thomas Fourier
  2026-12-03 13:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Fourier @ 2026-12-03 12:51 UTC (permalink / raw)
  Cc: Thomas Fourier, Amit Shah, Arnd Bergmann, Greg Kroah-Hartman,
	Rusty Russell, open list:VIRTIO CONSOLE DRIVER

When init_vqs() fails, it frees portdev->in_vqs and portdev->out_vqs
but leaves both pointers set. In the probe path this does not matter,
because the probe fails. virtcons_restore() also calls init_vqs(), and
if it fails there the device stays bound to the driver. When the
device is later removed, virtcons_remove() calls remove_vqs(), which
frees both arrays a second time.

Set both pointers to NULL after freeing them in init_vqs().

Fixes: 2b8f41d84699 ("virtio: console: Add freeze and restore handlers to support S4")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/char/virtio_console.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 69046ae583ba..65662e1c602b 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1946,7 +1946,9 @@ static int init_vqs(struct ports_device *portdev)
 
 free:
 	kfree(portdev->out_vqs);
+	portdev->out_vqs = NULL;
 	kfree(portdev->in_vqs);
+	portdev->in_vqs = NULL;
 	kfree(vqs_info);
 	kfree(vqs);
 
-- 
2.53.0


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

end of thread, other threads:[~2026-12-03 13:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:51 [PATCH] virtio_console: prevent double free in init_vqs() Thomas Fourier
2026-12-03 13:03 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.