From: BALATON Zoltan <balaton@eik.bme.hu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
qemu-stable <qemu-stable@nongnu.org>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Zhang Zi Ming" <1015138407@qq.com>,
qemu-ppc <qemu-ppc@nongnu.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH-for-5.0 v2] hw/display/sm501: Avoid heap overflow in sm501_2d_operation()
Date: Wed, 15 Apr 2020 19:39:14 +0200 (CEST) [thread overview]
Message-ID: <alpine.BSF.2.22.395.2004151934110.92157@zero.eik.bme.hu> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2004151923090.92157@zero.eik.bme.hu>
[-- Attachment #1: Type: text/plain, Size: 3023 bytes --]
On Wed, 15 Apr 2020, BALATON Zoltan wrote:
> On Wed, 15 Apr 2020, Peter Maydell wrote:
>> On Mon, 13 Apr 2020 at 23:01, Philippe Mathieu-Daudé <f4bug@amsat.org>
>> wrote:
>>>
>>> Zhang Zi Ming reported a heap overflow in the Drawing Engine of
>>> the SM501 companion chip model, in particular in the COPY_AREA()
>>> macro in sm501_2d_operation().
>>>
>>> Add a simple check to avoid the heap overflow.
>>
>>> diff --git a/hw/display/sm501.c b/hw/display/sm501.c
>>> index de0ab9d977..902acb3875 100644
>>> --- a/hw/display/sm501.c
>>> +++ b/hw/display/sm501.c
>>> @@ -726,6 +726,12 @@ static void sm501_2d_operation(SM501State *s)
>>> int crt = (s->dc_crt_control & SM501_DC_CRT_CONTROL_SEL) ? 1 : 0;
>>> int fb_len = get_width(s, crt) * get_height(s, crt) * get_bpp(s,
>>> crt);
>>>
>>> + if (rtl && (src_x < operation_width || src_y < operation_height)) {
>>> + qemu_log_mask(LOG_GUEST_ERROR, "sm501: Illegal RTL address (%i,
>>> %i)\n",
>>> + src_x, src_y);
>>> + return;
>>> + }
>>
>> This does fix an issue, but I have a feeling that there are
>> other possible guest register value combinations that might
>> cause us to index off one end or the other of the local_mem.
>
> That's what I've meant by it should be reimplemented eventually to fix all
> possible problems but could not do that before 5.0. Since this is existing
> bug ever since this device is first committed not patching it now is probably
> not a big deal if this is not considered a security problem. (And if it is
> then all the abort() calls are probably a problem too although less serious.)
>
>> The SM501 datasheet is entirely unhelpful on this question, but
>> my suggestion is that we should convert the code so that instead
>> of operating directly on pointers into the middle of the local_mem
>> buffer all the accesses to local_mem go via functions which mask
>> off the high bits of the index. That effectively means that the
>> behaviour if we index off the end of the graphics memory is
>> that we just wrap round to the start of it. It should be fairly
>> easy to be confident that the code isn't accessing off the end
>> of the array and it might even be what the hardware actually does
>> (since it would correspond to 'use low bits of the address to
>> index the ram, ignore high bits')...
>
> Does that make it even slower than it is already? I think it should rather be
> changed to do what I've done in ati_2d.c and call optimised functions to do
> the blit operation instead of implementing it directly. Then we'll need
As blits are common operation in several video cards, such as sm501,
cirrus and ati-vga at least maybe we could also split off some common
helpers to have one implementation of these which could be secured and
optimised once and not have to fix it in every device separately. I don't
volunteer to do that by maybe there's someone who wants to try that?
Regards,
BALATON Zoltan
next prev parent reply other threads:[~2020-04-15 17:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-13 22:01 [PATCH-for-5.0 v2] hw/display/sm501: Avoid heap overflow in sm501_2d_operation() Philippe Mathieu-Daudé
2020-04-15 15:01 ` Peter Maydell
2020-04-15 17:33 ` BALATON Zoltan
2020-04-15 17:39 ` BALATON Zoltan [this message]
2020-04-21 9:15 ` Gerd Hoffmann
2020-04-21 9:25 ` Peter Maydell
2020-04-21 11:26 ` 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=alpine.BSF.2.22.395.2004151934110.92157@zero.eik.bme.hu \
--to=balaton@eik.bme.hu \
--cc=1015138407@qq.com \
--cc=aurelien@aurel32.net \
--cc=f4bug@amsat.org \
--cc=kraxel@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-stable@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).