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.0 required=3.0 tests=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 AE223C04AB6 for ; Fri, 31 May 2019 19:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9239F26D87 for ; Fri, 31 May 2019 19:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727164AbfEaTQL (ORCPT ); Fri, 31 May 2019 15:16:11 -0400 Received: from sed198n136.SEDSystems.ca ([198.169.180.136]:44724 "EHLO sed198n136.sedsystems.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726807AbfEaTQL (ORCPT ); Fri, 31 May 2019 15:16:11 -0400 Received: from barney.sedsystems.ca (barney [198.169.180.121]) by sed198n136.sedsystems.ca with ESMTP id x4VJGAqE005235 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 31 May 2019 13:16:10 -0600 (CST) Received: from SED.RFC1918.192.168.sedsystems.ca (eng1n65.eng.sedsystems.ca [172.21.1.65]) by barney.sedsystems.ca (8.14.7/8.14.4) with ESMTP id x4VJG6dn007508 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 31 May 2019 13:16:10 -0600 From: Robert Hancock To: netdev@vger.kernel.org Cc: Robert Hancock Subject: [PATCH net-next] net: phy: Ensure scheduled work is cancelled during removal Date: Fri, 31 May 2019 13:15:50 -0600 Message-Id: <1559330150-30099-2-git-send-email-hancock@sedsystems.ca> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559330150-30099-1-git-send-email-hancock@sedsystems.ca> References: <1559330150-30099-1-git-send-email-hancock@sedsystems.ca> X-Scanned-By: MIMEDefang 2.64 on 198.169.180.136 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is possible that scheduled work started by the PHY driver is still outstanding when phy_device_remove is called if the PHY was initially started but never connected, and therefore phy_disconnect is never called. phy_stop does not guarantee that the scheduled work is stopped because it is called under rtnl_lock. This can cause an oops due to use-after-free if the delayed work fires after freeing the PHY device. Ensure that the state_queue work is cancelled in both phy_device_remove and phy_remove paths. Signed-off-by: Robert Hancock --- drivers/net/phy/phy_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2c879ba..1c90b33 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -877,6 +877,8 @@ int phy_device_register(struct phy_device *phydev) */ void phy_device_remove(struct phy_device *phydev) { + cancel_delayed_work_sync(&phydev->state_queue); + device_del(&phydev->mdio.dev); /* Assert the reset signal */ -- 1.8.3.1