From nobody Mon Nov 23 04:30:09 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793550138; cv=none; d=zohomail.com; s=zohoarc; b=U8ZUBp2QHiz7XycV4+4uMzRBBr99Jo77A14LPmXErrMS0qK+CB/OWJT0c2AfrK3l+7+cA8WPQ5qdg9IMAB2/0mi80fWc/h+qLCykLYwWiTr7ZNafI2io1if23h5LseNkqaiO6HBh6pkGVbwfbfChoKEPPilfGP+f5pDFHMKIFpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793550138; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DK90sqm1ryXJrmhR0aD7lirEgNJpvXNkoK0C5mHitLY=; b=lbK6a5Bc+YqowtVqbn/3IE7sACEI1kqwQyMh9/uJuaFQEyv7584Xa2YTWRg7/w/qq7ElAW/oJFQmEBpYpFeUMPAud1f7rTA49+iQO8UAgS29rFTJkwlu2hUyOw92OKzPMLPjj3x8HBvFF/kMeXwHGRLzNPc4B4FydDbAcncsyEE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793550138302419.23980835420866; Sun, 1 Nov 2026 08:22:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNYJY-0004at-90; Sun, 01 Nov 2026 11:21:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNYJQ-0004Wx-JZ for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:40 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNYJO-0008MR-OC for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:40 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4a599e9110eso10696205e9.0 for ; Sun, 01 Nov 2026 08:21:38 -0800 (PST) Received: from AtiePC ([2a0c:5a87:5006:4800:78cf:63bd:d449:f7bc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4aa80f04785sm283897765e9.4.2026.11.01.08.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2026 08:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793550097; x=1794154897; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DK90sqm1ryXJrmhR0aD7lirEgNJpvXNkoK0C5mHitLY=; b=QHmgzJ9E4ZW+RXCwjCFUiyeiHOH7kCPSMuzzNm57lCi4w75/4xsH+BMmIYLHZWsQxa wTlILN79p1DliuY+1Ey69UHkW46DHIMRlP9d4r2JQaDvjo/baRxFHrSr9n8C2vCVE/OX ZY8+IeF2JEWchfA2s/9HEPDmk1w/FU6d/ySOAxk90uR9/T6nALJEVBsSAp/NAOh8ryv/ RMnLhrpp1G9pRIIgu5v0ayI+DORDgENtd6wKEUFJIzkt2gcpC/2/ZeeLydf8LjNlnrFn mWgcmsYjI6xzmOdtUmyr5xpveuZeXVy2oLpQ1R/8GMX80q+eXX9YWy+gF0NONsEW0mAF ksIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793550097; x=1794154897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DK90sqm1ryXJrmhR0aD7lirEgNJpvXNkoK0C5mHitLY=; b=GprA7IESLrWN8Op4YOR79G+YIfpZe9ObKvyRfQapAZa0cccmiy16HMlF1kJby0tdMN 8zWowQjoanMZ6n6AlqTrXVaH71Tkv4drmPFZo2P8ntXnVXWCWFJOiViTaTevV2aCGCF1 37AERLGgtB16Uitrbv96SJ1xAIJfCwZN9eujPIcyDEWGKXFjyTCOC3sjlkWxyqjJZO8Q 3eDa2F40rcD26m0/BDiUzq1xv3WRLpJcQElFjApGkWl/dsnGoUjL5BhECistcTW8k1iv I+7AtzHBf4OPMLX7Zr1txd53BbfCcs3V4pWcXZuMZBMDkLgJ4lz7zd2fG1fRzoKpeQOu j/lg== X-Forwarded-Encrypted: i=1; AKwUvByX3QB/12rwupF3GMoWiYci9PaeThAjPzWhEA+wqFrAgConN7xwd8L6KZVi45Ni8ruLuqWic76Ishfk@nongnu.org X-Gm-Message-State: AFq9FYKp5lT92pbL6laWAGBOOUmDU4PA9Ob9oP4dK/UE913e2ksN+Y31 mLm4YOq0G1vnulOSWumlhHkKXZORCNFUqNCT6vZ6vbL170+V9RIazB9k X-Gm-Gg: AYBFou23yK+r0bwcOoD7W0ti/C4IAt6TQ3tk86qvj5AKUs34LQ5rh7OTP8y/oVNUOuR 1GGrlx9B9Cubmk/z9PMcPiv2MykASEr5r4nlwyGyGRr2g/ITgtf6uHZfE5K/yu2HjNUJlQbMOJA oNPU3XPx7Jl0mbXCBMG+DI9ARLvShJjGi8ctWetSrbQ4SXK8HrZgeVXIzbc+0fsk7OcnoiFmH0C dOAKluW0PakEBQBqOJYFuYvrlhJve+xO2afK8B9nubKssEtvFP5eyn2WqGeBr2bi+Sgn4jauuUZ 0jMUv3G8Nx8GSxmnMRdZaHhQRBgJTuM0B6XoSHjS/As9Q/cTxxoyLd1NcO3ggMFMncj4q300knz CE26CLP58nLd7wXAzeMaUOARo0nZi0hVjpNhF1ITUh51hB55vq6md6H5Umc0V5mGH4uzaEbHrRZ xNHYKUGiZdvrxzeG6+c/avDgBmA6VKaeXMl3M8HgjgnFugsENr/Qxmen0uZdUNHyj7aAUBbv9Mu 1T7fknv7rr2rVfIhREGaSpvX935qnJYb7btemIB02I30fF+ckVZ4vEtV9i5QMXVLtdliHxMcBEx 46BHTzokX73CXE+nn6BvotiexEKFuEofrx84qwvbaX7fJM0H0juv/ZzDcmGPhh7+Ag== X-Received: by 2002:a05:600c:34c5:b0:4a0:13d8:cd0c with SMTP id 5b1f17b1804b1-4ac16acdfe0mr174629045e9.2.1793550097311; Sun, 01 Nov 2026 08:21:37 -0800 (PST) From: Daniel Paziyski To: "Michael S. Tsirkin" Cc: Daniel Paziyski , qemu-stable@nongnu.org, qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 1/3] pci: fix null pointer dereference on pci device registration failure Date: Sun, 1 Nov 2026 17:21:29 +0100 Message-ID: <20261101162132.147838-2-danielpaziyski@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261101162132.147838-1-danielpaziyski@gmail.com> References: <20261101162132.147838-1-danielpaziyski@gmail.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=danielpaziyski@gmail.com; helo=mail-wm1-x330.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1793550140387158500 Content-Type: text/plain; charset="utf-8" When a PCI device fails to be registered using do_pci_register_device, which takes the PCI device as one of its arguments, and returns the PCI device it= self on success or null on failure, the acpi index is forcefully released using pci_unregister_acpi_index. However, this causes a null pointer to be passed always on failure to pci_unregister_acpi_index. Instead, do not reassign pci_dev from the return value of do_pci_register_device, just check it. Cc: qemu-stable@nongnu.org Resolves: Coverity CID 1689947 Fixes: 432ea8cc7d27 ("pcie_sriov: register user created virtual function be= fore realizing it") Signed-off-by: Daniel Paziyski --- hw/pci/pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2d2fe02c68..1ea388be37 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2327,10 +2327,8 @@ static void pci_qdev_realize(DeviceState *qdev, Erro= r **errp) pci_dev->cap_present |=3D QEMU_PCIE_CAP_CXL; } =20 - pci_dev =3D do_pci_register_device(pci_dev, - object_get_typename(OBJECT(qdev)), - pci_dev->devfn, errp); - if (pci_dev =3D=3D NULL) { + if (!do_pci_register_device(pci_dev, object_get_typename(OBJECT(qdev)), + pci_dev->devfn, errp)) { pci_unregister_acpi_index(pci_dev); return; } --=20 2.56.0 From nobody Mon Nov 23 04:30:09 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793550178; cv=none; d=zohomail.com; s=zohoarc; b=W3PxJjOutJjYhCyWDGq1v04W74XTSnKdR/zTCwCFdZkUpNP/xJHpHFr3NG+S1NyhKPhu95yD+3OkU4/zWN6wm6GMQGyVMVQ2J4SlsPxd7wnLrjlZQHuw6dEgcoQ0mfP2HBrkT9MZXkzZvFFs6Uk5Sx9vi48XnjdQJS8NW/Wzc+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793550178; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QNmwF2Dh91QQRjJUcxKTTlI814KBb5gis7Xe9e9Z6qU=; b=KrnZq1tcxqTMnuNbIcntwoj7SPsIceytU3r3VF5Aq9+/Q9zqmRH/KciBmJtBJl6J9F4DXf1sDT6yUoiWsz15pE+Shgz3o6ojw4gidfVE2417U+Pleui1Qqrzb2obZSQ2FI+5fQBn39fzUUKEtaJKeNPkED5iRC4qqRzU73EtGE0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793550178776390.166332344097; Sun, 1 Nov 2026 08:22:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNYJW-0004a0-LK; Sun, 01 Nov 2026 11:21:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNYJS-0004Xu-A6 for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:42 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNYJQ-0008Mp-LP for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:42 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4ae34ad9bb6so1884305e9.2 for ; Sun, 01 Nov 2026 08:21:40 -0800 (PST) Received: from AtiePC ([2a0c:5a87:5006:4800:78cf:63bd:d449:f7bc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4aa80f04785sm283897765e9.4.2026.11.01.08.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2026 08:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793550099; x=1794154899; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QNmwF2Dh91QQRjJUcxKTTlI814KBb5gis7Xe9e9Z6qU=; b=n19OKedgrPf2VfupaPL/ERbxitjL6OG87Wg8hQgTaALBXkXmYwlQdnUa9stsdrvo0E JGxmscZYk/OBhphI3c53VBCD1i08iUl9bYdaO2cY+86YFNYsXxL0N7PHA+mPWk/7+r1U IJxyhgJw6ZxcoWtvrOSa8DUtUOoddT48eYd3xDtX1lOmLUP9N0pWJeUA55m1agzPjR+8 xGJ9rQQSYmVxsKNG6bdNOw/nbiGxdva1agYR0jJUzPVlF/OfwJzHPqFA/Rqlzp8IzGdL 1sZIQkONFEmVbsFa9ra7cV6XvJc863cwnQ9h7wU5T8ChUSNOVX6UZz9jw9VangtR/fXO bpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793550099; x=1794154899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QNmwF2Dh91QQRjJUcxKTTlI814KBb5gis7Xe9e9Z6qU=; b=ePO+OT9pHAauiCr2L3Cr2a5fzN51eENsSOELSsgyXK2eEM55i15VnD6H7cI+Y6ArXV 6D+lFBGNiW8CLNTJn52dussrJM6+C9uR1F+TDxYVkQ3YAiUJFccrRTHDv9atKuH4m+kk HU09Q9dwcQFemipiKlwGzvhG7H/HAjrOWa25e0u3LDzhzH6Zd15pTWlilZWk0yDRa+Cf kRE2cJ7bHtIND8RUmL9LK1+G0AdKdRL4tNrRa/82dghJGTGfGrz1qabviKuKHeimtEWh VX3Z+n1fcspvY15Q3sDRfcdFiqFrPc2GNPt6IwBf6OjvVB7gY9xsdqblqSMueN43GbmF YH7A== X-Forwarded-Encrypted: i=1; AKwUvBxFx1ajBOeyqFEszkQVHRVDbn9QQYPnv7IPgzwfDAHrpYAyB2S0ovd/kIvWSDcnUwRhpu3DTEDIlRl2@nongnu.org X-Gm-Message-State: AFq9FYI4RxIl7P6AJtIKecs9vblMQtF4P4EtQus+irWjgzNLoo4qTlwS Mu1DhzABy35LO59Z0XYywAfXRCGwd+Vn8D2hL6UYulx1T2qbDbRACXN9 X-Gm-Gg: AYBFou3sL76R/PLtqhZMh00xsBLKAIxw78ELqq0SuerSHL3ceFFdBfSnHKK4GbOMDpu F8lEvTsCXCVpbif5vL+VY1FokunFH7E3HuztYZWX6lHVJoeVqwpjMT4mWaaXaJ6ERxkUVxqEZDe 0CKW4c31L7Moo4vcSgjtJ+lMgiL57ZVQPR4D5d4ijZNERIODVBkDAlJJB5/M55Y1TU9qdkJN7O5 trU8uAmlMjRuTK1K/ay/SHZ14rBPSTy+T5w+laR2Z11lsmz7UwKEXb8cAO8YbHBMYGPVNCoKDci +YupPWW52pfHpJxurCsB7dH5KW+L/PBvdZlvZmyQjlojZt4K/DBakS11TQawDYcB0Kv+CJEvBf6 RG1B8GIsB9lyfcT7ahlq/fPOa2sLbMbfbsACv9DUrBMyfGSEqhc4s0/vO1fbsDBs9SRKsHqhZNA G+7ks93lLAPjgJinZpwXBYi6wQIx2zh+55eU6GBpDdNigzV/zquZK+z8kom3I61cC7mQOTmB4Ld 8fhjFG3H8jKt4OZeAsp+PwxASQDc7actYuvRzPuAAnX0xdb3ScQ5T2v+ayQiQNURzrhmghgvhxN eHUoQB3lne/Tcfr4QhmO92WXpXujSEcIgtiOIRFskM8SWNB7taHF3Oc8qAc7Z88I X-Received: by 2002:a05:600c:2604:b0:4a1:b027:99ef with SMTP id 5b1f17b1804b1-4ac16acfa8emr133908255e9.2.1793550098883; Sun, 01 Nov 2026 08:21:38 -0800 (PST) From: Daniel Paziyski To: "Michael S. Tsirkin" Cc: Daniel Paziyski , qemu-stable@nongnu.org, qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 2/3] pcie_sriov: perform additional checks after pci device realization Date: Sun, 1 Nov 2026 17:21:30 +0100 Message-ID: <20261101162132.147838-3-danielpaziyski@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261101162132.147838-1-danielpaziyski@gmail.com> References: <20261101162132.147838-1-danielpaziyski@gmail.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=danielpaziyski@gmail.com; helo=mail-wm1-x32b.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1793550179136158501 Content-Type: text/plain; charset="utf-8" Handle two cases after realization, which were implicitly handled back when= PCI SR-IOV device registration was done after PCI realization before commit 432ea8cc7d27 ("pcie_sriov: register user created virtual function before re= alizing it") - If a device is a PF of user created VFs, make sure that it has initialize= d its list of VFs. This check seems to be superfluous, because the only way it = can fail is: - if PCI device realization forgets to initialize the user created virtual functions via pcie_sriov_pf_init_from_user_created_vfs, despite having = set sriov_vf_user_creatable in the device class; - if the pcie_sriov_pf_init_from_user_created_vfs function fails, but for= gets to set errp (which does not happen), and the device specific realization code forgets to check and/or propagate if an error has happened. However, this check was present, so let's include it again for good measu= re. - If a device is a user created VF, make sure that the device is still a PCI Express device. This edge case occurs on devices that before realizat= ion have the PCIe capability set, but then during realization they clear it f= or some reason. This only seems to happen to modern virtio-net-pci devices, = which have their PCIe capability on, as any other modern virtio device, on obje= ct instantiation, but is then cleared in its realize function when it is loc= ated at the root complex or not in a PCIe bus. Cc: qemu-stable@nongnu.org Fixes: 432ea8cc7d27 ("pcie_sriov: register user created virtual function be= fore realizing it") Signed-off-by: Daniel Paziyski --- hw/pci/pci.c | 5 +++++ hw/pci/pcie_sriov.c | 19 +++++++++++++++++++ include/hw/pci/pcie_sriov.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1ea388be37..e85b34d06d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2347,6 +2347,11 @@ static void pci_qdev_realize(DeviceState *qdev, Erro= r **errp) } } =20 + if (!pcie_sriov_check_after_realize(pci_dev, errp)) { + pci_qdev_unrealize(DEVICE(pci_dev)); + return; + } + /* * A PCIe Downstream Port that do not have ARI Forwarding enabled must * associate only Device 0 with the device attached to the bus diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 6a748c3626..618d2a4a64 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -392,6 +392,25 @@ bool pcie_sriov_register_device(PCIDevice *dev, Error = **errp) return true; } =20 +bool pcie_sriov_check_after_realize(PCIDevice *dev, Error **errp) +{ + if (!dev->exp.sriov_pf.vf && dev->qdev.id && + pfs && g_hash_table_contains(pfs, dev->qdev.id)) { + error_setg(errp, "attaching user-created SR-IOV VF unsupported"); + return false; + } + + if (dev->sriov_pf) { + /* some devices might clear their PCIe capability during realizati= on */ + if (!pci_is_express(dev)) { + error_setg(errp, "PCI Express is required for SR-IOV VF"); + return false; + } + } + + return true; +} + void pcie_sriov_unregister_device(PCIDevice *dev) { if (dev->sriov_pf && pfs) { diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index b0ea6a62c7..00fe8c4ada 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -57,6 +57,8 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevic= e *dev, bool pcie_sriov_register_device(PCIDevice *dev, Error **errp); void pcie_sriov_unregister_device(PCIDevice *dev); =20 +bool pcie_sriov_check_after_realize(PCIDevice *dev, Error **errp); + /* * Default (minimal) page size support values * as required by the SR/IOV standard: --=20 2.56.0 From nobody Mon Nov 23 04:30:09 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793550165; cv=none; d=zohomail.com; s=zohoarc; b=E4dDqJFJDGoO332ZIE1ma9hoPjL7LhZbwOCbOdHGg3mwEth1svv4ffrUvqGL8n3pDAY1Hlo1CXdiUcDTeZv26OwdEoTMjknUqKLVjXv03Do3IkCBgPeQ3DTgmnLeoZLt8V8NtpiYlW1mftU7yOB37qf4vqnUjNhkf+t4cgcbWtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793550165; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2hhR2YuIT0xv5LOPPT7Hlt+EDaoi3+8UIv1NmjBiJaE=; b=E7uny9VZxAIJx48YnyoHO4Ti4BzHWEvS/tNM2D/rZ++UM/yRAievyCnmWNg2UoNzAAkV0x8zTX5cyzHDa1aWKl15s9J3LJ2Jq5pcL0AZ9m6R1a40sP8s8CNj/kPGHvSSUT62j2dXOFtzEFJcrXRqtLeoO8qygvF1DdXTaosvkro= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179355016521619.143313120209427; Sun, 1 Nov 2026 08:22:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNYJX-0004am-En; Sun, 01 Nov 2026 11:21:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNYJU-0004YV-0h for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:44 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNYJS-0008N8-5h for qemu-devel@nongnu.org; Sun, 01 Nov 2026 11:21:43 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a78ec32fadso4121115e9.3 for ; Sun, 01 Nov 2026 08:21:41 -0800 (PST) Received: from AtiePC ([2a0c:5a87:5006:4800:78cf:63bd:d449:f7bc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4aa80f04785sm283897765e9.4.2026.11.01.08.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2026 08:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793550101; x=1794154901; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2hhR2YuIT0xv5LOPPT7Hlt+EDaoi3+8UIv1NmjBiJaE=; b=Ac6dAwGl2T8cJ//aeHRsawRTqqPdWpFrtuC25l0UPJqJYi4zF7M6WgUQlO/RxIqrFm NCLYfysrfjV5116ieu+DOSX++JS3ckn16UdRbyySW/ASQ3SRN9WsVzkMKt7xMyNwsZeS BvfItfWNOr8PhDDZT/ZipMTHylZxaRsTNhGuy6UCR6G+QirfBgKj9cggMq2F3QYWaaPR 3ZPlj/mj7hI2bLMaIa8UR7WoyjzOL4NqiOEjxmRBbunQBruDvWPopaRCuNZNQXcrNngr NJfVMC410q1js6RBDrH1VcuDPcSfg8WRX+I9xwAO3UzPxbskrvAQPQwKZs3sHfMZ/LJt gmvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793550101; x=1794154901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=2hhR2YuIT0xv5LOPPT7Hlt+EDaoi3+8UIv1NmjBiJaE=; b=IX1I6PGh+3jizkh5q0ZchCJpyGwDMSAtqN7t54TvitEKv8kbbuHLXfJASQCKtKB5z+ iRjBLYZiM6h7RNAtdC5g6EQGSlvtWhJnLYmIzT1OCCgksAdcsUpZuCs8WZTO+JrJr3LA S648G2Ruvw8WzwciskTSRgdGCr9qyfShE6AkVZWA95SYXBrCcddxe2KgjJNQ5q5/XsDt Ayfnw5rD0jnzhLdun04sfkv0Biiln8PxiwLSpDbP2ShYnQsL9sYL1dWQcMohTLsChjuu kJD3FXP9EaEqi+qDCNeZE7dWPcHkMHQGaN3JWwzT2REaEEQv3MFlgpSyYuK9B72ilrFX Ij1w== X-Forwarded-Encrypted: i=1; AKwUvBzSpXmQ49yFgiAy5DD7WiJYblO9LKSRMWlyZ1/9FFzvY97QWad/iTU8Uxe7YNK8MONBIhixoFAzt/0w@nongnu.org X-Gm-Message-State: AFq9FYI+zcFz5Q2nAkFxub2pdHf06u3LgOeuQRfX8KBivEasTSGaxhcZ 3MhZrvBKSTqlnlVuIvyXsdCe8vDJt5HvWL3n89OOM5kTlYDoqz1WVCkw X-Gm-Gg: AYBFou1nU/5GPKDF59AAljHtWLl2gopXJ2HT0zp0EP/rUSMUxRNSio8nc5VxlSB+XVb DsHMarBv13F+ECkuPbxBaTkCqtuunvNphfd+/tXn8StUANFs8/lq+cdCvMHamgko60PpmBpsG0R sSpeyZVPmce0nUq5AUWpY/f/Ql5v2ojY4G44M2ke/LwEV2L/KN9b+Nk7qpyrXr+p6wUibN0qCtX i+8qwlS2xgZgKrW6s8nGgsEBGriWeQT3ehXq0EIc7xmyIV5cnLEl61/JZwjxegSm8uEu+igDrZY tf13utSlH/vht2YXDqvYMIUxT8JGsi0HN7ZsnhsgU+GBbPj7YqVD7e0ZF1oJAe/2khjUt3sHFQG DeRNf+YoTyUsBk3PpLQzapB6gDjqBhpodC1hOsQ7O3e6LQ3PuZeYZA05XTLH4kLPTYGpyMqBms9 ftzEPB9D10UaCkgQu2WAOKc2eDgZvW7mM97iME5kyYI1gPdvD0v5vs1Q0WeMpM6u8/TcIhSl7yp hMNUtI/kOpheqyf5cJRpJDyEpKwAaDNe3wr1t6yn98iAafvPSQJIbmMfOUI4IS1lE69699CbfJY rp37lK/Eg/8j4hF2DSyN8XXefa/AImcjy703nRR43HnHHHPsVE68TCv45R+CFlXZ X-Received: by 2002:a05:600c:1798:b0:4a0:1f9e:5f78 with SMTP id 5b1f17b1804b1-4ac1228a41emr117770255e9.0.1793550100685; Sun, 01 Nov 2026 08:21:40 -0800 (PST) From: Daniel Paziyski To: "Michael S. Tsirkin" Cc: Daniel Paziyski , qemu-stable@nongnu.org, qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 3/3] pcie_sriov: fix null pointer dereference when initializing PFs in a system with user and device created VFs Date: Sun, 1 Nov 2026 17:21:31 +0100 Message-ID: <20261101162132.147838-4-danielpaziyski@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261101162132.147838-1-danielpaziyski@gmail.com> References: <20261101162132.147838-1-danielpaziyski@gmail.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=danielpaziyski@gmail.com; helo=mail-wm1-x32b.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1793550166899158500 Content-Type: text/plain; charset="utf-8" pcie_sriov_pf_init is only used to initialize PFs for device created VFs, a= nd as such, it is checked that the PF has not been referenced by a user create= d VF by means of the sriov-pf parameter. This check crashes if it is performed for a PF that does not have an ID, and there are already user created VFs in the system. Example: qemu-system-x86_64 -M q35 \ -device pcie-root-port,id=3Drp1,chassis=3D1,slot=3D1 \ -device virtio-net-pci,sriov-pf=3Df,addr=3D0.1,bus=3Drp1 \ -device virtio-net-pci,id=3Df,addr=3D0.0,bus=3Drp1 \ -device pcie-root-port,id=3Drp2,chassis=3D1,slot=3D2 \ -device nvme-subsys,id=3Dsubsys0 \ -device nvme,sriov_max_vfs=3D1,serial=3Ds,sriov_vq_flexible=3D2,sri= ov_vi_flexible=3D1,bus=3Drp2,subsys=3Dsubsys0 ASAN message: The signal is caused by a READ memory access. Hint: address points to the zero page. #0 in g_str_hash (/usr/lib/libglib-2.0.so.0+0x49954) #1 in g_hash_table_contains (/usr/lib/libglib-2.0.so.0+0x4ad3b) #2 in pcie_sriov_pf_init ../hw/pci/pcie_sriov.c:161 #3 in nvme_init_sriov ../hw/nvme/ctrl.c:9088 #4 in nvme_init_pci ../hw/nvme/ctrl.c:9218 #5 in nvme_realize ../hw/nvme/ctrl.c:9696 Cc: qemu-stable@nongnu.org Fixes: 19e55471d4e8 ("pcie_sriov: Allow user to create SR-IOV device") Signed-off-by: Daniel Paziyski --- hw/pci/pcie_sriov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 618d2a4a64..7111f2f399 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -158,7 +158,7 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, BusState *bus =3D qdev_get_parent_bus(&dev->qdev); int32_t devfn =3D dev->devfn + vf_offset; =20 - if (pfs && g_hash_table_contains(pfs, dev->qdev.id)) { + if (pfs && dev->qdev.id && g_hash_table_contains(pfs, dev->qdev.id)) { error_setg(errp, "attaching user-created SR-IOV VF unsupported"); return false; } --=20 2.56.0