qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write()
Date: Mon, 13 Jul 2015 16:37:29 +0800	[thread overview]
Message-ID: <55A378C9.5050401@redhat.com> (raw)
In-Reply-To: <20150713102533-mutt-send-email-mst@redhat.com>



On 07/13/2015 03:36 PM, Michael S. Tsirkin wrote:
> On Mon, Jul 13, 2015 at 01:46:47PM +0800, Jason Wang wrote:
>> We abort on unaligned read/write in
>> virtio_address_space_read()/write() but since len in under control of
>> guest so qemu will simply crash when booting a modern guest (guest is
>> try to read when len is zero).
>> read.
> How can len be 0? Isn't this a guest bug? Or is this
> a theoretical issue?

E.g cat /sys/bus/pci/devices/0000\:00\:03.0/config
and also happen during boot (but not virtio specific code, probably pci
core or something else).

>
>> Fix this by ignoring unaligned write or
>>
>> Fixes 1e40356ce5f6ccfa0bb57104a533c62952c560ce
>> ("virtio fix cfg endian-ness for BE targets")
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
> I guess since we ignore some illegal values (e.g. > 4)
> we should just whitelist the legal ones.
> So the following looks like a slightly cleaner way to
> make this change.
>
> --->
> virtio-pci: don't crash on illegal length
>
> Some guests seem to access cfg with an illegal length value.
> It's worth fixing them but debugging is easier if
> qemu does not crash.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

I believe when we can, we should avoid guest trigger-able abort.

>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 6ca0258..c5e8cc0 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -546,7 +546,8 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
>          off = le32_to_cpu(cfg->cap.offset);
>          len = le32_to_cpu(cfg->cap.length);
>  
> -        if (len <= sizeof cfg->pci_cfg_data) {
> +        if (len == 1 || len == 2 || len == 4) {
> +            assert(len <= sizeof cfg->pci_cfg_data);
>              virtio_address_space_write(&proxy->modern_as, off,
>                                         cfg->pci_cfg_data, len);
>          }
> @@ -570,7 +571,8 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
>          off = le32_to_cpu(cfg->cap.offset);
>          len = le32_to_cpu(cfg->cap.length);
>  
> -        if (len <= sizeof cfg->pci_cfg_data) {
> +        if (len == 1 || len == 2 || len == 4) {
> +            assert(len <= sizeof cfg->pci_cfg_data);
>              virtio_address_space_read(&proxy->modern_as, off,
>                                        cfg->pci_cfg_data, len);
>          }
>

      parent reply	other threads:[~2015-07-13  8:37 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-13  5:46 [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write() Jason Wang
2015-07-13  5:46 ` [Qemu-devel] [PATCH 2/5] virtio-blk: disable scsi passthrough for 1.0 device Jason Wang
2015-07-13  7:46   ` Michael S. Tsirkin
2015-07-13  9:00     ` Jason Wang
2015-07-13  9:56       ` Kevin Wolf
2015-07-13 11:51         ` Cornelia Huck
2015-07-13 12:22           ` Michael S. Tsirkin
2015-07-13 12:30             ` Cornelia Huck
2015-07-13 12:36               ` Michael S. Tsirkin
2015-07-13 13:20                 ` Cornelia Huck
2015-07-13 14:34                   ` Paolo Bonzini
2015-07-13 14:41                     ` Cornelia Huck
2015-07-13 15:13                       ` Paolo Bonzini
2015-07-13 15:35                   ` Michael S. Tsirkin
2015-07-14 17:43                     ` Cornelia Huck
2015-07-15 10:59                       ` Michael S. Tsirkin
2015-07-15 11:46                         ` Cornelia Huck
2015-07-15 12:01                           ` Michael S. Tsirkin
2015-07-15 12:43                             ` Cornelia Huck
2015-07-15 13:16                               ` Michael S. Tsirkin
2015-07-15 13:40                                 ` Cornelia Huck
2015-07-15 14:11                                   ` Michael S. Tsirkin
2015-07-15 14:30                                     ` Cornelia Huck
2015-07-15 14:39                                       ` Michael S. Tsirkin
2015-07-15 15:38                                         ` Cornelia Huck
2015-07-15 18:51                                           ` Michael S. Tsirkin
2015-07-16 12:37                                             ` Cornelia Huck
2015-07-16 12:47                                               ` Michael S. Tsirkin
2015-07-16 17:22                                                 ` Paolo Bonzini
2015-07-17  7:18                                                   ` Cornelia Huck
2015-07-13 11:27       ` Michael S. Tsirkin
2015-07-13  5:46 ` [Qemu-devel] [PATCH 3/5] virtio-blk: set VIRTIO_F_ANY_LAYOUT when 1.0 is supported Jason Wang
2015-07-13  5:46 ` [Qemu-devel] [PATCH 4/5] Revert "virtio-net: enable virtio 1.0" Jason Wang
2015-07-13  6:16   ` Cornelia Huck
2015-07-13  7:22     ` Michael S. Tsirkin
2015-07-13  8:46       ` Cornelia Huck
2015-07-13  8:29     ` Jason Wang
2015-07-13  5:46 ` [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout Jason Wang
2015-07-13  6:50   ` Paolo Bonzini
2015-07-13  8:30     ` Jason Wang
2015-07-13  7:24   ` Michael S. Tsirkin
2015-07-13  8:22     ` Michael S. Tsirkin
2015-07-13 10:54       ` Greg Kurz
2015-07-13 11:13         ` Michael S. Tsirkin
2015-07-13  8:30     ` Jason Wang
2015-07-13  7:36 ` [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write() Michael S. Tsirkin
2015-07-13  7:53   ` Gerd Hoffmann
2015-07-13  8:00     ` Michael S. Tsirkin
2015-07-13  8:39       ` Gerd Hoffmann
2015-07-13  8:37   ` Jason Wang [this message]

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=55A378C9.5050401@redhat.com \
    --to=jasowang@redhat.com \
    --cc=mst@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).