Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4448982rwb; Tue, 6 Sep 2022 07:41:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR46D6wLEFeuU49egjQ7H1wL2m0YHt73Ta1wT/9fji8i60IuYVpHN+Nu6xlwo0GuQmxPWJr+ X-Received: by 2002:a17:907:968f:b0:742:1244:b02 with SMTP id hd15-20020a170907968f00b0074212440b02mr24275894ejc.496.1662475314494; Tue, 06 Sep 2022 07:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662475314; cv=none; d=google.com; s=arc-20160816; b=N29CH6ihZGeFJu7seSTYob9epjjiUBB53RTYIXxGF0lFK5+jTni9P8QZTGrtnkpxQX tnfxui4TaNlDirOMZCdYgaE4FAlMmFiQZf9RClgnu9BwDFcS/HNIq0p5jm5ObG8bhCKX btbrByB6ji+2fhx4YpOiPfqrbEUSjhYa6yD57uYYD2NiQx/jr0ZwwkQYMCsDBlUAq/EC 8ZiFh9QYPQQN8jD/QAn6iqSLz6KjUeR63BHeRAqVtforxZt6v27oL8XLWLtrVk7LHcUY nEkLoMtQsoAS4lpQOWFdhZXbzqtRzP9U8gk9u/1Hgp2d5hzbNztiGf/GG/xzN8l7XARG Ug1A== 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=Bl3TtjXMYQc2lGFQa/fjJAqQbyWDPBK/JbLt3Aa9RmA=; b=bqZnXGtFahra5HG2wLMsWPnwFapf0hWf32M9WWO0CfWekbew7gXkdQgVqG8fgSjo0j a/OCSGQLyW/AybwiFkffCCJ1nlt1X2yQ79KWcz5J/BiMRI8QiKsrHCSBiGfnG+YTJZaq Zg2bzxjc8IYdzpa/nhNv9J+2Hs0sdaA3dc6uQYEupdzaX8tKYTBANGNMvY88g64k7c7y hPmazh0fNKrPsGjW5AELZeL/xZjnurmVusaNZmgZWvoFhR1ksMMNDupH2LUNqE9v5Xfl tftssNMh15qf93qYIfat/Q9pBlYXbKz8FlfEHvKdx3LHiejxooTdvwCdKt9phvkV+Hhl GXYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rNMj8yUr; 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 t29-20020a056402241d00b0044e9f2b1df9si3539382eda.151.2022.09.06.07.41.28; Tue, 06 Sep 2022 07:41:54 -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=rNMj8yUr; 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 S240155AbiIFOAX (ORCPT + 99 others); Tue, 6 Sep 2022 10:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239863AbiIFN4N (ORCPT ); Tue, 6 Sep 2022 09:56:13 -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 318FB82843; Tue, 6 Sep 2022 06:42:15 -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 B1D7EB818D7; Tue, 6 Sep 2022 13:42:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B8B6C433C1; Tue, 6 Sep 2022 13:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471727; bh=jOSKa1L8cXAEXeuUyFHShlp+6IoPoZrwu06vY1iCl3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNMj8yUrI3Wf+9ltltiZRfbE1ucGL0oKli/98BHAhdBSm8DJvUqJ/Kp6+phCZXWad JfHwKtE/NZho7wn96XBNlsL+9Kb1k4ij90LIQz72UTPlz+kErNeT7IZ9WhX7dqSbqa xfG4M0mvzpEdrBdeJyFupEouupkdVWwD0g0un040= 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.19 018/155] ieee802154/adf7242: defer destroy_workqueue call Date: Tue, 6 Sep 2022 15:29:26 +0200 Message-Id: <20220906132830.195459255@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@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 6afdf1622944e..5cf218c674a5a 100644 --- a/drivers/net/ieee802154/adf7242.c +++ b/drivers/net/ieee802154/adf7242.c @@ -1310,10 +1310,11 @@ static void 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