From nobody Tue Feb 10 07:22:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1587667601; cv=none; d=zohomail.com; s=zohoarc; b=B0JNFu610Fk2qGJ9WqL4NgB7gRNSU0MAFb80gaXDpKpTTGszpypIHKIBzgkRhmA3zikewiFoZNTJpeXGyQhtoSqppz3Hu25QWQK03mGFdw3GhWBVCfKWVnAjraEOH29pmD7qJrU0Peb+mSeyC/AhB3It1ogALJSs0WoSg/4UM4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587667601; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5FKUZYsWXSmWGJbzPGJ+rs4aPqD/ORGDojQy3boMTtI=; b=YFxqjXUy/veZbEyDPRTyvNd7w+0CXzknW0DBSDspr5+1y0pfYrrXNvStXynLGzIp85CUt9sf9XULbKZvUXysH8tmBgGCcqTsXBl9Pa41F1rzpCN4qjcqF7SEK4C2t/v4DOPxhjFU78PDMZvzn2YKFdmZ/MhyeiIhiaajcMKS8zM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1587667601883432.90689497718836; Thu, 23 Apr 2020 11:46:41 -0700 (PDT) Received: from localhost ([::1]:36966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgrw-0002IY-KY for importer@patchew.org; Thu, 23 Apr 2020 14:46:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32968) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRgmJ-0001WE-V7 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRgmI-0004g3-Fm for qemu-devel@nongnu.org; Thu, 23 Apr 2020 14:40:51 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:39752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRgmD-0004YU-RO; Thu, 23 Apr 2020 14:40:47 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id ACA512E14E5; Thu, 23 Apr 2020 21:40:42 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp1o.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id pcbgbebQ4k-efJusTgp; Thu, 23 Apr 2020 21:40:42 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:1313::1:e]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7hClKENKMK-eeXeQske; Thu, 23 Apr 2020 21:40:40 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1587667242; bh=5FKUZYsWXSmWGJbzPGJ+rs4aPqD/ORGDojQy3boMTtI=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=rMobuxyHc5x4g6A2pejKni5IaV8SRrbf+O1fcjyDAZhhN4mT+0BG5n42RjHD/JB6O juaZ878nkfrXoMoLW7Ov+8gpAkyd1AyVlc/gdysTZtrZWE8e51cBlTNRe0lLcowl7N /KTorukp4wIxxpVLM8CqAqYt2W+D5i1zZ2/Wwp4w= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [RFC PATCH v1 6/7] vhost: check vring address before calling unmap Date: Thu, 23 Apr 2020 21:39:37 +0300 Message-Id: <696f43b4883f0ce1d3695458653da885f7693692.1587667007.git.dimastep@yandex-team.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: 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=2a02:6b8:0:1619::183; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:6b8:0:1619::183 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, yc-core@yandex-team.ru, qemu-block@nongnu.org, mst@redhat.com, jasowang@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, arei.gonglei@huawei.com, stefanha@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since disconnect can happen at any time during initialization not all vring buffers (for instance used vring) can be intialized successfully. If the buffer was not initialized then vhost_memory_unmap call will lead to SIGSEGV. Add checks for the vring address value before calling unmap. Also add assert() in the vhost_memory_unmap() routine. Signed-off-by: Dima Stepanov --- hw/virtio/vhost.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ddbdc53..3ee50c4 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -314,6 +314,8 @@ static void vhost_memory_unmap(struct vhost_dev *dev, v= oid *buffer, hwaddr len, int is_write, hwaddr access_len) { + assert(buffer); + if (!vhost_dev_has_iommu(dev)) { cpu_physical_memory_unmap(buffer, len, is_write, access_len); } @@ -1132,12 +1134,25 @@ static void vhost_virtqueue_stop(struct vhost_dev *= dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), - 0, virtio_queue_get_desc_size(vdev, idx)); + /* + * Since the vhost-user disconnect can happen during initialization + * check if vring was initialized, before making unmap. + */ + if (vq->used) { + vhost_memory_unmap(dev, vq->used, + virtio_queue_get_used_size(vdev, idx), + 1, virtio_queue_get_used_size(vdev, idx)); + } + if (vq->avail) { + vhost_memory_unmap(dev, vq->avail, + virtio_queue_get_avail_size(vdev, idx), + 0, virtio_queue_get_avail_size(vdev, idx)); + } + if (vq->desc) { + vhost_memory_unmap(dev, vq->desc, + virtio_queue_get_desc_size(vdev, idx), + 0, virtio_queue_get_desc_size(vdev, idx)); + } } =20 static void vhost_eventfd_add(MemoryListener *listener, --=20 2.7.4