From patchwork Mon Mar 7 22:33:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 593311 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0C9F9140273 for ; Tue, 8 Mar 2016 09:35:23 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ad3ie-0006D3-JY; Mon, 07 Mar 2016 22:33:40 +0000 Received: from mail.kernel.org ([198.145.29.136]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ad3ia-00068y-Nu for linux-arm-kernel@lists.infradead.org; Mon, 07 Mar 2016 22:33:38 +0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 59C992022D; Mon, 7 Mar 2016 22:33:14 +0000 (UTC) Received: from localhost (unknown [69.71.1.1]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 20FD22026F; Mon, 7 Mar 2016 22:33:12 +0000 (UTC) Date: Mon, 7 Mar 2016 16:33:11 -0600 From: Bjorn Helgaas To: Krzysztof =?utf-8?Q?Ha=C5=82asa?= Subject: Re: [PATCH] Fix NULL ptr dereference in pci_bus_assign_domain_nr() on ARM Message-ID: <20160307223311.GB26149@localhost> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160307_143336_891914_498DC71C X-CRM114-Status: GOOD ( 21.33 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [198.145.29.136 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Lorenzo Pieralisi , linux-kernel@vger.kernel.org, linux-arm-kernel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org [+cc Lorenzo] On Tue, Mar 01, 2016 at 07:07:18AM +0100, Krzysztof Hałasa wrote: > Many ARM platforms use a wrapper: > /* > * Compatibility wrapper for older platforms that do not care about > * passing the parent device. > */ > static inline void pci_common_init(struct hw_pci *hw) > { > pci_common_init_dev(NULL, hw); > } > > which means that pci_bus_assign_domain_nr() can be called without > a parent. This patch fixes the NULL pointer dereference. > > Signed-off-by: Krzysztof Hałasa > Cc: stable@vger.kernel.org I applied this to for-linus with changelog as below for v4.5, thanks! Wow, this is terrible. All ARM32 systems that use pci_common_init() crash at boot. That includes cns3xxx, dove, footbridge, iopl13xx, ip32x, iop33x, ixp4xx, ks8695, mv78xx0, orion5x, pxa, sa1100, etc. Apparently they've been crashing since v4.0, when 7c674700098c and 8c7d14746abc appeared. I can hardly believe nobody noticed until now. Actually, I did find one problem report: http://forum.doozan.com/read.php?2,17868,22070,quote=1 from last May, but apparently it got lost in a forum and never found its way upstream. I reworked the changelog because this problem will affect *any* arch that enables CONFIG_PCI_DOMAINS_GENERIC and supplies NULL "parent" pointers -- ia64, mips, mn10300, s390, x86, etc., would be affected if they enabled CONFIG_PCI_DOMAINS_GENERIC. I also added a "Fixes:" tag for 7c674700098c, since that's the commit that added the generic code we're fixing. Backports of 7c674700098c should also backport this change. Bjorn commit 71babd2a89fe Author: Krzysztof =?utf-8?Q?Ha=C5=82asa?= Date: Tue Mar 1 07:07:18 2016 +0100 PCI: Allow a NULL "parent" pointer in pci_bus_assign_domain_nr() pci_create_root_bus() passes a "parent" pointer to pci_bus_assign_domain_nr(). When CONFIG_PCI_DOMAINS_GENERIC is defined, pci_bus_assign_domain_nr() dereferences that pointer. Many callers of pci_create_root_bus() supply a NULL "parent" pointer, which leads to a NULL pointer dereference error. 7c674700098c ("PCI: Move domain assignment from arm64 to generic code") moved the "parent" dereference from arm64 to generic code. Only arm64 used that code (because only arm64 defined CONFIG_PCI_DOMAINS_GENERIC), and it always supplied a valid "parent" pointer. Other arches supplied NULL "parent" pointers but didn't defined CONFIG_PCI_DOMAINS_GENERIC, so they used a no-op version of pci_bus_assign_domain_nr(). 8c7d14746abc ("ARM/PCI: Move to generic PCI domains") defined CONFIG_PCI_DOMAINS_GENERIC on ARM, and many ARM platforms use pci_common_init(), which supplies a NULL "parent" pointer. These platforms (cns3xxx, dove, footbridge, iop13xx, etc.) crash with a NULL pointer dereference like this while probing PCI: Unable to handle kernel NULL pointer dereference at virtual address 000000a4 PC is at pci_bus_assign_domain_nr+0x10/0x84 LR is at pci_create_root_bus+0x48/0x2e4 Kernel panic - not syncing: Attempted to kill init! [bhelgaas: changelog, add "Reported:" and "Fixes:" tags] Reported: http://forum.doozan.com/read.php?2,17868,22070,quote=1 Fixes: 8c7d14746abc ("ARM/PCI: Move to generic PCI domains") Fixes: 7c674700098c ("PCI: Move domain assignment from arm64 to generic code") Signed-off-by: Krzysztof Hałasa Signed-off-by: Bjorn Helgaas CC: stable@vger.kernel.org # v4.0+ Acked-by: Lorenzo Pieralisi diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 602eb42..f89db3a 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4772,8 +4772,10 @@ int pci_get_new_domain_nr(void) void pci_bus_assign_domain_nr(struct pci_bus *bus, struct device *parent) { static int use_dt_domains = -1; - int domain = of_get_pci_domain_nr(parent->of_node); + int domain = -1; + if (parent) + domain = of_get_pci_domain_nr(parent->of_node); /* * Check DT domain and use_dt_domains values. *