public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hou Qiming <hqm03ster@gmail.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: valerij zaporogeci <vlrzprgts@gmail.com>,
	discuss@edk2.groups.io,  Gerd Hoffmann <kraxel@redhat.com>,
	 "Marcel Apfelbaum (GMail address)" <marcel.apfelbaum@gmail.com>,
	edk2-devel-groups-io <devel@edk2.groups.io>,
	 qemu devel list <qemu-devel@nongnu.org>
Subject: Re: [edk2-discuss] Load Option passing. Either bugs or my confusion.
Date: Thu, 16 Apr 2020 12:38:19 +0800	[thread overview]
Message-ID: <CABSdmr=u9QeNA6jy29e2pkiqnGH=xw1n+Hkkrd=AH1RRvj92Ng@mail.gmail.com> (raw)
In-Reply-To: <a972450d-8834-ae87-e4e3-5263a41d1735@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 5377 bytes --]

Very good point, I did neglect ramfb resolution changes... But there is one
important thing: it *can* cause a QEMU crash, a potentially exploitable
one, not always a guest crash. That's what motivated my heavy-handed
approach since allowing resolution change would have necessitated a good
deal of security checks. It has crashed my host *kernel* quite a few times.

The point is, while the QemuRamfbDxe driver may behave properly, nothing
prevents the guest from writing garbage or *malicious* values to the ramfb
config space. Then the values are sent to the display component without any
sanity check. For some GUI frontends, this means allocating an OpenGL
texture with guest-supplied dimensions and uploading guest memory content
to it, which means that guest memory content goes straight into a *kernel
driver*, *completely unchecked*. Some integer overflow and a lenient GPU
driver later, and the guest escapes straight to kernel.

The proper way to enable ramfb resolution change again is adding sanity
checks for ramfb resolution / pointer / etc. on the QEMU side. We have to
make sure it doesn't exceed what the host GPU driver supports. Maybe clamp
both width and height to between 1 and 2048? We also need to validate that
OpenGL texture dimension update succeeds. Note that OpenGL is not obliged
to validate anything and everything has to be checked on the QEMU side.

Qiming


On Wed, Apr 15, 2020 at 11:05 PM Laszlo Ersek <lersek@redhat.com> wrote:

> (CC Gerd, Qiming, Marcel, qemu-devel for ramfb:)
>
> On 04/14/20 23:20, valerij zaporogeci wrote:
>
> [snip]
>
> > There is a Boot Manager UI display problem, I don't know if this is
> > qemu problem, but with the ARM (both 32 and 64 bits, the qemu version
> > is 4.2.0, the OVMF is fresh), and using "ramfb" device, the Boot
> > Manager has troubles with drawing - it's interfase looks entirely
> > broken, like this (I'll try to attach the screenshot). UEFI shell
> > doesn't have this problem. switching to "serial" (which is -serial vc)
> > doesn't produce it too. Only when ramfb is chosen, the Boot Manager UI
> > gets smeared. But it takes input and presumable works properly, except
> > displaying things. qemu writes these messages in the command prompt:
> > ramfb_fw_cfg_write: 640x480 @ 0x4bd00000
> > ramfb_fw_cfg_write: resolution locked, change rejected
> > ramfb_fw_cfg_write: 800x600 @ 0x4bd00000
> > ramfb_fw_cfg_write: resolution locked, change rejected
>
> Gerd contributed the OVMF QemuRamfbDxe driver in edk2 commit
> 1d25ff51af5c ("OvmfPkg: add QemuRamfbDxe", 2018-06-14). Note the date:
> June 2018.
>
> The then-latest (released) QEMU version was v2.12.0, and v2.12.1 /
> v3.0.0 were in the making.
>
> At that time, the resolution change definitely worked -- note my
> "Tested-by" on the edk2 commit message.
>
>
> Running "git blame" on the QEMU source, I now find commit a9e0cb67b7f4
> ("hw/display/ramfb: lock guest resolution after it's set", 2019-05-24).
>
> Again, note the date: May 2019 (and this commit was released with QEMU
> v4.1.0).
>
> So I would say that the symptom you see is a QEMU v4.1.0 regression. The
> QemuRamfbGraphicsOutputSetMode() function in the OVMF ramfb driver
> certainly needs the QemuFwCfgWriteBytes() call to work, for changing the
> resolution.
>
>
> Now, I'm not familiar with the reasons behind QEMU commit a9e0cb67b7f4.
> It says it intends to "prevent[] a crash when the guest writes garbage
> to the configuration space (e.g. when rebooting)".
>
> But I don't understand why locking the resolution was necessary for
> preventing "a crash":
>
> (1) Registering a device reset handler in QEMU seems sufficient, so that
> QEMU forget about the currently shared RAMFB area at platform reset.
>
> (2) The crash in question is apparently not a *QEMU* crash -- which
> might otherwise justify a heavy-handed approach. Instead, it is a
> *guest* crash. See the references below:
>
> (2a)
> http://mid.mail-archive.com/CABSdmrmU7FK90Bupq_ySowcc9Uk=8nQxNLHgzvDsNYdp_QLogA@mail.gmail.com
>      https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg02299.html
>
> (2b) https://github.com/intel/gvt-linux/issues/23#issuecomment-483651476
>
> Therefore, I don't think that locking the resolution was justified!
>
> Importantly:
>
> - The QemuRamfbDxe driver allocates the framebuffer in *reserved*
> memory, therefore any well-behaving OS will *never* touch the
> framebuffer.
>
> - The QemuRamfbDxe driver allocates the framebuffer memory only once,
> namely for such a resolution that needs the largest amount of
> framebuffer memory. Therefore, framebuffer re-allocations in the guest
> driver -- and thereby guest RAM *re-mapping* in QEMU -- are *not*
> necessary, upon resolution change.
>
> The ramfb device reset handler in QEMU is justified (for unmapping /
> forgetting the previously shared RAMFB area).
>
> The resolution locking is *NOT* justified, and it breaks the OVMF
> driver. I suggest backing out the resolution locking from QEMU.
>
> Reference (2a) above indicates 'It could be a misguided attempt to
> "resize ramfb" by the guest Intel driver'. If that is the case, then
> please fix the Intel guest driver, without regressing the QEMU device
> model.
>
> I'm sad that the QEMU device model change was not regression-tested
> against the *upstream* OVMF driver (which, by then, had been upstream
> for almost a year).
>
> Laszlo
>
>

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

  reply	other threads:[~2020-04-16  4:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <18709.1586743215734342129@groups.io>
     [not found] ` <11181.1586825080096843656@groups.io>
2020-04-14 14:26   ` [edk2-discuss] Load Option passing. Either bugs or my confusion Laszlo Ersek
     [not found]     ` <5211.1586899245384995995@groups.io>
2020-04-15 15:05       ` Laszlo Ersek
2020-04-16  4:38         ` Hou Qiming [this message]
2020-04-16 14:12           ` Laszlo Ersek
2020-04-17  3:22             ` Hou Qiming
2020-04-20  9:32               ` Laszlo Ersek
2020-04-20 14:19           ` Gerd Hoffmann
2020-04-20 14:13         ` Gerd Hoffmann
2020-04-21 13:02           ` Laszlo Ersek
2020-04-22  7:42             ` Hou Qiming
2020-04-22 16:05               ` Laszlo Ersek
2020-04-23  3:15                 ` Hou Qiming

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-list 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='CABSdmr=u9QeNA6jy29e2pkiqnGH=xw1n+Hkkrd=AH1RRvj92Ng@mail.gmail.com' \
    --to=devel@edk2.groups.io \
    /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