From nobody Sun Oct 26 01:45:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516079123608655.7093120707464; Mon, 15 Jan 2018 21:05:23 -0800 (PST) Received: from localhost ([::1]:35330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebJR4-0006CI-IS for importer@patchew.org; Tue, 16 Jan 2018 00:05:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebJAo-0000ZA-Mb for qemu-devel@nongnu.org; Mon, 15 Jan 2018 23:48:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebJAn-00059Y-Sp for qemu-devel@nongnu.org; Mon, 15 Jan 2018 23:48:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebJAn-00059N-Mt; Mon, 15 Jan 2018 23:48:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAA5081DED; Tue, 16 Jan 2018 04:48:32 +0000 (UTC) Received: from redhat.com (ovpn-125-221.rdu2.redhat.com [10.10.125.221]) by smtp.corp.redhat.com (Postfix) with SMTP id 10D5A11CC1D; Tue, 16 Jan 2018 04:48:28 +0000 (UTC) Date: Tue, 16 Jan 2018 06:48:28 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1516077852-7974-34-git-send-email-mst@redhat.com> References: <1516077852-7974-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1516077852-7974-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 16 Jan 2018 04:48:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 33/33] vhost: remove assertion to prevent crash X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , qemu-stable@nongnu.org, Jay Zhou Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jay Zhou QEMU will assert on vhost-user backed virtio device hotplug if QEMU is using more RAM regions than VHOST_MEMORY_MAX_NREGIONS (for example if it were started with a lot of DIMM devices). Fix it by returning error instead of asserting and let callers of vhost_set_mem_table() handle error condition gracefully. Cc: qemu-stable@nongnu.org Signed-off-by: Igor Mammedov Signed-off-by: Jay Zhou --- hw/virtio/vhost-user.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 7930fd8..6eb9798 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -342,11 +342,14 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, &offset); fd =3D memory_region_get_fd(mr); if (fd > 0) { + if (fd_num =3D=3D VHOST_MEMORY_MAX_NREGIONS) { + error_report("Failed preparing vhost-user memory table msg= "); + return -1; + } msg.payload.memory.regions[fd_num].userspace_addr =3D reg->use= rspace_addr; msg.payload.memory.regions[fd_num].memory_size =3D reg->memor= y_size; msg.payload.memory.regions[fd_num].guest_phys_addr =3D reg->gu= est_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset =3D offset; - assert(fd_num < VHOST_MEMORY_MAX_NREGIONS); fds[fd_num++] =3D fd; } } --=20 MST