From: "Daniel P. Berrangé" <berrange@redhat.com>
To: marcandre.lureau@redhat.com
Cc: qemu-devel@nongnu.org, akihiko.odaki@gmail.com
Subject: Re: [PATCH] ui/console: fix use-after-free in qemu_console_set_cursor
Date: Thu, 27 Aug 2026 09:47:18 +0100 [thread overview]
Message-ID: <ao_5WNBxRiZycEeb@redhat.com> (raw)
In-Reply-To: <20260827070647.2872650-1-marcandre.lureau@redhat.com>
On Thu, Aug 27, 2026 at 11:06:47AM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> When the new cursor is the same object as the one already held by
> the console and the refcount is 1, cursor_unref frees it before
> cursor_ref can increment the count.
>
> Ref the incoming cursor before unreffing the old one so the
> refcount goes 1-2-1 instead of 1-0 (freed) then use-after-free.
I don't see where/how this can happen. The caller of
qemu_console_set_cursor should own its own reference
on 'cursor'. So on entry to this method, 'cursor'
should have a ref of 2 if it is the same as the
current con->cursor.
if anything the behaviour you describe sounds like a
bug in a caller not holding its own reference.
>
> This is related to 385ac97f8fad ("ui: keep current cursor with
> QemuConsole"), but could have happened earlier with VNC too.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> ui/console.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/ui/console.c b/ui/console.c
> index a8a2a247d8f4..4db8f1cb431f 100644
> --- a/ui/console.c
> +++ b/ui/console.c
> @@ -904,8 +904,9 @@ void qemu_console_set_cursor(QemuConsole *c, QEMUCursor *cursor)
> DisplayState *s = c->ds;
> DisplayChangeListener *dcl;
>
> + cursor_ref(cursor);
> cursor_unref(con->cursor);
> - con->cursor = cursor_ref(cursor);
> + con->cursor = cursor;
> QLIST_FOREACH(dcl, &s->listeners, next) {
> if (c != dcl->con) {
> continue;
> --
> 2.55.0.543.g5ebe2ebe4ea8
>
>
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-08-27 8:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 7:06 [PATCH] ui/console: fix use-after-free in qemu_console_set_cursor marcandre.lureau
2026-08-27 8:47 ` Daniel P. Berrangé [this message]
2026-08-27 9:58 ` Marc-André Lureau
2026-08-27 10:30 ` Daniel P. Berrangé
2026-08-27 10:36 ` Marc-André Lureau
2026-08-29 5:14 ` Akihiko Odaki
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=ao_5WNBxRiZycEeb@redhat.com \
--to=berrange@redhat.com \
--cc=akihiko.odaki@gmail.com \
--cc=marcandre.lureau@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.