Skip to contentSkip to conversation

serial: clear transmit retry callback on unrealize

PATCH In review Paolo Bonzini 3 participants 4 messages Aug 18 – Aug 21

lore
Share & tools
lore
#0 lore raw

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
index 0729cd2ce9d..4339562ab00 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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

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
index 0729cd2ce9d..4339562ab00 100644
@@ -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
#2 lore raw

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

it fixes a use-after-free, so

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
index 0729cd2ce9d..4339562ab00 100644
@@ -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

#3 lore raw
In reply to Paolo Bonzini
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

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
index 0729cd2ce9d..4339562ab00 100644
@@ -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);