From nobody Sat Apr 27 14:39:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nutanix.com ARC-Seal: i=1; a=rsa-sha256; t=1592869904; cv=none; d=zohomail.com; s=zohoarc; b=ggCqyyH0hNizunwsKcaUi/LPG7WS40EBbmeS2s+belXJ7QFHHMMaVwKTyKhFvGNuW34ILOb77uZGp3vTVokrKD2Cz2qoYwmMUhX6M/V16dnnJs1Rn7hfoE0lw+AJwX1HBBqsas0ctce/+K5JpGS30werFa/kgXNraVLwei4GT2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592869904; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=2EK/TVrJ0nlzGGWoinbFck4ynoGiAbDO7j4h+VsciZc=; b=LsTokOUepXxWho7sW04Cb6LGM/NobIF3nC9Y/91pEq31/CHY8UismOF2kh4M5tfWM8Xcp9TGIYnqk6R8X6zJg/hG6jhLxTkrMEbtsN/Px+TXpOtR878vY53yzVYSFvKsCmVzcpk/htwi7T9VMHW/I6AoTuna4XcbcKeQfAIuJhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592869904191190.01050956106394; Mon, 22 Jun 2020 16:51:44 -0700 (PDT) Received: from localhost ([::1]:52836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnWE2-000648-6d for importer@patchew.org; Mon, 22 Jun 2020 19:51:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnWDA-0005d5-Ps for qemu-devel@nongnu.org; Mon, 22 Jun 2020 19:50:48 -0400 Received: from o1.dev.nutanix.com ([198.21.4.205]:38838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnWD8-0004NV-Ig for qemu-devel@nongnu.org; Mon, 22 Jun 2020 19:50:48 -0400 Received: by filter0084p3las1.sendgrid.net with SMTP id filter0084p3las1-29588-5EF143D4-A1 2020-06-22 23:50:44.93605569 +0000 UTC m=+364819.999495779 Received: from localhost.localdomain.com (unknown) by ismtpd0003p1sjc2.sendgrid.net (SG) with ESMTP id xCd9yGn6RbO8znAgWlQ83w Mon, 22 Jun 2020 23:50:44.767 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.net; h=from:subject:to:cc:content-type:content-transfer-encoding; s=smtpapi; bh=2EK/TVrJ0nlzGGWoinbFck4ynoGiAbDO7j4h+VsciZc=; b=WfjsZNpbtuKM34qhGFzNCL2tmxo0tw3MtyIjfZAy8LPi8x4ZEzZqaH60axMBIJ8EYc8Z UebyV56KQ8nINbFMQ6ztBkn8tLn5B+yfLxd1NxLZHl0i0iXApmLdun+0rck0wLno2QkuC0 uki0DwcM74Yr7XEzdAp+ZWcEwALglP93I= From: Raphael Norwitz Subject: [PATCH v2] Stop vhost-user sending uninitialized mmap_offsets Date: Mon, 22 Jun 2020 23:50:44 +0000 (UTC) Message-Id: <1592650156-25845-1-git-send-email-raphael.norwitz@nutanix.com> X-Mailer: git-send-email 1.8.3.1 X-SG-EID: =?us-ascii?Q?YCLURHX+pjNDm1i7d69iKyMnQi=2FdvWah9veFa8nllaoUC0ScIWrCgiaWGu43Vg?= =?us-ascii?Q?xFdB4istXUBpN9H93OJgc8zXOvSrqN=2FYuTjgVlA?= =?us-ascii?Q?o8+DJJPqp3vSods6DHufD52bIq=2F4OhO6pTm0kt4?= =?us-ascii?Q?rlVyAlSqhXrDEKHtz4daGWq=2FDMP7aAgP0j25T3b?= =?us-ascii?Q?X5B3EyBGMNNi6iUPDEtc6pwCU7LP3tCvI9jmeCi?= =?us-ascii?Q?IB3ngse5Qip8R23X89fm87hGVBF06gpyIdU16E?= To: qemu-devel@nongnu.org, mst@redhat.com, peter.maydell@linaro.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.21.4.205; envelope-from=bounces+16159052-3d09-qemu-devel=nongnu.org@sendgrid.net; helo=o1.dev.nutanix.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/22 19:50:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, Raphael Norwitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sendgrid.net) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Raphael Norwitz Reviewed-by: Peter Maydell Reviewed-by: Stefan Hajnoczi --- 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 4d6cd4e..3123121 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, } =20 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 !=3D NULL && dst !=3D NULL); dst->userspace_addr =3D src->userspace_addr; dst->memory_size =3D src->memory_size; dst->guest_phys_addr =3D src->guest_phys_addr; + dst->mmap_offset =3D mmap_offset; } =20 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 vho= st_user *u, error_report("Failed preparing vhost-user memory table msg= "); return -1; } - vhost_user_fill_msg_region(®ion_buffer, reg); + vhost_user_fill_msg_region(®ion_buffer, reg, offset); msg->payload.memory.regions[*fd_num] =3D region_buffer; - msg->payload.memory.regions[*fd_num].mmap_offset =3D offset; fds[(*fd_num)++] =3D fd; } else if (track_ramblocks) { u->region_rb_offset[i] =3D 0; @@ -649,7 +650,7 @@ static int send_remove_regions(struct vhost_dev *dev, =20 if (fd > 0) { msg->hdr.request =3D VHOST_USER_REM_MEM_REG; - vhost_user_fill_msg_region(®ion_buffer, shadow_reg); + vhost_user_fill_msg_region(®ion_buffer, shadow_reg, 0); msg->payload.mem_reg.region =3D region_buffer; =20 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] =3D mr->ram_block; } msg->hdr.request =3D VHOST_USER_ADD_MEM_REG; - vhost_user_fill_msg_region(®ion_buffer, reg); + vhost_user_fill_msg_region(®ion_buffer, reg, offset); msg->payload.mem_reg.region =3D region_buffer; - msg->payload.mem_reg.region.mmap_offset =3D offset; =20 if (vhost_user_write(dev, msg, &fd, 1) < 0) { return -1; --=20 1.8.3.1