From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D27AC76196 for ; Mon, 3 Apr 2023 14:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233212AbjDCOYm (ORCPT ); Mon, 3 Apr 2023 10:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbjDCOYh (ORCPT ); Mon, 3 Apr 2023 10:24:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE50312BD for ; Mon, 3 Apr 2023 07:24:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1086261D82 for ; Mon, 3 Apr 2023 14:24:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20DB5C433EF; Mon, 3 Apr 2023 14:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680531860; bh=VxhM1OT+WAig7YlWhpqE95wvoEoiL9Y9vNk6i21+gVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tT8dn1yFTrmjTN5e+nxAiRtmVSi4kkAaEOAjgNzKjkTKe/tdfjbQjVces2WMGKrPJ B+hYfOleoTnJSnTewzleLw/fqs8gKnvQ+x7cfkGfzGlGbeWI4Otwsts05xsL8ED8BE hb4A/dqGkrVnFKdP42Hh/NMmteZRvgPFA0m8L5CQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zheng Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 034/173] xirc2ps_cs: Fix use after free bug in xirc2ps_detach Date: Mon, 3 Apr 2023 16:07:29 +0200 Message-Id: <20230403140415.484371033@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403140414.174516815@linuxfoundation.org> References: <20230403140414.174516815@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zheng Wang [ Upstream commit e8d20c3ded59a092532513c9bd030d1ea66f5f44 ] In xirc2ps_probe, the local->tx_timeout_task was bounded with xirc2ps_tx_timeout_task. When timeout occurs, it will call xirc_tx_timeout->schedule_work to start the work. When we call xirc2ps_detach to remove the driver, there may be a sequence as follows: Stop responding to timeout tasks and complete scheduled tasks before cleanup in xirc2ps_detach, which will fix the problem. CPU0 CPU1 |xirc2ps_tx_timeout_task xirc2ps_detach | free_netdev | kfree(dev); | | | do_reset | //use dev Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Zheng Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c index 3e337142b5161..56cef59c1c872 100644 --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c @@ -503,6 +503,11 @@ static void xirc2ps_detach(struct pcmcia_device *link) { struct net_device *dev = link->priv; + struct local_info *local = netdev_priv(dev); + + netif_carrier_off(dev); + netif_tx_disable(dev); + cancel_work_sync(&local->tx_timeout_task); dev_dbg(&link->dev, "detach\n"); -- 2.39.2