From nobody Tue Feb 10 16:22:29 2026 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=1688164652; cv=none; d=zohomail.com; s=zohoarc; b=jIZyu7gB5FjyUr6wMhP8YOLHF2oOVOZU1B+rnoum0T4JwiXVuHFYRD9j1CtrOx6IL7LYfO1pWKe8pAqxoq7O9KQxezPRZId2OvsH530p1jNO/eKVTup6PV8VeTLsL/olQxVk436py8voKOhY+Rc1nzUp/Gvdgsd10bFkd5IY7OE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688164652; 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=dEyD3iHgilQFlIPg2fAFXZ/xWzZgJDycfhkwmW5Zyx0=; b=TO6rUJk3s1zal37/DD4YCTjCywdPeO99yka82RYxBlwKjtizo8xbeUyLWGz22yAkC9YdEJ5/bZ6lxdkr4zrgk/FmCQSqQrHz6iwSXSfHEPUU3OCDQKixwxgAnFa68L4a/aU4cLCCI0c4LvQ1BfDFet2ySGwE582w7d6yJopDtP0= 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 1688164652199145.5970756680165; Fri, 30 Jun 2023 15:37:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qFMjL-00013o-Mk; Fri, 30 Jun 2023 18:36:43 -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 1qFMjK-00013f-UE for qemu-devel@nongnu.org; Fri, 30 Jun 2023 18:36:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qFMjF-0005ZA-Nk for qemu-devel@nongnu.org; Fri, 30 Jun 2023 18:36:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-jBggILtUNJ-g_D3uoDl9fw-1; Fri, 30 Jun 2023 18:36:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 089E73C0ED41 for ; Fri, 30 Jun 2023 22:36:34 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.17.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id B62602166B2D; Fri, 30 Jun 2023 22:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688164596; 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=dEyD3iHgilQFlIPg2fAFXZ/xWzZgJDycfhkwmW5Zyx0=; b=bYXOR5fM8HdPKr8xysZBB2I0KKZ8CsaForMZ/Z1KiqVqEkz7GIpafFtgy2J9PjdIWMcbzz gxd+3J1Px09bTEtm2dCfUDXME1fqM1YNXlFXy3JHPHWouapvhX+jTNLQBp05oKy9S4izGw Rusy4JhDc4tJD51vQweE6ABCVW5JEec= X-MC-Unique: jBggILtUNJ-g_D3uoDl9fw-1 From: Alex Williamson To: qemu-devel@nongnu.org Cc: Alex Williamson , clg@redhat.com Subject: [PATCH] hw/vfio/pci-quirks: Sanitize capability pointer Date: Fri, 30 Jun 2023 16:36:08 -0600 Message-Id: <20230630223608.650555-1-alex.williamson@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.133.124; envelope-from=alex.williamson@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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1688164653452100001 Content-Type: text/plain; charset="utf-8" Coverity reports a tained scalar when traversing the capabilities chain (CID 1516589). In practice I've never seen a device with a chain so broken as to cause an issue, but it's also pretty easy to sanitize. Fixes: f6b30c1984f7 ("hw/vfio/pci-quirks: Support alternate offset for GPUD= irect Cliques") Signed-off-by: Alex Williamson Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/pci-quirks.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 0ed2fcd53152..f4ff83680572 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1530,6 +1530,12 @@ const PropertyInfo qdev_prop_nv_gpudirect_clique =3D= { .set =3D set_nv_gpudirect_clique_id, }; =20 +static bool is_valid_std_cap_offset(uint8_t pos) +{ + return (pos >=3D PCI_STD_HEADER_SIZEOF && + pos <=3D (PCI_CFG_SPACE_SIZE - PCI_CAP_SIZEOF)); +} + static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; @@ -1563,7 +1569,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *v= dev, Error **errp) */ ret =3D pread(vdev->vbasedev.fd, &tmp, 1, vdev->config_offset + PCI_CAPABILITY_LIST); - if (ret !=3D 1 || !tmp) { + if (ret !=3D 1 || !is_valid_std_cap_offset(tmp)) { error_setg(errp, "NVIDIA GPUDirect Clique ID: error getting cap li= st"); return -EINVAL; } @@ -1575,7 +1581,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *v= dev, Error **errp) d4_conflict =3D true; } tmp =3D pdev->config[tmp + PCI_CAP_LIST_NEXT]; - } while (tmp); + } while (is_valid_std_cap_offset(tmp)); =20 if (!c8_conflict) { pos =3D 0xC8; --=20 2.40.1