From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: qemu-devel@nongnu.org, dgilbert@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] libvhost-user: fix vu_queue_get_avail_bytes() crash
Date: Wed, 3 May 2017 08:32:48 -0400 (EDT) [thread overview]
Message-ID: <873732298.6521406.1493814768361.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <f2d892bd-9a95-a470-0490-042c98d8b0d9@amsat.org>
Hi
----- Original Message -----
> Hi Marc-André,
>
> On 05/03/2017 09:11 AM, Marc-André Lureau wrote:
> > Calling vu_queue_get_avail_bytes() when the queue doesn't yet have
> > addresses will result in the following crash:
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x000055c414112ce4 in vring_avail_idx (vq=0x55c41582fd68,
> > vq=0x55c41582fd68)
> > at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:940
> > 940 vq->shadow_avail_idx = vq->vring.avail->idx;
> > (gdb) p vq
> > $1 = (VuVirtq *) 0x55c41582fd68
> > (gdb) p vq->vring
> > $2 = {num = 0, desc = 0x0, avail = 0x0, used = 0x0, log_guest_addr = 0,
> > flags = 0}
> >
> > at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:940
> > No locals.
> > at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:960
> > num_heads = <optimized out>
> > out_bytes=out_bytes@entry=0x7fffd035d7c4,
> > max_in_bytes=max_in_bytes@entry=0,
> > max_out_bytes=max_out_bytes@entry=0) at
> > /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:1034
> >
> > Check if vring.avail != null before accessing it.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > contrib/libvhost-user/libvhost-user.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/contrib/libvhost-user/libvhost-user.c
> > b/contrib/libvhost-user/libvhost-user.c
> > index af4faad60b..f9680b6279 100644
> > --- a/contrib/libvhost-user/libvhost-user.c
> > +++ b/contrib/libvhost-user/libvhost-user.c
> > @@ -1031,6 +1031,10 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq,
> > unsigned int *in_bytes,
> > idx = vq->last_avail_idx;
> >
> > total_bufs = in_total = out_total = 0;
> > + if (!vq->vring.avail) {
> > + goto done;
> > + }
> > +
> > while ((rc = virtqueue_num_heads(dev, vq, idx)) > 0) {
> > unsigned int max, num_bufs, indirect = 0;
> > struct vring_desc *desc;
> >
>
> It seems to me safer to fix instead vring_avail_ring(), and fix
> neighbours vring_avail_flags() and vring_avail_idx() while here.
Those are internal/static functions, possibly on hot paths. So I would rather keep the check on the external/public functions only.
next prev parent reply other threads:[~2017-05-03 12:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-03 12:11 [Qemu-devel] [PATCH 1/2] libvhost-user: fix vu_queue_get_avail_bytes() crash Marc-André Lureau
2017-05-03 12:11 ` [Qemu-devel] [PATCH 2/2] libvhost-user: make vu_queue_empty() safer Marc-André Lureau
2017-05-03 12:27 ` Philippe Mathieu-Daudé
2017-05-03 12:26 ` [Qemu-devel] [PATCH 1/2] libvhost-user: fix vu_queue_get_avail_bytes() crash Philippe Mathieu-Daudé
2017-05-03 12:32 ` Marc-André Lureau [this message]
2017-05-03 12:57 ` Philippe Mathieu-Daudé
2017-05-03 14:56 ` 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=873732298.6521406.1493814768361.JavaMail.zimbra@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=dgilbert@redhat.com \
--cc=f4bug@amsat.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.