From: Paul Durrant <xadimgnik@gmail.com>
To: "'Grzegorz Uriasz'" <gorbak25@gmail.com>, <qemu-devel@nongnu.org>
Cc: artur@puzio.waw.pl, 'Stefano Stabellini' <sstabellini@kernel.org>,
jakub@bartmin.ski, marmarek@invisiblethingslab.com,
'Anthony Perard' <anthony.perard@citrix.com>,
j.nowak26@student.uw.edu.pl, xen-devel@lists.xenproject.org
Subject: RE: [PATCH v2 1/2] Fix undefined behaviour
Date: Wed, 29 Apr 2020 09:07:22 +0100 [thread overview]
Message-ID: <002001d61dfd$37500210$a5f00630$@xen.org> (raw)
In-Reply-To: <20200429030409.9406-2-gorbak25@gmail.com>
> -----Original Message-----
> From: Grzegorz Uriasz <gorbak25@gmail.com>
> Sent: 29 April 2020 04:04
> To: qemu-devel@nongnu.org
> Cc: Grzegorz Uriasz <gorbak25@gmail.com>; marmarek@invisiblethingslab.com; artur@puzio.waw.pl;
> jakub@bartmin.ski; j.nowak26@student.uw.edu.pl; Stefano Stabellini <sstabellini@kernel.org>; Anthony
> Perard <anthony.perard@citrix.com>; Paul Durrant <paul@xen.org>; xen-devel@lists.xenproject.org
> Subject: [PATCH v2 1/2] Fix undefined behaviour
>
> This patch fixes qemu crashes when passing through an IGD device to HVM guests under XEN. The problem
> is that on almost every laptop
> reading the IGD ROM from SYSFS will fail, the reason for it is that the IGD rom is polymorphic and it
> modifies itself
> during bootup - this results in an invalid rom image - the kernel checks whether the image is valid
> and when that's not the case
> it won't allow userspace to read it. It seems that when the code was first written(xen_pt_load_rom.c)
> the kernel's back then didn't check
> whether the rom is valid and just passed the contents to userspace - because of this qemu also tries
> to repair the rom later in the code.
> When stating the rom the kernel isn't validating the rom contents so it is returning the proper size
> of the rom(32 4kb pages).
>
> This results in undefined behaviour - pci_assign_dev_load_option_rom is creating a buffer and then
> writes the size of the buffer to a pointer.
> In pci_assign_dev_load_option_rom under old kernels if the fstat would succeed then fread would also
> succeed - this means if the buffer
> is allocated the size of the buffer will be set. On newer kernels this is not the case - on all
> laptops I've tested(spanning a few
> generations of IGD) the fstat is successful and the buffer is allocated but the fread is failing - as
> the buffer is not deallocated
> the function is returning a valid pointer without setting the size of the buffer for the caller. The
> caller of pci_assign_dev_load_option_rom
> is holding the size of the buffer in an uninitialized variable and is just checking whether
> pci_assign_dev_load_option_rom returned a valid pointer.
> This later results in cpu_physical_memory_write(0xc0000, result_of_pci_assign_dev_load_option_rom,
> unitialized_variable) which
> depending on the compiler parameters, configure flags, etc... might crash qemu or might work - the xen
> 4.12 stable release with default configure
> parameters works but changing the compiler options slightly(for instance by enabling qemu debug)
> results in qemu crashing ¯\_(;-;)_/¯
>
> The only situation when the original pci_assign_dev_load_option_rom works is when the IDG is not the
I think you mean IGD
> boot gpu - this won't happen on any laptop and
> will be rare on desktops.
>
> This patch deallocates the buffer and returns NULL if reading the VBIOS fails - the caller of the
> function then properly shuts down qemu.
> The next patch in the series introduces a better method for getting the vbios so qemu does not exit
> when pci_assign_dev_load_option_rom fails -
> this is the reason I've changed error_report to warn_report as whether a failure in
> pci_assign_dev_load_option_rom is fatal
> depends on the caller.
>
> Signed-off-by: Grzegorz Uriasz <gorbak25@gmail.com>
With the typo fixed...
Reviewed-by: Paul Durrant <paul@xen.org>
next prev parent reply other threads:[~2020-04-29 8:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 3:04 [PATCH v2 0/2] Fix QEMU crashes when passing IGD to a guest VM under XEN Grzegorz Uriasz
2020-04-29 3:04 ` [PATCH v2 1/2] Fix undefined behaviour Grzegorz Uriasz
2020-04-29 8:07 ` Paul Durrant [this message]
2020-04-29 3:04 ` [PATCH v2 2/2] Improve legacy vbios handling Grzegorz Uriasz
2020-04-29 8:20 ` Paul Durrant
2020-05-04 10:36 ` Paul Durrant
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='002001d61dfd$37500210$a5f00630$@xen.org' \
--to=xadimgnik@gmail.com \
--cc=anthony.perard@citrix.com \
--cc=artur@puzio.waw.pl \
--cc=gorbak25@gmail.com \
--cc=j.nowak26@student.uw.edu.pl \
--cc=jakub@bartmin.ski \
--cc=marmarek@invisiblethingslab.com \
--cc=paul@xen.org \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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).