Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp877208pxb; Fri, 13 Aug 2021 08:15:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJAwwqwcTh+/dqzFFcOvQeTUZod5BevjQZ8u3KaolNwWvxjwOyGtsya19mWsiXGZGPBfXq X-Received: by 2002:aa7:c45a:: with SMTP id n26mr3813096edr.218.1628867734455; Fri, 13 Aug 2021 08:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867734; cv=none; d=google.com; s=arc-20160816; b=ovLC6sVtMuB4wRuT9CZA19zw1+D4Te7yC1vUFdoIeSm3++E2wW6sl76+F9EVaK0ij2 fOotLOsMJUcgSJ/+dtxFCJ9QtIyBgIa+25NghZAE8URnBBSvIwr0HU9lKCNDa7yeKTbr 6IMUamHiUdQp/y0fnUvlo6tG9C+wj9tNcRWhcWFgZNeTMTCU3sA3A9Fs9BVxPCMHSX1n njRDA3RlOo3J8MXLMxkHiWKfQZkvjA9tfMYho9KcQrpc3pQWCByK4gd2xidwLHTUAAyw Zm2uw0zXPnvo8yRl4z+VqP8o7hTtVFn7mrdJmU0jXU+tOZkd8lXIZRO9JmeygHXQpTwL FmXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RJZvRODVOP8Z4HazvE3WaFat7cX5lG15t+htnm010gw=; b=Q5jP2ETqpw8qFXH/TV5k5tX+5jdzXU2VBoAp6+SD1hJSnJNfqr7apFunhDndW9H4Ag IB7o876VNCc6tpvC/NuwrRL0KIZ5BtVD/vTV4BSkUc3Jb/J2RF/S8jUpWvRj3eu9RPzm fxhvF7A0trlUQoKlYTETT+KLgUAzu6cY5gjT9yD+l4jB+S1s3TPOCnkUCr2PuBDo37Ih u5motiGrm78W4+fN8FxIQ0CauqQT/DDYv/3ZSeYQaVpI5aOspukvbD5dxn1t7HlhCkhM 2j3Y8An+mzobQZwT4M+VvqQjr9Ok7py5/FY5MipmeSV3YNDFYzbQzxB4ceaydVjWZV5c e+OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WHR615a3; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si2099895edq.273.2021.08.13.08.15.09; Fri, 13 Aug 2021 08:15:34 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WHR615a3; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241854AbhHMPLF (ORCPT + 99 others); Fri, 13 Aug 2021 11:11:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:53104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241680AbhHMPK2 (ORCPT ); Fri, 13 Aug 2021 11:10:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3093A610CC; Fri, 13 Aug 2021 15:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867401; bh=xnJVZJG8PZGq3xEdTLOJw2KvvZESvI8y51hBAJZ4+N8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHR615a3rCrAmexaWugu9/2ks1lpcflxi0f+vh9QNOOIY8Om+AewE09X57eVJfjc7 D46XmDPJneSerluGjgKFWI8F1KPCbRh2DIIDfCWcFQ5wLcJMrRmCcQnic/DkfYbLOz QNc04LHqXyAS6KxltD5l77jVP4sc76SdnUOZXwhc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Pavel Skripkin , Joakim Zhang , Jesse Brandeburg , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.9 08/30] net: fec: fix use-after-free in fec_drv_remove Date: Fri, 13 Aug 2021 17:06:36 +0200 Message-Id: <20210813150522.713376126@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 44712965bf12ae1758cec4de53816ed4b914ca1a ] Smatch says: drivers/net/ethernet/freescale/fec_main.c:3994 fec_drv_remove() error: Using fep after free_{netdev,candev}(ndev); drivers/net/ethernet/freescale/fec_main.c:3995 fec_drv_remove() error: Using fep after free_{netdev,candev}(ndev); Since fep pointer is netdev private data, accessing it after free_netdev() call can cause use-after-free bug. Fix it by moving free_netdev() call at the end of the function Reported-by: Dan Carpenter Fixes: a31eda65ba21 ("net: fec: fix clock count mis-match") Signed-off-by: Pavel Skripkin Reviewed-by: Joakim Zhang Reviewed-by: Jesse Brandeburg Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 9b3ea0406e0d..5fc40f025d21 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3546,13 +3546,13 @@ fec_drv_remove(struct platform_device *pdev) if (of_phy_is_fixed_link(np)) of_phy_deregister_fixed_link(np); of_node_put(fep->phy_node); - free_netdev(ndev); clk_disable_unprepare(fep->clk_ahb); clk_disable_unprepare(fep->clk_ipg); pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev); + free_netdev(ndev); return 0; } -- 2.30.2