From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] vfio: fix use-after-free in display
Date: Mon, 13 Jul 2020 16:09:15 +0200 [thread overview]
Message-ID: <7e76540f-6d3e-de4b-c26b-2806162f72cb@redhat.com> (raw)
In-Reply-To: <20200713140028.yoxn77csag7cbbfh@sirius.home.kraxel.org>
On 7/13/20 4:00 PM, Gerd Hoffmann wrote:
> On Mon, Jul 13, 2020 at 02:51:05PM +0200, Philippe Mathieu-Daudé wrote:
>> On 7/13/20 2:45 PM, Gerd Hoffmann wrote:
>>> Calling ramfb_display_update() might replace the DisplaySurface with the
>>> boot display, which in turn will free the currently active
>>> DisplaySurface.
>>>
>>> So clear our DisplaySurface pinter (dpy->region.surface pointer) to (a)
>>> avoid use-after-free and (b) force replacing the boot display with the
>>> real display when switching back.
>>>
>>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>>> ---
>>> hw/vfio/display.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/hw/vfio/display.c b/hw/vfio/display.c
>>> index a57a22674d62..342054193b3c 100644
>>> --- a/hw/vfio/display.c
>>> +++ b/hw/vfio/display.c
>>> @@ -405,6 +405,7 @@ static void vfio_display_region_update(void *opaque)
>>> if (!plane.drm_format || !plane.size) {
>>> if (dpy->ramfb) {
>>> ramfb_display_update(dpy->con, dpy->ramfb);
>>> + dpy->region.surface = NULL;
>>> }
>>> return;
>>> }
>>>
>>
>> More generic fix:
>>
>> -- >8 --
>> --- a/ui/console.c
>> +++ b/ui/console.c
>> @@ -1580,10 +1580,10 @@ void dpy_gfx_replace_surface(QemuConsole *con,
>> DisplaySurface *surface)
>> {
>> DisplayState *s = con->ds;
>> - DisplaySurface *old_surface = con->surface;
>> + QemuConsole *old_con = con;
>> DisplayChangeListener *dcl;
>>
>> - assert(old_surface != surface || surface == NULL);
>> + assert(con->surface != surface || surface == NULL);
>>
>> con->surface = surface;
>> QLIST_FOREACH(dcl, &s->listeners, next) {
>> @@ -1594,7 +1594,8 @@ void dpy_gfx_replace_surface(QemuConsole *con,
>> dcl->ops->dpy_gfx_switch(dcl, surface);
>> }
>> }
>> - qemu_free_displaysurface(old_surface);
>> + qemu_free_displaysurface(old_con->surface);
>> + old_con->surface = NULL;
>
> No.
>
> That doesn't clear VFIODisplay->region.surface, but it sets
> QemuConsole->surface to NULL no matter what got passed to
> dpy_gfx_replace_surface().
>
> Guesswork based just on the patch chunk doesn't always work,
> sometimes you have to consult the source code to see what the
> patch actually does ;)
I'm certainly not a source of trust producing perfect code :)
I appreciate being reviewed on snippets, so I can learn from my
mistakes and improve. I looked at the code (ui/console.c was not
in the previous context) but I missed to look at the other call
sites for dpy_gfx_replace_surface() and how it is used.
Thanks,
Phil.
>
> take care,
> Gerd
>
next prev parent reply other threads:[~2020-07-13 14:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-13 12:45 [PATCH] vfio: fix use-after-free in display Gerd Hoffmann
2020-07-13 12:51 ` Philippe Mathieu-Daudé
2020-07-13 14:00 ` Gerd Hoffmann
2020-07-13 14:09 ` Philippe Mathieu-Daudé [this message]
2020-07-13 20:53 ` Alex Williamson
2020-07-15 10:40 ` Gerd Hoffmann
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=7e76540f-6d3e-de4b-c26b-2806162f72cb@redhat.com \
--to=philmd@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=kraxel@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 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).