qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH RFC v1]display: fix heap use after free in cursor_put
       [not found] <tencent_BE1012EC266132443B1FA040EF8A60D1EC0A@qq.com>
@ 2024-04-10 13:24 ` Marc-André Lureau
  2024-04-11  1:55   ` =?gb18030?B?u9i4tKO6IFtQQVRDSCBSRkMgdjFdZGlzcGxheTogZml4IGhlYXAgdXNlIGFmdGVyIGZyZWUgaW4gY3Vyc29yX3B1dA==?= =?gb18030?B?qWdseW0=?=
  0 siblings, 1 reply; 2+ messages in thread
From: Marc-André Lureau @ 2024-04-10 13:24 UTC (permalink / raw)
  To: ゞlym; +Cc: qemu-devel, kraxel

Hi

On Wed, Apr 10, 2024 at 2:06 PM ゞlym <707242047@qq.com> wrote:
>
>

Please send the patch as inline:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#do-not-send-as-an-attachment

The patch is doing too much changes to the ssd.lock usage without
explaining in detail which race and how it solved it.

In particular, ui/spice-display.c usage seems safer before your
change, since it takes the lock on display_refresh and
display_mouse_define. It properly temporarily releases the lock before
calling the dpy_mouse_set() and dpy_cursor_define() as well.

To me, it looks like the only offender is qxl_spice_reset_cursor(),
which lacks locking before unrefing.

Could you confirm this hypothesis if you are able to reproduce the issue?

thanks



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

* =?gb18030?B?u9i4tKO6IFtQQVRDSCBSRkMgdjFdZGlzcGxheTogZml4IGhlYXAgdXNlIGFmdGVyIGZyZWUgaW4gY3Vyc29yX3B1dA==?=
  2024-04-10 13:24 ` [PATCH RFC v1]display: fix heap use after free in cursor_put Marc-André Lureau
@ 2024-04-11  1:55   ` =?gb18030?B?qWdseW0=?=
  0 siblings, 0 replies; 2+ messages in thread
From: =?gb18030?B?qWdseW0=?= @ 2024-04-11  1:55 UTC (permalink / raw)
  To: =?gb18030?B?TWFyYy1BbmRyqKYgTHVyZWF1?=
  Cc: =?gb18030?B?cWVtdS1kZXZlbA==?=, =?gb18030?B?a3JheGVs?=

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 3075 bytes --]

Hi


During the test with logging, I found that there may be a conflict between the logic of updating the refcount in vnc_dpy_cursor_define() and QXL_CURSOR_SET&nbsp;action,&nbsp; same as dpy_cursor_define() after commit&nbsp;385ac97f,&nbsp;&nbsp;and the atomic operation needs to be ensured;


The first thoughts are as follows£¬only lock cursor_unref/cursor_ref with ssd.lock£¬But&nbsp;it seems we can't get ssd.lock within dpy_cursor_define£¬so if we can't lock The top-level function&nbsp;qemu_spice_cursor_refresh_bh()£¿


--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -336,6 +336,7 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;qemu_mutex_lock(&amp;qxl-&gt;ssd.lock);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (qxl-&gt;ssd.cursor) {
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // other thread
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cursor_unref(qxl-&gt;ssd.cursor);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;qxl-&gt;ssd.cursor = c;
diff --git a/ui/console.c b/ui/console.c
index 43226c5c14..31dbd8fc6f 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -985,8 +985,10 @@ void dpy_cursor_define(QemuConsole *c, QEMUCursor *cursor)
&nbsp; &nbsp; &nbsp;DisplayState *s = c-&gt;ds;
&nbsp; &nbsp; &nbsp;DisplayChangeListener *dcl;
&nbsp;
+&nbsp; &nbsp; //lock, main thread
&nbsp; &nbsp; &nbsp;cursor_unref(con-&gt;cursor);
&nbsp; &nbsp; &nbsp;con-&gt;cursor = cursor_ref(cursor);
+&nbsp; &nbsp; //unlock
&nbsp; &nbsp; &nbsp;if (!qemu_console_is_visible(c)) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
&nbsp; &nbsp; &nbsp;}





------------------&nbsp;ԭʼÓʼþ&nbsp;------------------
·¢¼þÈË:                                                                                                                        "Marc-Andr¨¦ Lureau"                                                                                    <marcandre.lureau@redhat.com&gt;;
·¢ËÍʱ¼ä:&nbsp;2024Äê4ÔÂ10ÈÕ(ÐÇÆÚÈý) ÍíÉÏ9:24
ÊÕ¼þÈË:&nbsp;"©glym"<707242047@qq.com&gt;;
³­ËÍ:&nbsp;"qemu-devel"<qemu-devel@nongnu.org&gt;;"kraxel"<kraxel@redhat.com&gt;;
Ö÷Ìâ:&nbsp;Re: [PATCH RFC v1]display: fix heap use after free in cursor_put



Hi

On Wed, Apr 10, 2024 at 2:066§2PM ©glym <707242047@qq.com&gt; wrote:
&gt;
&gt;

Please send the patch as inline:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#do-not-send-as-an-attachment

The patch is doing too much changes to the ssd.lock usage without
explaining in detail which race and how it solved it.

In particular, ui/spice-display.c usage seems safer before your
change, since it takes the lock on display_refresh and
display_mouse_define. It properly temporarily releases the lock before
calling the dpy_mouse_set() and dpy_cursor_define() as well.

To me, it looks like the only offender is qxl_spice_reset_cursor(),
which lacks locking before unrefing.

Could you confirm this hypothesis if you are able to reproduce the issue?

thanks

[-- Attachment #2: Type: text/html, Size: 4285 bytes --]

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

end of thread, other threads:[~2024-04-11  1:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <tencent_BE1012EC266132443B1FA040EF8A60D1EC0A@qq.com>
2024-04-10 13:24 ` [PATCH RFC v1]display: fix heap use after free in cursor_put Marc-André Lureau
2024-04-11  1:55   ` =?gb18030?B?u9i4tKO6IFtQQVRDSCBSRkMgdjFdZGlzcGxheTogZml4IGhlYXAgdXNlIGFmdGVyIGZyZWUgaW4gY3Vyc29yX3B1dA==?= =?gb18030?B?qWdseW0=?=

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).