qemu-cr16/io
Eric Blake 6e03d5cdc9 qio: Unwatch before notify in QIONetListener
When changing the callback registered with QIONetListener, the code
was calling notify on the old opaque data prior to actually removing
the old GSource objects still pointing to that data.  Similarly,
during finalize, it called notify before tearing down the various
GSource objects tied to the data.

In practice, a grep of the QEMU code base found that every existing
client of QIONetListener passes in a NULL notifier (the opaque data,
if non-NULL, outlives the NetListener and so does not need cleanup
when the NetListener is torn down), so this patch has no impact.  And
even if a caller had passed in a reference-counted object with a
notifier of object_unref but kept its own reference on the data, then
the early notify would merely reduce a refcount from (say) 2 to 1, but
not free the object.  However, it is a latent bug waiting to bite any
future caller that passes in data where the notifier actually frees
the object, because the GSource could then trigger a use-after-free if
it loses the race on a last-minute client connection resulting in the
data being passed to one final use of the async callback.

Better is to delay the notify call until after all GSource that have
been given a copy of the opaque data are torn down.

CC: qemu-stable@nongnu.org
Fixes: 530473924d "io: introduce a network socket listener API", v2.12.0
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20251113011625.878876-18-eblake@redhat.com>
2025-11-13 08:21:32 -06:00
..
channel-buffer.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
channel-command.c treewide: use qemu_set_blocking instead of g_unix_set_fd_nonblocking 2025-09-19 12:46:07 +01:00
channel-file.c treewide: use qemu_set_blocking instead of g_unix_set_fd_nonblocking 2025-09-19 12:46:07 +01:00
channel-null.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
channel-socket.c io: flush zerocopy socket error queue on sendmsg failure due to ENOBUF 2025-11-03 10:45:28 +00:00
channel-tls.c io/channel: Have read/write functions take void * buffer argument 2025-11-03 10:05:40 +00:00
channel-util.c io: follow coroutine AioContext in qio_channel_yield() 2023-09-07 20:32:11 -05:00
channel-watch.c error: Kill @error_warn 2025-10-01 08:33:24 +02:00
channel-websock.c io: fix use after free in websocket handshake code 2025-10-24 13:04:31 +01:00
channel.c mem + migration pull for 10.2 2025-11-04 16:19:35 +01:00
dns-resolver.c io: Fix partial struct copy in qio_dns_resolver_lookup_sync_inet() 2025-05-22 11:24:41 +01:00
meson.build Revert "meson: Propagate gnutls dependency" 2024-07-03 18:41:26 +02:00
net-listener.c qio: Unwatch before notify in QIONetListener 2025-11-13 08:21:32 -06:00
task.c io: Fix Lesser GPL version number 2020-10-29 09:57:37 +00:00
trace-events qio: Add trace points to net_listener 2025-11-13 08:18:58 -06:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00