All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Li Hangjing <lihangjing@baidu.com>,
	qemu-stable@nongnu.org, "Michael S . Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH 36/36] vhost: fix vhost_log size overflow during migration
Date: Tue, 23 Jul 2019 12:01:04 -0500	[thread overview]
Message-ID: <20190723170104.4327-37-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <20190723170104.4327-1-mdroth@linux.vnet.ibm.com>

From: Li Hangjing <lihangjing@baidu.com>

When a guest which doesn't support multiqueue is migrated with a multi queues
vhost-user-blk deivce, a crash will occur like:

0 qemu_memfd_alloc (name=<value optimized out>, size=562949953421312, seals=<value optimized out>, fd=0x7f87171fe8b4, errp=0x7f87171fe8a8) at util/memfd.c:153
1 0x00007f883559d7cf in vhost_log_alloc (size=70368744177664, share=true) at hw/virtio/vhost.c:186
2 0x00007f88355a0758 in vhost_log_get (listener=0x7f8838bd7940, enable=1) at qemu-2-12/hw/virtio/vhost.c:211
3 vhost_dev_log_resize (listener=0x7f8838bd7940, enable=1) at hw/virtio/vhost.c:263
4 vhost_migration_log (listener=0x7f8838bd7940, enable=1) at hw/virtio/vhost.c:787
5 0x00007f88355463d6 in memory_global_dirty_log_start () at memory.c:2503
6 0x00007f8835550577 in ram_init_bitmaps (f=0x7f88384ce600, opaque=0x7f8836024098) at migration/ram.c:2173
7 ram_init_all (f=0x7f88384ce600, opaque=0x7f8836024098) at migration/ram.c:2192
8 ram_save_setup (f=0x7f88384ce600, opaque=0x7f8836024098) at migration/ram.c:2219
9 0x00007f88357a419d in qemu_savevm_state_setup (f=0x7f88384ce600) at migration/savevm.c:1002
10 0x00007f883579fc3e in migration_thread (opaque=0x7f8837530400) at migration/migration.c:2382
11 0x00007f8832447893 in start_thread () from /lib64/libpthread.so.0
12 0x00007f8832178bfd in clone () from /lib64/libc.so.6

This is because vhost_get_log_size() returns a overflowed vhost-log size.
In this function, it uses the uninitialized variable vqs->used_phys and
vqs->used_size to get the vhost-log size.

Signed-off-by: Li Hangjing <lihangjing@baidu.com>
Reviewed-by: Xie Yongji <xieyongji@baidu.com>
Reviewed-by: Chai Wen <chaiwen@baidu.com>
Message-Id: <20190603061524.24076-1-lihangjing@baidu.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit 240e647a14df9677b3a501f7b8b870e40aac3fd5)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/virtio/vhost.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 569c4053ea..be38b39242 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -131,6 +131,11 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev,
     }
     for (i = 0; i < dev->nvqs; ++i) {
         struct vhost_virtqueue *vq = dev->vqs + i;
+
+        if (!vq->used_phys && !vq->used_size) {
+            continue;
+        }
+
         vhost_dev_sync_region(dev, section, start_addr, end_addr, vq->used_phys,
                               range_get_last(vq->used_phys, vq->used_size));
     }
@@ -168,6 +173,11 @@ static uint64_t vhost_get_log_size(struct vhost_dev *dev)
     }
     for (i = 0; i < dev->nvqs; ++i) {
         struct vhost_virtqueue *vq = dev->vqs + i;
+
+        if (!vq->used_phys && !vq->used_size) {
+            continue;
+        }
+
         uint64_t last = vq->used_phys + vq->used_size - 1;
         log_size = MAX(log_size, last / VHOST_LOG_CHUNK + 1);
     }
-- 
2.17.1



  parent reply	other threads:[~2019-07-23 17:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 17:00 [Qemu-devel] [PATCH 00/36] Patch Round-up for stable 3.1.1, freeze on 2019-07-29 Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 01/36] i2c: Move typedef of bitbang_i2c_interface to i2c.h Michael Roth
2019-07-23 18:57   ` BALATON Zoltan
2019-07-23 19:01     ` Thomas Huth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 02/36] iotests: make 235 work on s390 (and others) Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 03/36] Changes requirement for "vsubsbs" instruction Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 04/36] pcie: set link state inactive/active after hot unplug/plug Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 05/36] pc:piix4: Update smbus I/O space after a migration Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 06/36] hw/s390x: Fix bad mask in time2tod() Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 07/36] linux-user: make pwrite64/pread64(fd, NULL, 0, offset) return 0 Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 08/36] s390x: Return specification exception for unimplemented diag 308 subcodes Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 09/36] exec.c: Don't reallocate IOMMUNotifiers that are in use Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 10/36] tpm: Make sure new locality passed to tpm_tis_prep_abort() is valid Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 11/36] tpm: Make sure the locality received from backend " Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 12/36] block: Fix invalidate_cache error path for parent activation Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 13/36] hw/rdma: another clang compilation fix Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 14/36] slirp: check sscanf result when emulating ident Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 15/36] tpm_tis: fix loop that cancels any seizure by a lower locality Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 16/36] vfio-ap: flag as compatible with balloon Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 17/36] i386: remove the new CPUID 'PCONFIG' from Icelake-Server CPU model Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 18/36] i386: remove the 'INTEL_PT' CPUID bit from named CPU models Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 19/36] json: Fix % handling when not interpolating Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 20/36] qga-win: include glib when building VSS DLL Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 21/36] configure: improve usbfs check Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 22/36] mac_oldworld: use node name instead of alias name for hd device in FWPathProvider Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 23/36] mac_newworld: " Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 24/36] qga: update docs with systemd suspend support info Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 25/36] usb-mtp: use O_NOFOLLOW and O_CLOEXEC Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 26/36] qemu-img: fix error reporting for -object Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 27/36] qcow2: Avoid COW during metadata preallocation Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 28/36] cutils: Fix size_to_str() on 32-bit platforms Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 29/36] block: Fix AioContext switch for bs->drv == NULL Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 30/36] do not call vhost_net_cleanup() on running net from char user event Michael Roth
2019-07-23 17:00 ` [Qemu-devel] [PATCH 31/36] s390x/cpumodel: ignore csske for expansion Michael Roth
2019-07-23 17:01 ` [Qemu-devel] [PATCH 32/36] megasas: fix mapped frame size Michael Roth
2019-07-23 17:01 ` [Qemu-devel] [PATCH 33/36] iotests: Filter second BLOCK_JOB_ERROR from 229 Michael Roth
2019-07-23 17:01 ` [Qemu-devel] [PATCH 34/36] block/file-posix: Unaligned O_DIRECT block-status Michael Roth
2019-07-23 17:01 ` [Qemu-devel] [PATCH 35/36] iotests: Test unaligned raw images with O_DIRECT Michael Roth
2019-07-23 17:01 ` Michael Roth [this message]
2019-07-23 17:12 ` [Qemu-devel] [PATCH 00/36] Patch Round-up for stable 3.1.1, freeze on 2019-07-29 Aleksandar Markovic
2019-07-23 18:52   ` Michael Roth
2019-07-23 18:50 ` [Qemu-devel] [Qemu-stable] " Michael Roth
2019-07-24 13:21   ` Philippe Mathieu-Daudé
2019-08-02 17:54   ` Philippe Mathieu-Daudé
2019-07-24 17:07 ` Cole Robinson
2019-07-29 20:13 ` Bruce Rogers

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=20190723170104.4327-37-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=lihangjing@baidu.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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.