ui/cursor: fix two races that free a cursor early
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 4 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | hw/display/qxl: hold ssd.lock while replacing ssd.cursorhw/ | +2 | 1 reply | |
| 2/2 | ui/cursor: make the cursor refcount atomicinclude/ ui/ | +20 | 1 reply |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Marc-André Lureau |
|---|---|
| 1/2 | R-b |
| 2/2 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/2] ui/cursor: fix two races that free a cursor early
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.
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(-)
Signature · 1 line
2.53.0