serial: clear transmit retry callback on unrealize
PATCH 1/1 serial: clear transmit retry callback on unrealize
The GSource is removed when resetting but remains active (and can cause use-after-free) on hot-unplug. Remove it before the character device is disconnected.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4125
--- hw/char/serial.c | 1 + 1 file changed, 1 insertion(+)
hw/char/serial.c +1 -0
@@ -936,6 +936,7 @@ static void serial_unrealize(DeviceState *dev) {SerialState *s =SERIAL (dev); +g_clear_handle_id (&s->watch_tag, g_source_remove);qemu_chr_fe_deinit (&s->chr, false);timer_free (s->modem_status_poll);
Signature · 1 line
2.55.0
Hi
Quoted 7 lines · Paolo Bonzini
The GSource is removed when resetting but remains active (and can cause use-after-free) on hot-unplug. Remove it before the character device is disconnected.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4125
Signed-off-by Paolo Bonzini <[email protected]>
it fixes a use-after-free, so
But should we care about flushing pending data?
Quoted 20 lines
--- hw/char/serial.c | 1 + 1 file changed, 1 insertion(+)hw/char/serial.c +1
-1@@ -936,6 +936,7 @@ static void serial_unrealize(DeviceState *dev) {SerialState *s =SERIAL (dev); +g_clear_handle_id (&s->watch_tag, g_source_remove);qemu_chr_fe_deinit (&s->chr, false);timer_free (s->modem_status_poll); --2.55.0
Signature · 1 line
Marc-André Lureau
Il mar 18 ago 2026, 16:42 Marc-André Lureau <[email protected]> ha scritto:
Quoted 8 lines
Hi
Quoted 5 lines · Paolo Bonzini
The GSource is removed when resetting but remains active (and can cause use-after-free) on hot-unplug. Remove it before the character device is disconnected.
Quoted 8 lines
Quoted 2 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4125
Signed-off-by Paolo Bonzini <[email protected]>it fixes a use-after-free, so
Reviewed-by Marc-André Lureau <[email protected]>But should we care about flushing pending data?
To where, :) since the transmit channel was not ready?
Paolo
Quoted 26 lines
Quoted 17 lines
--- hw/char/serial.c | 1 + 1 file changed, 1 insertion(+)hw/char/serial.c +1
-1@@ -936,6 +936,7 @@ static void serial_unrealize(DeviceState *dev) {SerialState *s =SERIAL (dev); +g_clear_handle_id (&s->watch_tag, g_source_remove);qemu_chr_fe_deinit (&s->chr, false);timer_free (s->modem_status_poll); --Quoted 3 lines
2.55.0
--
Marc-André Lureau
Quoted 6 lines · Paolo Bonzini
The GSource is removed when resetting but remains active (and can cause use-after-free) on hot-unplug. Remove it before the character device is disconnected.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4125
Signed-off-by Paolo Bonzini <[email protected]>
I'm picking this up for qemu-stable.
Please let me know if I shouldn't.
Thanks,
/mjt
Quoted 12 lines
hw/char/serial.c +1
-0@@ -936,6 +936,7 @@ static void serial_unrealize(DeviceState *dev) {SerialState *s =SERIAL (dev); +g_clear_handle_id (&s->watch_tag, g_source_remove);qemu_chr_fe_deinit (&s->chr, false);timer_free (s->modem_status_poll);