From: Stefan Hajnoczi <stefanha@redhat.com>
To: Felipe Franciosi <felipe@nutanix.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH] virtio: skip guest index check on device load
Date: Tue, 27 Oct 2020 11:30:49 +0000 [thread overview]
Message-ID: <20201027113049.GH79063@stefanha-x1.localdomain> (raw)
In-Reply-To: <20201026151328.77611-1-felipe@nutanix.com>
[-- Attachment #1: Type: text/plain, Size: 2852 bytes --]
On Mon, Oct 26, 2020 at 03:13:32PM +0000, Felipe Franciosi wrote:
> QEMU must be careful when loading device state off migration streams to
> prevent a malicious source from exploiting the emulator. Overdoing these
> checks has the side effect of allowing a guest to "pin itself" in cloud
> environments by messing with state which is entirely in its control.
>
> Similarly to what f3081539 achieved in usb_device_post_load(), this
> commit removes such a check from virtio_load(). Worth noting, the result
> of a load without this check is the same as if a guest enables a VQ with
> invalid indexes to begin with. That is, the virtual device is set in a
> broken state (by the datapath handler) and must be reset.
>
> Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
> ---
> hw/virtio/virtio.c | 12 ------------
> 1 file changed, 12 deletions(-)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 6f8f865aff..0561bdb857 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3136,8 +3136,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> RCU_READ_LOCK_GUARD();
> for (i = 0; i < num; i++) {
> if (vdev->vq[i].vring.desc) {
> - uint16_t nheads;
> -
> /*
> * VIRTIO-1 devices migrate desc, used, and avail ring addresses so
> * only the region cache needs to be set up. Legacy devices need
> @@ -3157,16 +3155,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> continue;
> }
>
> - nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;
> - /* Check it isn't doing strange things with descriptor numbers. */
> - if (nheads > vdev->vq[i].vring.num) {
> - error_report("VQ %d size 0x%x Guest index 0x%x "
> - "inconsistent with Host index 0x%x: delta 0x%x",
> - i, vdev->vq[i].vring.num,
> - vring_avail_idx(&vdev->vq[i]),
> - vdev->vq[i].last_avail_idx, nheads);
> - return -1;
> - }
Michael, the commit that introduced this check seems to have been for
debugging rather than to prevent a QEMU crash, so this removing the
check may be safe:
commit 258dc7c96bb4b7ca71d5bee811e73933310e168c
Author: Michael S. Tsirkin <mst@redhat.com>
Date: Sun Oct 17 20:23:48 2010 +0200
virtio: sanity-check available index
Checking available index upon load instead of
only when vm is running makes is easier to
debug failures.
Felipe: Did you audit the code to make sure the invalid avail_idx value
and the fields it is propagated to (e.g. shadow_avail_idx) are always
used in a safe way?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-10-27 11:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 15:13 [PATCH] virtio: skip guest index check on device load Felipe Franciosi
2020-10-27 11:30 ` Stefan Hajnoczi [this message]
2020-10-27 12:25 ` Michael S. Tsirkin
2020-10-27 12:53 ` Felipe Franciosi
2020-10-27 12:56 ` Michael S. Tsirkin
2020-10-27 13:02 ` Felipe Franciosi
2020-10-27 13:04 ` Michael S. Tsirkin
2020-10-28 11:00 ` Stefan Hajnoczi
2020-10-28 11:30 ` Michael S. Tsirkin
2020-10-28 12:44 ` Stefan Hajnoczi
2020-11-02 13:31 ` Dr. David Alan Gilbert
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=20201027113049.GH79063@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=felipe@nutanix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@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).