All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ui/cursor: fix two races that free a cursor early
@ 2026-09-03 19:26 Denis V. Lunev
  2026-09-03 19:26 ` [PATCH 1/2] hw/display/qxl: hold ssd.lock while replacing ssd.cursor Denis V. Lunev
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Denis V. Lunev @ 2026-09-03 19:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, Marc-André Lureau

A guest with a qxl display can make QEMU drop more references to a
QEMUCursor than were taken. The cursor is freed while another owner
still points at it, and that owner's later cursor_unref() decrements
four bytes of a chunk the allocator has handed out again. Nothing
aborts and nothing is logged; QEMU dies later in an unrelated
allocation, in another thread.

Two defects get there, and neither fix is sufficient alone:

 - qxl_spice_reset_cursor() replaces qxl->ssd.cursor with no lock held,
   while every other writer of that field takes ssd.lock. It runs on a
   vCPU thread from QXL_IO_DESTROY_PRIMARY and, unlike qxl_hard_reset(),
   leaves the SPICE display worker running.

 - QEMUCursor.refcount is a plain int, taken and dropped from the main
   loop, the SPICE worker, ui/cocoa.m and ui/dbus-listener.c, with no
   lock common to all of them, so an increment can be lost.

A qxl device starts a spice-server instance for local rendering even
with no -spice, so this is not limited to SPICE console setups.

Patch 2 also asserts that the refcount was positive. Only qxl was
exercised here, so if another display backend drops a reference it
never took, that assert turns a silent leak into an abort.

Reproducer: a libdrm program in the guest queues cursor SET commands,
then disables the CRTC so the driver issues QXL_IO_DESTROY_PRIMARY.
Unpatched QEMU dies within seconds; with the series it does not. Happy
to post it.

This is independent of the pending "ui/console: fix use-after-free in
qemu_console_set_cursor", which fixes a self-assignment ordering bug at
the same line. With that applied the crash here is unchanged.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>

Denis V. Lunev (2):
  hw/display/qxl: hold ssd.lock while replacing ssd.cursor
  ui/cursor: make the cursor refcount atomic

 hw/display/qxl.c     |  2 ++
 include/ui/console.h |  9 +++++++++
 ui/cursor.c          | 17 +++++++++++------
 3 files changed, 22 insertions(+), 6 deletions(-)

-- 
2.53.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-14  6:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03 19:26 [PATCH 0/2] ui/cursor: fix two races that free a cursor early Denis V. Lunev
2026-09-03 19:26 ` [PATCH 1/2] hw/display/qxl: hold ssd.lock while replacing ssd.cursor Denis V. Lunev
2026-09-03 19:30   ` Marc-André Lureau
2026-09-03 19:26 ` [PATCH 2/2] ui/cursor: make the cursor refcount atomic Denis V. Lunev
2026-09-03 19:29   ` Marc-André Lureau
2026-09-13 19:57 ` [PATCH 0/2] ui/cursor: fix two races that free a cursor early Denis V. Lunev
2026-09-14  6:23   ` Marc-André Lureau

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.