From patchwork Fri Feb 21 07:42:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 230867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 666B9C35641 for ; Fri, 21 Feb 2020 08:23:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3332224697 for ; Fri, 21 Feb 2020 08:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273411; bh=LiJe7Oagm1mNMXF6zMLtUS9MDYRytae+4NbXXsV9DaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ai2S71PyBn/qlBLRAMiLjG/EXqrXd063OPLjvyk2b6Eh3keuZrX3b9PsdlGeFuW40 nt6lV9qrJ/dxvM6Ywxhz4c98HZBPyBIlds9/fAn8qNkqnVc+3e7Da9/B5m/4OCSN1e TsWX4ah7YvDb3D+Oh89Wl5t0YNWinSRnv3Jlfkbk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388241AbgBUIX3 (ORCPT ); Fri, 21 Feb 2020 03:23:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:35522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388486AbgBUIX2 (ORCPT ); Fri, 21 Feb 2020 03:23:28 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 95EA224697; Fri, 21 Feb 2020 08:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273408; bh=LiJe7Oagm1mNMXF6zMLtUS9MDYRytae+4NbXXsV9DaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Us42cI4wy5Ihk+NVP/r4zjhx6ZUr8gV3mjsSPVV3W0pf76uPQfuNokrAyP6OPhBJf wAcusXh3mPvMFhVLCZjvwCtxbiKAPEfPSmVZ52Ap3kL2mSptz3j8NfXKm45r6EVuto 8M0uA8gGbJ68UsvRJv4bQvBuemE1Cnfl0dv0VhoM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver OHalloran , Sam Bobroff , Michael Ellerman , Sasha Levin Subject: [PATCH 4.19 158/191] powerpc/sriov: Remove VF eeh_dev state when disabling SR-IOV Date: Fri, 21 Feb 2020 08:42:11 +0100 Message-Id: <20200221072309.787670966@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Oliver O'Halloran [ Upstream commit 1fb4124ca9d456656a324f1ee29b7bf942f59ac8 ] When disabling virtual functions on an SR-IOV adapter we currently do not correctly remove the EEH state for the now-dead virtual functions. When removing the pci_dn that was created for the VF when SR-IOV was enabled we free the corresponding eeh_dev without removing it from the child device list of the eeh_pe that contained it. This can result in crashes due to the use-after-free. Signed-off-by: Oliver O'Halloran Reviewed-by: Sam Bobroff Tested-by: Sam Bobroff Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20190821062655.19735-1-oohall@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/pci_dn.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c index ab147a1909c8b..7cecc3bd953b7 100644 --- a/arch/powerpc/kernel/pci_dn.c +++ b/arch/powerpc/kernel/pci_dn.c @@ -257,9 +257,22 @@ void remove_dev_pci_data(struct pci_dev *pdev) continue; #ifdef CONFIG_EEH - /* Release EEH device for the VF */ + /* + * Release EEH state for this VF. The PCI core + * has already torn down the pci_dev for this VF, but + * we're responsible to removing the eeh_dev since it + * has the same lifetime as the pci_dn that spawned it. + */ edev = pdn_to_eeh_dev(pdn); if (edev) { + /* + * We allocate pci_dn's for the totalvfs count, + * but only only the vfs that were activated + * have a configured PE. + */ + if (edev->pe) + eeh_rmv_from_parent_pe(edev); + pdn->edev = NULL; kfree(edev); }