Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4185779imu; Tue, 18 Dec 2018 10:22:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6yykHbDX92Obp1+qm6qnykK+O2RsHDG703NjYeUwQ54BUTPQE50bk4mn3PbyFARMAvUNe X-Received: by 2002:a17:902:f082:: with SMTP id go2mr17407176plb.115.1545157367015; Tue, 18 Dec 2018 10:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545157366; cv=none; d=google.com; s=arc-20160816; b=oGuhErSacNjwZPj1SHsdh7Y/WmByOpMBuv7uGpbJG5lMoXAzLLC3RXK/SA2XaHXY5T HAziwYyOw+OrVtNcDMbx5hourLDhB8dkUdKW0fAUezyzzoF9TPddF1eL9ouZ+8LracS4 8EGPGEOIPSA2Q8K3Agk0nEyStYaWujYMNnRanMMSTdeZrbFjKmQ3q+Q5n1ZOk1JzaTpW 7KXwnGKNBmcuPbvDiu5iThdN7XHZID1AV/Fk57a8awj+lI1DqEnL7qQxm9TibUtnu6A7 nZsO8CTrlqo+L0awDWDYqvRxlivHzFJrO0o2/Tu6+/m2kv1XXuaqkZkV76K0S1UWDhE9 S8mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X+G5Y7roFktvHc0hT8Zhm1Bo5CeVryVVPC4o9k3zxJg=; b=zfx0MmZCmjKMlC2KXVoOow7vNFZ4E7nqfbNPOru1ox3LeyXmea10IMC+/aFHnT/RWq B/7+bQKXCpJtuVyhSUauTjPdAMUSUJbgptQjVea4cxOkZffD0/VbNpOb3bYGA7zROOhr Si6s0XuQ/orJhsMTjI7KZlZV2j/PobNKu3Z94Iox7DRyakZR2l53pXCO2RWJbmsCzfNe Y9tjC2qbzJWR8W6AvRraBf9EDwmVVc1S2IVsi++eQj5Y8ymi1kIYgXaWB3LQFnyTvwKy F+lyOcyXXfwnD8BeiUbRC1lol6kCuBF1016gfmCPeec2sO0OSYeABCtdmNaJvWApQCvw QeMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VkihMO/E"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si12688863pgm.250.2018.12.18.10.22.29; Tue, 18 Dec 2018 10:22:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VkihMO/E"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbeLRQlw (ORCPT + 99 others); Tue, 18 Dec 2018 11:41:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:39398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727598AbeLRQlt (ORCPT ); Tue, 18 Dec 2018 11:41:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 388FA218A4; Tue, 18 Dec 2018 16:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545151308; bh=qPba8Uk0y0zHYJaSx5j2SPDYnRI40m9EhfSc1vrHaHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VkihMO/En9738WyTnB/vJjIeTbUTaWYoDmgTCJBAF5dLdRJl3FdceuGQPpfdVNjtg 8LruLyivp8BbfaYTangmnirvr9ahoP2xCCSjnzZsqEr7ZjpxIhWPsB11d9PE7IHtM8 7+lSWHz03UtLRL4p2tRKDsLcxE9TjJ7bGMomWw8M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Radu Rendec , Michael Ellerman Subject: [PATCH 4.19 31/44] powerpc/msi: Fix NULL pointer access in teardown code Date: Tue, 18 Dec 2018 17:39:43 +0100 Message-Id: <20181218163931.095810312@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181218163927.119623235@linuxfoundation.org> References: <20181218163927.119623235@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Radu Rendec commit 78e7b15e17ac175e7eed9e21c6f92d03d3b0a6fa upstream. The arch_teardown_msi_irqs() function assumes that controller ops pointers were already checked in arch_setup_msi_irqs(), but this assumption is wrong: arch_teardown_msi_irqs() can be called even when arch_setup_msi_irqs() returns an error (-ENOSYS). This can happen in the following scenario: - msi_capability_init() calls pci_msi_setup_msi_irqs() - pci_msi_setup_msi_irqs() returns -ENOSYS - msi_capability_init() notices the error and calls free_msi_irqs() - free_msi_irqs() calls pci_msi_teardown_msi_irqs() This is easier to see when CONFIG_PCI_MSI_IRQ_DOMAIN is not set and pci_msi_setup_msi_irqs() and pci_msi_teardown_msi_irqs() are just aliases to arch_setup_msi_irqs() and arch_teardown_msi_irqs(). The call to free_msi_irqs() upon pci_msi_setup_msi_irqs() failure seems legit, as it does additional cleanup; e.g. list_del(&entry->list) and kfree(entry) inside free_msi_irqs() do happen (MSI descriptors are allocated before pci_msi_setup_msi_irqs() is called and need to be cleaned up if that fails). Fixes: 6b2fd7efeb88 ("PCI/MSI/PPC: Remove arch_msi_check_device()") Cc: stable@vger.kernel.org # v3.18+ Signed-off-by: Radu Rendec Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/msi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/arch/powerpc/kernel/msi.c +++ b/arch/powerpc/kernel/msi.c @@ -34,5 +34,10 @@ void arch_teardown_msi_irqs(struct pci_d { struct pci_controller *phb = pci_bus_to_host(dev->bus); - phb->controller_ops.teardown_msi_irqs(dev); + /* + * We can be called even when arch_setup_msi_irqs() returns -ENOSYS, + * so check the pointer again. + */ + if (phb->controller_ops.teardown_msi_irqs) + phb->controller_ops.teardown_msi_irqs(dev); }