Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4611022pxb; Tue, 5 Oct 2021 06:48:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyVcFT1ZKJnq2dNMQr0EpIGb3f5rePJYo5AWsR5ertXJCBCq26o/srqMOIsJ4VVhyqJt/V X-Received: by 2002:a17:906:713:: with SMTP id y19mr24868718ejb.506.1633441734240; Tue, 05 Oct 2021 06:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633441734; cv=none; d=google.com; s=arc-20160816; b=XP8sO0erkoowhmMTGdMohkbhtFlad6J5egaOUzauAvKvmEQ499Sd/VnH7of5g6o1hl nL9N9L/q1BKikJVUlqMAmz653/EwCRdiC1qaZ2SlvmLMi+IA3q6OEYwqoA3f2/kMSMCr q1jKRdZMp3Lq+HTnCE1D2V6dkFv2C7tcoDphpy0XHP8rcXv8nbC6mD8dM4W3gj5SiuuA 9DAu4D6R9+R9dfQOy0HeWKuvpl6oS/V/R92wC/3jAJCVZmpIja3jUn42IyZeV6aOhtcT jVmxK/1tEZUYRw+qT6Kd4zACW2n4HDdjIJaFh+feO8/96U8g5vK4sMVcthuBTjPpLl7P tphQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=GZuitQsZRbIllSd5c/N0q7ztxTY7wBNZEilaLOdnQlM=; b=ljUkX43ndG8ZzY5n8k9K/4umXrqzGcd42ERb1JURLaIQtrAoHzE758fYEWS6bedUdA wM5glOuGT14T+f9mOmeER0CAjJZ0cR1JFwFTuc4XJPp8LaKqmB6185DPgtkJlRSLkngN dc/Q2ut4CxLRitaX1i7h/bAHcaXEbVLam88e3oLMLj+Lp+elDoS7Vqd0nt6iTtEpzKa0 tEojniJcX6eIqk2v48oHh+hHYigj4ZzdrX/dZOhAqpkz0edA/oI8iFwlArcLPLp95ZMZ dy0Z88tbVpgHrj6rKxP/7YxzqrLeqvBcZidvnuocAErQXjytgIdTx1Ab8u5Ro1dHXY4r W3vA== ARC-Authentication-Results: i=1; mx.google.com; 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 x21si18030456eje.216.2021.10.05.06.48.28; Tue, 05 Oct 2021 06:48:54 -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; 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 S235056AbhJENsP (ORCPT + 99 others); Tue, 5 Oct 2021 09:48:15 -0400 Received: from mail-oi1-f174.google.com ([209.85.167.174]:35501 "EHLO mail-oi1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235132AbhJENsO (ORCPT ); Tue, 5 Oct 2021 09:48:14 -0400 Received: by mail-oi1-f174.google.com with SMTP id n64so26293186oih.2; Tue, 05 Oct 2021 06:46:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GZuitQsZRbIllSd5c/N0q7ztxTY7wBNZEilaLOdnQlM=; b=b+Rr4me7ShRBrYIYKZ+QX2dzafebnTZqEql7zZiqIYQxLBO9gO1cM+tz6pIge1gSIz +Fciz2VjkFtaI5n7gKWXyGSzLph1EQnT8BpHF0uLvQ4EJTajFzE6l/zF8f7qZItYSVy5 ibE+ocJUE/Gkg3/pTU0L7xZ+U1mT1sLEaG6tVio7bEXLFU3TCgn71vg6ccHeKdbjhrN9 co24lEs+yIVhGPxiyfDQHCtdmUvhPd2SdZaO+u8FoSsdyDgxh2VbW8hYio39Ze2c61mQ Govqv68NsjFJkUnTdffX35U+9yn5CHzd2wbEjyH0PYZo2jvKv9HX5xHSIh4N1lq5hKmj XpEg== X-Gm-Message-State: AOAM531jXxiHJQsB2V3hJH/1PMrnaHkB8jRr+0PmZxIgLJ7I5E5Ijoj+ eDXmjrZwfbunX88GyHYwaBzH/JyWfpfej1s6F43zDm7K X-Received: by 2002:aca:6009:: with SMTP id u9mr2640823oib.71.1633441583791; Tue, 05 Oct 2021 06:46:23 -0700 (PDT) MIME-Version: 1.0 References: <5523582.DvuYhMxLoT@kreacher> In-Reply-To: <5523582.DvuYhMxLoT@kreacher> From: "Rafael J. Wysocki" Date: Tue, 5 Oct 2021 15:46:12 +0200 Message-ID: Subject: Re: [PATCH] PCI: ACPI: Check parent pointer in acpi_pci_find_companion() To: Linux PCI Cc: Bjorn Helgaas , Linux ACPI , LKML , Niklas Schnelle , Jesse Brandeburg , Shanker Donthineni , Alex Williamson , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 1, 2021 at 3:58 PM 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 Due to the lack of negative feedback I'm queuing this up for 5.15-rc5. If there are concerns, please let me know. > --- > 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 ? > > >