From patchwork Mon Nov 18 21:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 844125 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp838642wrx; Mon, 18 Nov 2024 13:10:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW3tN4Q9iEXDHO+PG33P+1FK3N7Wd1OdjWcuLS9o3hZLBZtr0RXZEUj5OpnrkEgG812cCHWvw==@linaro.org X-Google-Smtp-Source: AGHT+IH9Rz84yL5Cs6Yk3zfOH+YAW8Sk1Kja06pGGkyjySHgXuIE8RIiBCo4Olur4KlEhKz6UdeD X-Received: by 2002:a05:620a:408a:b0:7ac:e832:907c with SMTP id af79cd13be357-7b36237b24fmr1815679685a.55.1731964240719; Mon, 18 Nov 2024 13:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731964240; cv=none; d=google.com; s=arc-20240605; b=d3l2/32bxZVj3zp0frAt+jrb2GHNCw476wt1nQaYab5hD0xFdElejQZtxzM/nWXH+A rc3EK3GcaprJP1eK1mEkrA1YeqXfsXndFIDTQp6brGJ+fWjmTA4Sb3FpjAUAdk39xh/X dwr8sK14izx65AV+V/dvOFoKYQR9CJHSviA8DpzrJilovwawlnVRgddZSh/xaaHaBJ8L TZBPVnZdqI2f63xnWwR4gsFCyBQKe11ZNeSwiOCs8227J/gPxsEoll/ZndYqpgV7dyNr j62xh6a4kaQB1UeTCl1Gd5t7DO88VNSvHCmLGgYiwLgRuSrvx3u3RzQq1YkG5aESLWuL 19PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=HbmMIEBXm3RAl5QDCzhaVlmc5ulg64sG1lQj0hwDWeU=; fh=tMa47au2sw5piyxOJuQsGBLvYh0d/gfD9bj/VCraw+I=; b=hpwTbpr/ksE0g2YTB69JkR//HhySajuy1nUKaekp+uksVCCRR136c2L733FrlLUWEj qOTnXpwTw1NVWKjgK+YEYf0dTWJEl1Jq5oIOkDAGAoF3D/8sMMpIPnq8qwVbBbKRl5Pm jUBrhjnNUomIg1dx0Gqp8yIHyHgUuE3CWdaA30fzZvGMdqijhrIeFkCcQGBJVhKqy4nD i8+ccWpTcWV1H7GWvS8B84IURdXxK+zgMWgI2WctdAPKenthfTyH06au7lZxlep4k6/r seT2ac4uIphaPpdWoA69CoqXMYAjz+G3cBTyH4YLYtupWZTpCMWmPHgFtYDog3rWMh0k 4R3w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b37a8ac141si70092685a.643.2024.11.18.13.10.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 13:10:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD900-0002Gr-91; Mon, 18 Nov 2024 16:09:32 -0500 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 1tD8zG-0001rq-Fg; Mon, 18 Nov 2024 16:08:47 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tD8zC-0005M7-HF; Mon, 18 Nov 2024 16:08:45 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 54A0AA5608; Tue, 19 Nov 2024 00:08:31 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id E1EED173621; Tue, 19 Nov 2024 00:08:34 +0300 (MSK) Received: (nullmailer pid 2366099 invoked by uid 1000); Mon, 18 Nov 2024 21:08:34 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , Paolo Bonzini , Michael Tokarev Subject: [Stable-9.0.4 59/71] hw/i386/pc: Don't try to init PCI NICs if there is no PCI bus Date: Tue, 19 Nov 2024 00:08:16 +0300 Message-Id: <20241118210834.2366046-2-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell The 'isapc' machine type has no PCI bus, but pc_nic_init() still calls pci_init_nic_devices() passing it a NULL bus pointer. This causes the clang sanitizer to complain: $ ./build/clang/qemu-system-i386 -M isapc ../../hw/pci/pci.c:1866:39: runtime error: member access within null pointer of type 'PCIBus' (aka 'struct PCIBus') SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/pci/pci.c:1866:39 in This is because pci_init_nic_devices() does &bus->qbus which is undefined behaviour on a NULL pointer even though we're not actually dereferencing the pointer. (We don't actually crash as a result, so if you aren't running a sanitizer build then there are no user-visible effects.) Make pc_nic_init() avoid trying to initialize PCI NICs on a non-PCI system. Cc: qemu-stable@nongnu.org Fixes: 8d39f9ba14d64 ("hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()") Signed-off-by: Peter Maydell Link: https://lore.kernel.org/r/20241105171813.3031969-1-peter.maydell@linaro.org Signed-off-by: Paolo Bonzini (cherry picked from commit bd0e501e1a4813fa36a4cf9842aaf430323a03c3) Signed-off-by: Michael Tokarev diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5c21b0c4db..6bd2333c2e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1280,7 +1280,9 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus) } /* Anything remaining should be a PCI NIC */ - pci_init_nic_devices(pci_bus, mc->default_nic); + if (pci_bus) { + pci_init_nic_devices(pci_bus, mc->default_nic); + } rom_reset_order_override(); }