From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, marcandre.lureau@redhat.com, pbonzini@redhat.com
Subject: Re: [PATCH 1/4] chardev: Fix QIOChannel refcount
Date: Mon, 19 May 2025 11:49:47 +0100 [thread overview]
Message-ID: <aCsMy-OnmUPC-sB7@redhat.com> (raw)
In-Reply-To: <20250515222014.4161-2-farosas@suse.de>
On Thu, May 15, 2025 at 07:20:11PM -0300, Fabiano Rosas wrote:
> The IOWatchPoll holds a reference to the iochannel while the "child"
> source (iwp->src) is removed from the context and freed. Freeing the
> source leads to the iochannel being also freed at
> qio_channel_fd_source_finalize().
>
> Later, io_watch_poll_prepare() tries to create another source with the
> same iochannel and hits an use after free:
>
> ==8241==ERROR: AddressSanitizer: heap-use-after-free on address 0x514000000040
> READ of size 8 at 0x514000000040 thread T2
> #0 0x561c2d272fcd in object_get_class ../qom/object.c:1043:17
> #1 0x561c2d338f84 in QIO_CHANNEL_GET_CLASS include/io/channel.h:29:1
> #2 0x561c2d33b26f in qio_channel_create_watch ../io/channel.c:388:30
> #3 0x561c2d2f0993 in io_watch_poll_prepare ../chardev/char-io.c:65:20
> ...
>
> 0x514000000040 is located 0 bytes inside of 392-byte region [0x514000000040,0x5140000001c8)
> freed by thread T2 here:
> #0 0x561c2d2319a5 in free
> #1 0x7fb2c0926638 in g_free
> #2 0x561c2d276507 in object_finalize ../qom/object.c:734:9
> #3 0x561c2d271d0d in object_unref ../qom/object.c:1231:9
> #4 0x561c2d32ef1d in qio_channel_fd_source_finalize ../io/channel-watch.c:95:5
> #5 0x7fb2c091d124 in g_source_unref_internal ../glib/gmain.c:2298
> #6 0x561c2d2f0b6c in io_watch_poll_prepare ../chardev/char-io.c:71:9
> ...
>
> previously allocated by thread T3 (connect) here:
> #0 0x561c2d231c69 in malloc
> #1 0x7fb2c0926518 in g_malloc
> #2 0x561c2d27246e in object_new_with_type ../qom/object.c:767:15
> #3 0x561c2d272530 in object_new ../qom/object.c:789:12
> #4 0x561c2d320193 in qio_channel_socket_new ../io/channel-socket.c:64:31
> #5 0x561c2d308013 in tcp_chr_connect_client_async ../chardev/char-socket.c:1181:12
> #6 0x561c2d3002e7 in qmp_chardev_open_socket_client ../chardev/char-socket.c:1281:9
> ...
>
> Fix the issue by incrementing the iochannel reference count when the
> IOWatchPoll takes a reference and decrementing when it is finalized.
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> chardev/char-io.c | 5 +++++
> 1 file changed, 5 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2025-05-19 10:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 22:20 [PATCH 0/4] chardev: Fix issues found by vhost-user-test Fabiano Rosas
2025-05-15 22:20 ` [PATCH 1/4] chardev: Fix QIOChannel refcount Fabiano Rosas
2025-05-19 10:49 ` Daniel P. Berrangé [this message]
2025-05-15 22:20 ` [PATCH 2/4] chardev: Don't attempt to unregister yank function more than once Fabiano Rosas
2025-05-19 10:52 ` Daniel P. Berrangé
2025-05-15 22:20 ` [PATCH 3/4] chardev: Consolidate yank registration Fabiano Rosas
2025-05-19 10:53 ` Daniel P. Berrangé
2025-05-15 22:20 ` [PATCH 4/4] chardev: Introduce a lock for hup_source Fabiano Rosas
2025-05-19 11:00 ` Daniel P. Berrangé
2025-05-19 14:21 ` Fabiano Rosas
2026-02-28 15:16 ` Peter Maydell
2026-03-04 10:34 ` Daniel P. Berrangé
2026-03-06 13:57 ` Peter Maydell
2026-03-06 14:49 ` Daniel P. Berrangé
2026-03-06 14:55 ` Peter Maydell
2025-05-24 17:50 ` [PATCH 0/4] chardev: Fix issues found by vhost-user-test Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aCsMy-OnmUPC-sB7@redhat.com \
--to=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.