[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH v2] hw/virtio: Fix check available index on virtio loading
From: |
Wafer |
Subject: |
RE: [PATCH v2] hw/virtio: Fix check available index on virtio loading |
Date: |
Thu, 12 Dec 2024 02:30:19 +0000 |
> -----Original Message-----
> From: Eugenio Perez Martin <eperezma@redhat.com>
> Sent: 2024年12月11日 20:45
> To: Wafer <wafer@jaguarmicro.com>
> Cc: mst@redhat.com; jasowang@redhat.com; qemu-devel@nongnu.org;
> Angus Chen <angus.chen@jaguarmicro.com>
> Subject: Re: [PATCH v2] hw/virtio: Fix check available index on virtio loading
>
> External Mail: This email originated from OUTSIDE of the organization!
> Do not click links, open attachments or provide ANY information unless you
> recognize the sender and know the content is safe.
>
>
> On Wed, Dec 11, 2024 at 1:34 PM Wafer <Wafer@jaguarmicro.com> wrote:
> >
> > From: Wafer Xie <wafer@jaguarmicro.com>
> >
> > The virtio-1.2 specification writes:
> >
> > 2.7.6 The Virtqueue Available Ring:
> > "idx field indicates where the driver would put the next descriptor
> > entry in the ring (modulo the queue size). This starts at 0, and increases"
> >
> > The idx will increase from 0 to 0xFFFF and repeat, So idx may be less
> > than last_avail_idx.
> >
>
> I don't get this change. If that happens the driver went buggy or malicious
> and the next check nheads > vring.num should mark the vq as buggy, isn't it?
>
During the migration process, let's assume a scenario where:
The depth of the avail ring is 0x10000, last_avail_index is 0xFFF0, and
avail->idx is 0xFFFFF.
At this point, the guest VM driver sends a virtio data packet, and avail->idx
is updated to 0x0.
The migration occurs, and last_avail_index is sent to the target QEMU.
During the loading process of the target QEMU, it will check both
last_avail_index and avail->idx.
In this case, last_avail_index is greater than avail->idx.
> > Fixes: 258dc7c96b ("virtio: sanity-check available index")
> >
> > Signed-off-by: Wafer Xie <wafer@jaguarmicro.com>
> >
> > --
> > Changes in v2:
> > -Modify the commit id of the fix.
> > ---
> > hw/virtio/virtio.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index
> > a26f18908e..ae7d407113 100644
> > --- a/hw/virtio/virtio.c
> > +++ b/hw/virtio/virtio.c
> > @@ -3362,7 +3362,13 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int
> version_id)
> > continue;
> > }
> >
> > - nheads = vring_avail_idx(&vdev->vq[i]) -
> > vdev->vq[i].last_avail_idx;
> > + if (vring_avail_idx(&vdev->vq[i]) >=
> > vdev->vq[i].last_avail_idx) {
> > + nheads = vring_avail_idx(&vdev->vq[i]) -
> > + vdev->vq[i].last_avail_idx;
> > + } else {
> > + nheads = UINT16_MAX - vdev->vq[i].last_avail_idx +
> > + vring_avail_idx(&vdev->vq[i]) + 1;
> > + }
> > /* Check it isn't doing strange things with descriptor
> > numbers. */
> > if (nheads > vdev->vq[i].vring.num) {
> > virtio_error(vdev, "VQ %d size 0x%x Guest index 0x%x "
> > --
> > 2.27.0
> >