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>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>
Subject: [PULL 16/19] Stop vhost-user sending uninitialized mmap_offsets
Date: Wed, 24 Jun 2020 19:07:10 -0400	[thread overview]
Message-ID: <20200624230609.703104-17-mst@redhat.com> (raw)
In-Reply-To: <20200624230609.703104-1-mst@redhat.com>

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

Prior to this change, the vhost_user_fill_msg_region function filled out
all elements of the VhostUserMemoryRegion struct except the mmap_offset.

This function is often called on uninitialized structs, which are then
copied into VHOST_USER_SET_MEM_TABLE and VHOST_USER_ADD/REM_MEM_REG
messages. In some cases, where the mmap_offset was not needed, it was
left uninitialized, causing QEMU to send the backend uninitialized data,
which Coverity flagged as a series of issues.

This change augments the vhost_user_fill_msg_region API, adding a
mmap_offset paramenter, forcing the caller to initialize mmap_offset.

Fixes: ece99091c2d0aeb23734289a50ef2ff4e0a08929
Fixes: f1aeb14b0809e313c74244d838645ed25e85ea63
Reported-by: Coverity (CIDs 1429802, 1429803 and 1429804)
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <1592650156-25845-1-git-send-email-raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/vhost-user.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 4d6cd4e58a..31231218dc 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -460,12 +460,14 @@ static MemoryRegion *vhost_user_get_mr_data(uint64_t addr, ram_addr_t *offset,
 }
 
 static void vhost_user_fill_msg_region(VhostUserMemoryRegion *dst,
-                                       struct vhost_memory_region *src)
+                                       struct vhost_memory_region *src,
+                                       uint64_t mmap_offset)
 {
     assert(src != NULL && dst != NULL);
     dst->userspace_addr = src->userspace_addr;
     dst->memory_size = src->memory_size;
     dst->guest_phys_addr = src->guest_phys_addr;
+    dst->mmap_offset = mmap_offset;
 }
 
 static int vhost_user_fill_set_mem_table_msg(struct vhost_user *u,
@@ -500,9 +502,8 @@ static int vhost_user_fill_set_mem_table_msg(struct vhost_user *u,
                 error_report("Failed preparing vhost-user memory table msg");
                 return -1;
             }
-            vhost_user_fill_msg_region(&region_buffer, reg);
+            vhost_user_fill_msg_region(&region_buffer, reg, offset);
             msg->payload.memory.regions[*fd_num] = region_buffer;
-            msg->payload.memory.regions[*fd_num].mmap_offset = offset;
             fds[(*fd_num)++] = fd;
         } else if (track_ramblocks) {
             u->region_rb_offset[i] = 0;
@@ -649,7 +650,7 @@ static int send_remove_regions(struct vhost_dev *dev,
 
         if (fd > 0) {
             msg->hdr.request = VHOST_USER_REM_MEM_REG;
-            vhost_user_fill_msg_region(&region_buffer, shadow_reg);
+            vhost_user_fill_msg_region(&region_buffer, shadow_reg, 0);
             msg->payload.mem_reg.region = region_buffer;
 
             if (vhost_user_write(dev, msg, &fd, 1) < 0) {
@@ -709,9 +710,8 @@ static int send_add_regions(struct vhost_dev *dev,
                 u->region_rb[reg_idx] = mr->ram_block;
             }
             msg->hdr.request = VHOST_USER_ADD_MEM_REG;
-            vhost_user_fill_msg_region(&region_buffer, reg);
+            vhost_user_fill_msg_region(&region_buffer, reg, offset);
             msg->payload.mem_reg.region = region_buffer;
-            msg->payload.mem_reg.region.mmap_offset = offset;
 
             if (vhost_user_write(dev, msg, &fd, 1) < 0) {
                 return -1;
-- 
MST



  parent reply	other threads:[~2020-06-24 23:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 23:06 [PULL 00/19] virtio,acpi,pci: fixes, cleanups, tools Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 01/19] qtest: allow DSDT acpi table changes Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 02/19] acpi: bios-tables-test: show more context on asl diffs Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 03/19] acpi: move aml builder code for floppy device Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 04/19] floppy: make isa_fdc_get_drive_max_chs static Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 05/19] floppy: move cmos_get_fd_drive_type() from pc Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 06/19] acpi: move aml builder code for i8042 (kbd+mouse) device Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 07/19] acpi: factor out fw_cfg_add_acpi_dsdt() Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 08/19] acpi: simplify build_isa_devices_aml() Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 09/19] acpi: drop serial/parallel enable bits from dsdt Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 10/19] acpi: drop build_piix4_pm() Michael S. Tsirkin
2020-06-24 23:06 ` [PULL 11/19] acpi: q35: drop _SB.PCI0.ISA.LPCD opregion Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 12/19] tests/acpi: update expected data files Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 13/19] acpi: Some build_tpm2() code reshape Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 14/19] arm/acpi: Add the TPM2.0 device under the DSDT Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 15/19] docs/specs/tpm: ACPI boot now supported for TPM/ARM Michael S. Tsirkin
2020-06-24 23:07 ` Michael S. Tsirkin [this message]
2020-06-24 23:07 ` [PULL 17/19] Rename use_acpi_pci_hotplug to more appropriate use_acpi_hotplug_bridge Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 18/19] tests/qtest/bios-tables: Only run the TPM test with CONFIG_TPM enabled Michael S. Tsirkin
2020-06-24 23:07 ` [PULL 19/19] tests: disassemble-asm.sh: generate AML in readable format Michael S. Tsirkin
2020-06-25  5:47 ` [PULL 00/19] virtio,acpi,pci: fixes, cleanups, tools Thomas Huth
2020-06-25  6:49   ` Michael S. Tsirkin
2020-06-25 20:20 ` Peter Maydell

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=20200624230609.703104-17-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    --cc=stefanha@redhat.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).