Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp630349pxb; Wed, 6 Oct 2021 12:00:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbN1TDnFBoOf9hs+SA64lRvzE1TCUUYEeL1v8O2i+0aAhAUjhejhL5/eJPD9/HPKa2FoFF X-Received: by 2002:a63:5902:: with SMTP id n2mr289525pgb.305.1633546803286; Wed, 06 Oct 2021 12:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633546803; cv=none; d=google.com; s=arc-20160816; b=GMSq7YN7vpkno/PbKA93GBFGifprnMV2MvJqskL6VjnVvpFxS3MzKwDMdAIwoPfj0t RFKauAvkbQeOUhNiHcwlyjoqYHx6D9FrxjZh9aj6H7B9EzVWCyWWewBIX5T7dmA1/zrT cpDRy3djX4PFpTK5Whau88Gu707QrtwvtJeQku9MLMWMqDAvfAdtjS/R4ShcnKnEkyp4 0JZh21YI4TU64Vz3Gu8sHB2UKQe1oo6MKg46JyeljNxg9eBpLZebRZsD6sKyN76IYHtL kFrBFO28T2pXg7oXhAIPH9DYb2vEWkP5be3M3wFkEBdg6tRggaZH1UMSUGBAKYYWfSh+ NsAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=Ea77CYuA2YCrKCN8DmEUaYWjvIMhA+ARNgtG1yW5SLE=; b=H6Ks83Sk1CCFSFOiMlzQTB3ALw3o38ZdnNaCQrc8Q04QuUTt0lqQIEJSq9EbOre85x yw04M81xZ51cDaJhq1no8s//G3CzELcbWI9TqRVZyIBtdNjDf85Lk0DjjqzPopFIFJ5s 29IdqU8kBgAUAsIGqb8sZ7XpS550dlgRVkro/cT1RH2cTNdprL4Hht1IDd9TYX0wT3/A SA+ug2rvo14ejW21m+1/xjc5fBsnPiL6AuqpOwoKQhT3E8W8rAwUyKGdim3gAXcsxdpJ SWxbSYz+Eo1Tr6FFtK9eu6PZEaZoLdJ0RI7CgcaGP/zvDLc6NF8EWqTaUryl6sOdvlGh W8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sXZ7tDgT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r13si28843871pgr.342.2021.10.06.11.59.48; Wed, 06 Oct 2021 12:00:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sXZ7tDgT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232027AbhJFTAh (ORCPT + 99 others); Wed, 6 Oct 2021 15:00:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:54090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbhJFTAg (ORCPT ); Wed, 6 Oct 2021 15:00:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F24260FF2; Wed, 6 Oct 2021 18:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633546724; bh=BrN9DZemZ8hoX2bxvUst8/KdBJIpbuojdOqUUhWaURM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=sXZ7tDgTZ/NuDdHCT2qLEkuHF4wsk2U9FC5GsaLmvzZQg2BHcoz6mOaV6WBxgK6G/ cZ0v/bbw5FTNx4WJnpS0NNCj1OPoZm50TfAuItN9bLd+gpj4Ng32bw2R6LDla0ZPL2 zhNK/9J8VXVpPMN0X0f6RLqhg74EDJCTe3Rtupj9cUjqeZbypMo0BkR4KQlyUS4ylL f+h9nJbdQvfJMIRLSyw+4s8GL1B31ySUcCox2V5hEeH8Yq/V1jnIoX5bxQMfr3Lvey dkYZSR/JhtvRwDFKYcmDL6mdw8j4oE8vROo7YL+HXeg5lnwf7QTSGl/6bhH/8j2+Bk PcFAg/wcxFR1w== Date: Wed, 6 Oct 2021 13:58:42 -0500 From: Bjorn Helgaas To: "Rafael J. Wysocki" Cc: Linux PCI , Linux ACPI , LKML , Niklas Schnelle , Jesse Brandeburg , Shanker Donthineni , Alex Williamson Subject: Re: [PATCH] PCI: ACPI: Check parent pointer in acpi_pci_find_companion() Message-ID: <20211006185842.GA1172531@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5523582.DvuYhMxLoT@kreacher> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 01, 2021 at 03:58:10PM +0200, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > If acpi_pci_find_companion() is called for a device whose parent > pointer is NULL, it will crash when attempting to get the ACPI > companion of the parent due to a NULL pointer dereference in > the ACPI_COMPANION() macro. > > This was not a problem before commit 375553a93201 ("PCI: Setup ACPI > fwnode early and at the same time with OF") that made pci_setup_device() > call pci_set_acpi_fwnode() and so it allowed devices with NULL parent > pointers to be passed to acpi_pci_find_companion() which is the case > in pci_iov_add_virtfn(), for instance. > > Fix this issue by making acpi_pci_find_companion() check the device's > parent pointer upfront and bail out if it is NULL. > > While pci_iov_add_virtfn() can be changed to set the device's parent > pointer before calling pci_setup_device() for it, checking pointers > against NULL before dereferencing them is prudent anyway and looking > for ACPI companions of virtual functions isn't really useful. > > Fixes: 375553a93201 ("PCI: Setup ACPI fwnode early and at the same time with OF") > Link: https://lore.kernel.org/linux-acpi/8e4bbd5c59de31db71f718556654c0aa077df03d.camel@linux.ibm.com/ > Reported-by: Niklas Schnelle > Tested-by: Niklas Schnelle > Signed-off-by: Rafael J. Wysocki Acked-by: Bjorn Helgaas > --- > drivers/pci/pci-acpi.c | 3 +++ > 1 file changed, 3 insertions(+) > > Index: linux-pm/drivers/pci/pci-acpi.c > =================================================================== > --- linux-pm.orig/drivers/pci/pci-acpi.c > +++ linux-pm/drivers/pci/pci-acpi.c > @@ -1243,6 +1243,9 @@ static struct acpi_device *acpi_pci_find > bool check_children; > u64 addr; > > + if (!dev->parent) > + return NULL; > + > down_read(&pci_acpi_companion_lookup_sem); > > adev = pci_acpi_find_companion_hook ? > > >