qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] virtio: abort on zero config length
Date: Thu, 25 Apr 2013 17:27:19 -0500	[thread overview]
Message-ID: <878v461c1k.fsf@codemonkey.ws> (raw)
In-Reply-To: <20130425210242.GB2908@redhat.com>

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Thu, Apr 25, 2013 at 03:20:20PM -0500, Anthony Liguori wrote:
>> Jason Wang <jasowang@redhat.com> writes:
>> 
>> > In fact we don't support zero length config length for virtio device.
>> 
>> virtio-rng?
>
> It has config_len == 0?  In that case guest using virtio-rng can crash
> qemu or read qemu memory:
>
> uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
> {
>     uint8_t val;
>
>     vdev->get_config(vdev, vdev->config);
>
>     if (addr > (vdev->config_len - sizeof(val)))
>
> ^^^^^^^^^ quiz: spot a bug above if config_len is 0    :)

Then we need to fix these bugs and allocate a CVE.  virtio-rng has
shipped.  This code is also dumb.

There's no requirement that config_len is >= 4 so this would fail
equally awfully with config_len=1|2|3.

Regards,

Anthony Liguori

>
>
>         return (uint32_t)-1;
>
>     val = ldub_p(vdev->config + addr);
>     return val;
> }
>
> how about corrupting qemu memory? That too:
>
> void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
> {
>     uint8_t val = data;
>
>     if (addr > (vdev->config_len - sizeof(val)))
>         return;
>
>     stb_p(vdev->config + addr, val);
>
>     if (vdev->set_config)
>         vdev->set_config(vdev, vdev->config);
> }
>
>
>
>> > And it can lead outbound memory access. So abort on zero config length
>> > to catch the bug earlier.
>> 
>> Not sure what you mean, but virtio-rng has a zero length config space.
>> 
>> Regards,
>> 
>> Anthony Liguori
>> 
>> >
>> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>> > ---
>> >  hw/virtio/virtio.c |    7 ++-----
>> >  1 files changed, 2 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> > index 1c2282c..a6fa667 100644
>> > --- a/hw/virtio/virtio.c
>> > +++ b/hw/virtio/virtio.c
>> > @@ -923,6 +923,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,
>> >                   uint16_t device_id, size_t config_size)
>> >  {
>> >      int i;
>> > +    assert(config_size);
>> >      vdev->device_id = device_id;
>> >      vdev->status = 0;
>> >      vdev->isr = 0;
>> > @@ -938,11 +939,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,
>> >  
>> >      vdev->name = name;
>> >      vdev->config_len = config_size;
>> > -    if (vdev->config_len) {
>> > -        vdev->config = g_malloc0(config_size);
>> > -    } else {
>> > -        vdev->config = NULL;
>> > -    }
>> > +    vdev->config = g_malloc0(config_size);
>> >      vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
>> >                                                       vdev);
>> >  }
>> > -- 
>> > 1.7.1

  reply	other threads:[~2013-04-25 22:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25  7:43 [Qemu-devel] [PATCH] virtio: abort on zero config length Jason Wang
2013-04-25  8:11 ` Michael S. Tsirkin
2013-04-25 20:20 ` Anthony Liguori
2013-04-25 21:02   ` Michael S. Tsirkin
2013-04-25 22:27     ` Anthony Liguori [this message]
2013-04-26  5:06       ` Jason Wang
2013-04-26 10:32         ` Eric Blake
2013-04-26 10:33           ` Jason Wang
2013-04-26 12:31             ` Michael S. Tsirkin
2013-04-26 14:13               ` Anthony Liguori
2013-04-26 11:33           ` Laszlo Ersek

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=878v461c1k.fsf@codemonkey.ws \
    --to=aliguori@us.ibm.com \
    --cc=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).