From nobody Tue May 7 22:36:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642801611622183.38772417946882; Fri, 21 Jan 2022 13:46:51 -0800 (PST) Received: from localhost ([::1]:54748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1k9-0000kI-TN for importer@patchew.org; Fri, 21 Jan 2022 16:46:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB1cn-0004LR-4T; Fri, 21 Jan 2022 16:39:14 -0500 Received: from [2607:f8b0:4864:20::333] (port=38868 helo=mail-ot1-x333.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nB1cc-0003MQ-SD; Fri, 21 Jan 2022 16:39:04 -0500 Received: by mail-ot1-x333.google.com with SMTP id k13-20020a056830150d00b0059c6afb8627so11200662otp.5; Fri, 21 Jan 2022 13:39:02 -0800 (PST) Received: from rekt.ibmuc.com ([191.8.61.226]) by smtp.gmail.com with ESMTPSA id u4sm1514402ots.37.2022.01.21.13.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 13:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e/uJC9/bYCxhu6D/1sgpkQOihdP7dQbwa96H4PVeAg0=; b=YsW4yNTUJBPfqojpjQCjVqUW9D9ixxcMJ5MWu9FaiFJBRgrbB5jwb89w+exvvniqPI AahYc67CGymHbDDittanOwwGCSwS+ZBgywqUPoDpBXiFImGtgQjvI9DRZY8i5quF2eAE gbM7Ci+i005p+fU4OFvr281Cwsy3TYwaMfAOYcKgK0FHtqOs+ksHYusnDnZlpKlSd4VP irOMwcxrNlrjf9Fkuyq/V3gdhfnhxIZQ9tv0sDcLRD3O6ZzNbnOtavSc9ib3lp+F3BKN o27WCymH/QUeprSJCVGF+p4TyyzJR1kEOXU/jwg6rPh1/3qGyWsa9dRJkPHtw30Bj7iI 1Vig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e/uJC9/bYCxhu6D/1sgpkQOihdP7dQbwa96H4PVeAg0=; b=CMv1nMLjMosHZiNx2VXGKzrWqfJYbiMR7vmyv0AGH8loG8Aa8qsnbWJcJ5f4eJ6c0w FamPIEZggOigzu1q/jPYbt8vXe+MDoD5dQcoRASfM1TImarXzH+MQaslp8JHhs/NNV2S exYGdVuQfYpPtClcNhnUOQ5EjFklzXhhQUxWsIRgyIJxLsIahxl15HHSkKBeXpczJFKK 4rgPiGNSFx0G74x7ekL5CbbVGzS8knQWW5FnL6t6YYcchioZtovwn62XJro257/NsfYg d95yTXv8uFN21oi/fN3aqXNGJ7anlMRPirtoDC7Yq1ARVr1ecSiWKebxxZcTYk579Kri X4sg== X-Gm-Message-State: AOAM531JDIoDEjq2kRrOVcwVvLGYv5Jnwd5yDkVbY5IpMWMwHYzzg5wp ztVPmFiBmq9bPoHznWH/kICgw+6gyKQ= X-Google-Smtp-Source: ABdhPJx035x4sFzwfJgAIOux4o5+zN2YwvH253EBIx1j38KIdOwgFLjL2w0U2XSnwTD39IXQYNFbjA== X-Received: by 2002:a9d:6a47:: with SMTP id h7mr4048488otn.65.1642801141215; Fri, 21 Jan 2022 13:39:01 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH] spapr.c: check bus != NULL in spapr_get_fw_dev_path() Date: Fri, 21 Jan 2022 18:38:52 -0300 Message-Id: <20220121213852.30243-1-danielhb413@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::333 (failed) 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=2607:f8b0:4864:20::333; envelope-from=danielhb413@gmail.com; helo=mail-ot1-x333.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642801613457100001 Content-Type: text/plain; charset="utf-8" spapr_get_fw_dev_path() is an impl of FWPathProviderClass::get_dev_path(). This interface is used by hw/core/qdev-fw.c via fw_path_provider_try_get_dev_path() in two functions: - static char *qdev_get_fw_dev_path_from_handler(), which is used only in qdev_get_fw_dev_path_helper() and it's guarded by "if (dev && dev->parent_bus)"; - char *qdev_get_own_fw_dev_path_from_handler(), which is used in softmmu/bootdevice.c in get_boot_device_path() like this: if (dev) { d =3D qdev_get_own_fw_dev_path_from_handler(dev->parent_bus, dev); This means that, when called via softmmu/bootdevice.c, there's no check of 'dev->parent_bus' being not NULL. The result is that the "BusState *bus" arg of spapr_get_fw_dev_path() can potentially be NULL and if, at the same time, "SCSIDevice *d" is not NULL, we'll hit this line: void *spapr =3D CAST(void, bus->parent, "spapr-vscsi"); And we'll SIGINT because 'bus' is NULL and we're accessing bus->parent. Adding a simple 'bus !=3D NULL' check to guard the instances where we access 'bus->parent' can avoid this altogether. Signed-off-by: Daniel Henrique Barboza Reviewed-by: C=C3=A9dric Le Goater --- hw/ppc/spapr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 72f5dce751..3d6ec309dd 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3053,7 +3053,7 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p,= BusState *bus, VHostSCSICommon *vsc =3D CAST(VHostSCSICommon, dev, TYPE_VHOST_SCSI_CO= MMON); PCIDevice *pcidev =3D CAST(PCIDevice, dev, TYPE_PCI_DEVICE); =20 - if (d) { + if (d && bus) { void *spapr =3D CAST(void, bus->parent, "spapr-vscsi"); VirtIOSCSI *virtio =3D CAST(VirtIOSCSI, bus->parent, TYPE_VIRTIO_S= CSI); USBDevice *usb =3D CAST(USBDevice, bus->parent, TYPE_USB_DEVICE); --=20 2.34.1