Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1142141imm; Wed, 1 Aug 2018 10:53:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeQRo3ZzK9cJpQ1vD0lV+t/dVeP3MoyzVjoGxUHWDDwAcGFv6uznH/mJ9/qC+AMr955iPex X-Received: by 2002:a17:902:1101:: with SMTP id d1-v6mr16107720pla.131.1533146004886; Wed, 01 Aug 2018 10:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533146004; cv=none; d=google.com; s=arc-20160816; b=RzPs6LhAB6M9bgJifC0cyTE3N0+biXDgzpx9oNKxiDte9pg0Eu/OOhGNAFMHQHD1UU wtOxywkpnYB32w6eDCZRdbeubexBj8CO/DTYu9UYcYNr93K+L8/hd4rniJK9ZOTpt2e7 jRZJRV4xGZR0mF3QnJMWqyBo2//CugRaNSCpqx5MLotWrZGnYpu0wbuOxZNt3lk5zXhZ Ujvo/zakOARphvc7tYT5IcHf0HVt4QSZVVv9TDvljleCDEzzUXDK/9l20waOGRQNwttv R8NjGP/zAWN3K3dPNvOI5nEMVllIppEFGOWO7BVcRQEVHq7PGw7uPdInPskxx23LIjKf 7Irw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UOKMPQbV+RCBqxGapz/kk6DMhdYimIc4sw0L90Q5NHE=; b=tO6FOHlyzG4pq/MniCoyPJtoZCJzEOusvHHf7lo5H+4QRlMq2lAm1ZtM8g4n+3pnYG Jc97dHXPtH4WOs76Tk8QljSG155cUhjCExexw+IKZo01DpubtAL9CF9ukqFdxDF84gBU Vll792l92/r0twVsCdI3/ItN0JgOXkZCf83HIM4J/j8MzC1Mop76oTNmxm0oSX/U39BZ mx4e2PO1iIevfmymE11+fzis+N+UOc/W9xopFhz3KUDdktg47T2OTEpU88fGR+zuddtv AiIn9JA7FsXPbTH6dT/jLKM+AtueUuhsFATS4Z2sqNBkwiNcOt1pWUGJa9ahCOi1Wupp gK7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 f17-v6si16009298pge.494.2018.08.01.10.53.10; Wed, 01 Aug 2018 10:53:24 -0700 (PDT) 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; 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 S2390304AbeHATiF (ORCPT + 99 others); Wed, 1 Aug 2018 15:38:05 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50082 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406036AbeHATIl (ORCPT ); Wed, 1 Aug 2018 15:08:41 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7E4B01379; Wed, 1 Aug 2018 17:13:58 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sam Bobroff , Michael Ellerman , Sasha Levin Subject: [PATCH 4.14 048/246] powerpc/eeh: Fix use-after-release of EEH driver Date: Wed, 1 Aug 2018 18:49:18 +0200 Message-Id: <20180801165014.025848432@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sam Bobroff [ Upstream commit 46d4be41b987a6b2d25a2ebdd94cafb44e21d6c5 ] Correct two cases where eeh_pcid_get() is used to reference the driver's module but the reference is dropped before the driver pointer is used. In eeh_rmv_device() also refactor a little so that only two calls to eeh_pcid_put() are needed, rather than three and the reference isn't taken at all if it wasn't needed. Signed-off-by: Sam Bobroff Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/eeh_driver.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) --- a/arch/powerpc/kernel/eeh_driver.c +++ b/arch/powerpc/kernel/eeh_driver.c @@ -450,9 +450,11 @@ static void *eeh_add_virt_device(void *d driver = eeh_pcid_get(dev); if (driver) { - eeh_pcid_put(dev); - if (driver->err_handler) + if (driver->err_handler) { + eeh_pcid_put(dev); return NULL; + } + eeh_pcid_put(dev); } #ifdef CONFIG_PPC_POWERNV @@ -489,17 +491,19 @@ static void *eeh_rmv_device(void *data, if (eeh_dev_removed(edev)) return NULL; - driver = eeh_pcid_get(dev); - if (driver) { - eeh_pcid_put(dev); - if (removed && - eeh_pe_passed(edev->pe)) - return NULL; - if (removed && - driver->err_handler && - driver->err_handler->error_detected && - driver->err_handler->slot_reset) + if (removed) { + if (eeh_pe_passed(edev->pe)) return NULL; + driver = eeh_pcid_get(dev); + if (driver) { + if (driver->err_handler && + driver->err_handler->error_detected && + driver->err_handler->slot_reset) { + eeh_pcid_put(dev); + return NULL; + } + eeh_pcid_put(dev); + } } /* Remove it from PCI subsystem */