Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6817927rwn; Tue, 13 Sep 2022 09:22:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR62D8qSmYJYEWS5B8ysjkqzRCDd0/AfuCZk42yEI6GU04vGZ8NNhDN63Qidr/bmttYkZC66 X-Received: by 2002:a17:902:9a92:b0:178:2580:ce60 with SMTP id w18-20020a1709029a9200b001782580ce60mr14863058plp.80.1663086133895; Tue, 13 Sep 2022 09:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086133; cv=none; d=google.com; s=arc-20160816; b=mqwCcW9189KnrExAXUtxAjA+87gMyBKvyqSF6SepKMGKM2e4LoigzAajWI0C92+smC M/VsjprH9RYzo7dQKzcBYNUmnkZzdH7snfIf3CSpC8hiFDNdxRs6rXAEwm0ZY/upsgjo CPx9juzhDsrcqBSnEi1hsmTOE/ziSCg1GsvsVTlDlN+PCs5KrAdiBG0ISjCLOoSbVQ91 wg0vQypJ3L+wtTgVw9eR1GQg8l/f/7w6tbNzOa0ApXC1lt/B+9DpzAB7Txx+vs0XDOIj cXFF1iYz0loOTE0iV0Sb640484CkiprYpmWw7Crzx5SwtGVTgicj85s7ztgjRKjQH4JG OxZA== 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=e807cvjlJoW2YayrKXhm9EKW0Jh8E6yyGmpsw+cgqRg=; b=vcbl5T6878xYetnC4ybA0HpKDQnHoR/TPu9ESjswHubh/7MxHFPVz7eoplhnvaJ31p TrU2M4bLk+V5eeA62R6LIG26WR93ZG/Xwk9y1F3bGboP/DaOuO9Q1yPk1rMhcOvxrTHG CEf2QDHLuyWmIUbfiPupPSx8G97aTAQ2gBGCelB32G3PpL5ytRQbhOOxB2SZV5srHRky ydUsdYEIlyhox3HmYLN6D32SuenmaIzYgjCpes7DMZiVWzSaYhoSJxDMXPdK3AoOgw9N qOrfCvZMdFI/HBW5rDgcfKm19MIpvE0l54ijpf8KFhwmAJS4yZiqX0aIA0d2ek1t6D4c eW7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fbOdkVFU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm12-20020a17090b3ecc00b001fa55447988si1960470pjb.40.2022.09.13.09.22.02; Tue, 13 Sep 2022 09:22:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fbOdkVFU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232396AbiIMOxE (ORCPT + 99 others); Tue, 13 Sep 2022 10:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234658AbiIMOtW (ORCPT ); Tue, 13 Sep 2022 10:49:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E232871724; Tue, 13 Sep 2022 07:25:42 -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 ams.source.kernel.org (Postfix) with ESMTPS id 71C04B80F98; Tue, 13 Sep 2022 14:25:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C39C5C433B5; Tue, 13 Sep 2022 14:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079119; bh=WUvIG/wjb+NHZ795L5NT+jyIBxzqlNnQlcGfumrnbqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbOdkVFUR1SzKvuYBGr9kH87am/TBGe+aZOWnDku6g8Mm7zrgsfFfmNmez/cuqC80 8Jho/8ffaRCh4ciNxqtPZKoBnLlA9+ldG5NLcbjByLin/bEcxGviq+kxM4X9YYO7SY jqgwcIquBAn2WbgpXx4ifI4jidiLw7+uISMGSAcY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Ma , Michael Hennerich , Stefan Schmidt , Sasha Levin Subject: [PATCH 5.4 011/108] ieee802154/adf7242: defer destroy_workqueue call Date: Tue, 13 Sep 2022 16:05:42 +0200 Message-Id: <20220913140354.042864730@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lin Ma [ Upstream commit afe7116f6d3b888778ed6d95e3cf724767b9aedf ] There is a possible race condition (use-after-free) like below (FREE) | (USE) adf7242_remove | adf7242_channel cancel_delayed_work_sync | destroy_workqueue (1) | adf7242_cmd_rx | mod_delayed_work (2) | The root cause for this race is that the upper layer (ieee802154) is unaware of this detaching event and the function adf7242_channel can be called without any checks. To fix this, we can add a flag write at the beginning of adf7242_remove and add flag check in adf7242_channel. Or we can just defer the destructive operation like other commit 3e0588c291d6 ("hamradio: defer ax25 kfree after unregister_netdev") which let the ieee802154_unregister_hw() to handle the synchronization. This patch takes the second option. Fixes: 58e9683d1475 ("net: ieee802154: adf7242: Fix OCL calibration runs") Signed-off-by: Lin Ma Acked-by: Michael Hennerich Link: https://lore.kernel.org/r/20220808034224.12642-1-linma@zju.edu.cn Signed-off-by: Stefan Schmidt Signed-off-by: Sasha Levin --- drivers/net/ieee802154/adf7242.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ieee802154/adf7242.c b/drivers/net/ieee802154/adf7242.c index 5945ac5f38eea..cb29da961e12b 100644 --- a/drivers/net/ieee802154/adf7242.c +++ b/drivers/net/ieee802154/adf7242.c @@ -1310,10 +1310,11 @@ static int adf7242_remove(struct spi_device *spi) debugfs_remove_recursive(lp->debugfs_root); + ieee802154_unregister_hw(lp->hw); + cancel_delayed_work_sync(&lp->work); destroy_workqueue(lp->wqueue); - ieee802154_unregister_hw(lp->hw); mutex_destroy(&lp->bmux); ieee802154_free_hw(lp->hw); -- 2.35.1