qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-stable@nongnu.org,
	"Peter Turschmid" <peter.turschm@nutanix.com>,
	"Raphael Norwitz" <raphael.norwitz@nutanix.com>
Subject: [PULL 4/7] Fix vhost-user buffer over-read on ram hot-unplug
Date: Mon, 27 Jul 2020 09:49:39 -0400	[thread overview]
Message-ID: <20200727134614.96376-5-mst@redhat.com> (raw)
In-Reply-To: <20200727134614.96376-1-mst@redhat.com>

From: Raphael Norwitz <raphael.norwitz@nutanix.com>

The VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS vhost-user protocol
feature introduced a shadow-table, used by the backend to dynamically
determine how a vdev's memory regions have changed since the last
vhost_user_set_mem_table() call. On hot-remove, a memmove() operation
is used to overwrite the removed shadow region descriptor(s). The size
parameter of this memmove was off by 1 such that if a VM with a backend
supporting the VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS filled it's
shadow-table (by performing the maximum number of supported hot-add
operatons) and attempted to remove the last region, Qemu would read an
out of bounds value and potentially crash.

This change fixes the memmove() bounds such that this erroneous read can
never happen.

Signed-off-by: Peter Turschmid <peter.turschm@nutanix.com>
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <1594799958-31356-1-git-send-email-raphael.norwitz@nutanix.com>
Fixes: f1aeb14b0809 ("Transmit vhost-user memory regions individually")
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 31231218dc..d7e2423762 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -672,7 +672,7 @@ static int send_remove_regions(struct vhost_dev *dev,
         memmove(&u->shadow_regions[shadow_reg_idx],
                 &u->shadow_regions[shadow_reg_idx + 1],
                 sizeof(struct vhost_memory_region) *
-                (u->num_shadow_regions - shadow_reg_idx));
+                (u->num_shadow_regions - shadow_reg_idx - 1));
         u->num_shadow_regions--;
     }
 
-- 
MST



  parent reply	other threads:[~2020-07-27 13:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 13:49 [PULL 0/7] virtio,pci: bugfixes Michael S. Tsirkin
2020-07-27 13:49 ` [PULL 1/7] virtio-mem-pci: force virtio version 1 Michael S. Tsirkin
2020-07-27 13:49 ` [PULL 2/7] hw/pci-host: save/restore pci host config register Michael S. Tsirkin
2020-07-27 13:49 ` [PULL 3/7] hw/pci-host: save/restore pci host config register for old ones Michael S. Tsirkin
2020-07-27 13:49 ` Michael S. Tsirkin [this message]
2020-07-27 13:49 ` [PULL 5/7] libvhost-user: Report descriptor index on panic Michael S. Tsirkin
2020-07-27 13:49 ` [PULL 6/7] vhost-vdpa :Fix Coverity CID 1430270 / CID 1420267 Michael S. Tsirkin
2020-07-27 13:49 ` [PULL 7/7] MAINTAINERS: Cover the firmware JSON schema Michael S. Tsirkin

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=20200727134614.96376-5-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peter.turschm@nutanix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    /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).