From nobody Thu May 16 12:52:13 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693571056; cv=none; d=zohomail.com; s=zohoarc; b=H1/E6Lc1+LwXdW0XjCTHDPyH/XpRSdWe+bRWAGTrQQni2jyXbfFHo/hdcsqyeB5UWw8VVWtUrQp2fQa0nELv488P5gnNVbgJKeNTZizqGzbwCpl/JPZpMY2AT4rUVm03BMlQ1CHr94cpmk8oQ7s2TPtx9l8VySiRvgi3vM3p3DY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693571056; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=HpDc0+/XXYKR0NtBCGyPSKv38OLN2dLh3nwWw6zVwyY=; b=hkdrtK7pGNG4RHxvvxSOtXL3ye48rKSS8sblOoZg/FRoh0FNNj8HrSwX/YMg4sQZhygCVswWillk3RMUMXeEwaKAgYW/v/n8JOgYlUK79agn7KABB9sjjI01+QZpEDpW/AQBDGW2uHIkKkincE3OvMMNWyKVQt5LZcmpEkFUYk4= 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693571056855193.55799868250358; Fri, 1 Sep 2023 05:24:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qc3BU-0000V3-MB; Fri, 01 Sep 2023 08:23:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qc3BS-0000Oy-2O for qemu-devel@nongnu.org; Fri, 01 Sep 2023 08:23:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qc3BP-0007EY-TO for qemu-devel@nongnu.org; Fri, 01 Sep 2023 08:23:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-Tipm5M9hPUCj-yyxNcSqjA-1; Fri, 01 Sep 2023 08:23:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94A7D1817908 for ; Fri, 1 Sep 2023 12:23:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 973CD83B7A; Fri, 1 Sep 2023 12:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693571007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HpDc0+/XXYKR0NtBCGyPSKv38OLN2dLh3nwWw6zVwyY=; b=G4VAsVqQ7mk9HF7ZjhYuI0LshhlagzFxAQZAHq/R707T2zfITZ//tjIEH7pHt8knTpg63v Klp0oHnrBOpp0t9zAvlRCzN0AtwvfHHz0mZSj6rDKXDQpQb8VZrYdHQl3w9a+KmMckDT+3 d0bdt1fTrQWEcsV65N/kMD3YkZK3Yoc= X-MC-Unique: Tipm5M9hPUCj-yyxNcSqjA-1 From: Albert Esteve To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Albert Esteve Subject: [PATCH] hw/virtio/vhost: check nvqs at dev_start Date: Fri, 1 Sep 2023 14:23:23 +0200 Message-ID: <20230901122323.66183-1-aesteve@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=170.10.129.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693571057728100001 Content-Type: text/plain; charset="utf-8" While this is not expected to happen, it could still be that a vhost_dev did not set its nvqs member. Since `vhost_dev_start` access the device's vqs array later without checking its size, it would cause a Segmentation fault when nvqs is 0. To avoid this `rare` case and made the code safer, add a clause that ensures nvqs has been set, and warn the user if it has not. Signed-off-by: Albert Esteve --- hw/virtio/vhost.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e2f6ffb446..78805fe5b7 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1935,6 +1935,11 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev, bool vrings) hdev->started =3D true; hdev->vdev =3D vdev; =20 + if (!hdev->nvqs) { + error_report("device nvqs not set"); + goto fail_nvqs; + } + r =3D vhost_dev_set_features(hdev, hdev->log_enabled); if (r < 0) { goto fail_features; @@ -2028,6 +2033,7 @@ fail_mem: if (vhost_dev_has_iommu(hdev)) { memory_listener_unregister(&hdev->iommu_listener); } +fail_nvqs: fail_features: vdev->vhost_started =3D false; hdev->started =3D false; --=20 2.41.0