Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6820130rwn; Tue, 13 Sep 2022 09:23:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR6mcKYFgwqMhKSXvLoxFOLqrCOwT09tYl1i7r9qVQrxit4EqMGg+ho1o51jxnRiSr6rwfC/ X-Received: by 2002:a17:903:22cd:b0:176:ca53:3e82 with SMTP id y13-20020a17090322cd00b00176ca533e82mr33017449plg.59.1663086236131; Tue, 13 Sep 2022 09:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086236; cv=none; d=google.com; s=arc-20160816; b=KslhZ+i2LgTw0UvRm8b08LyQjAHdarLq1QfRvGU0vOvvlm1/dg0B2SxNcCBP1VYcgF Q6K4h7N7P8dIUVw6UT0Li82ljCqGpb4AqPcVoRvmfTbh8j1h4+CXTK4KrjTKrXRYSNDs PxQZVu+R8gKOPV9ZD+gg1vTEA9l3nE7YVb653IGwufQKKSYwJXxWljthflFp9dco4bLq ztSOqxtEflijEjMi7IuARNYZ07rf3pfCVuIO4EC0GuMdwe5YqyMMcKL56ULScuP+fBQK i2W9I1q5693QL4yWk2NnW/uGxunQsjpjKht9lxoDGtGxEwryiZqDmLCUeHGpH02XfYrH r6xg== 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=fgM6O7UszJklVRmRrL3Jpb00mqeloktq10B/HsRGtPw=; b=pHhedfTVJHdjMZYOMaRryjvNZsU8I8814AGhXu6A6DuqL3ZKFgucf99H59RX+ibYtR A01ObSgAV7SpKh5CojHWrAJx0g+EuKROEsPXsrVBCkUo3oXJoGR6UyufKVXWvu6s+fxH toQRLBNWYcTbS+bxjlODHGlH8ngGyHHYF+7kaBE5PVhXLVr7bsXSXvGEmvgaCKSdkbTc pLcKLQIcbyCHeJlJzr5xcC0jiuS+ffOoKV3+CSPdMEGesHVyDlUc6pyIXmtAxTngyyZj XHqEoMjFfmrvXzRhlI6OPFWoLKj1+basLbnDFsf5+2Bu9KrQl94zlVl+9rgKVDwvuaNp nlCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c6dDT8Cw; 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 r13-20020a65508d000000b00429d2838aa5si1078288pgp.635.2022.09.13.09.23.43; Tue, 13 Sep 2022 09:23:56 -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=c6dDT8Cw; 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 S233508AbiIMPHT (ORCPT + 99 others); Tue, 13 Sep 2022 11:07:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234769AbiIMPEx (ORCPT ); Tue, 13 Sep 2022 11:04:53 -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 1BA316C114; Tue, 13 Sep 2022 07:30:08 -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 4AA8FB80F88; Tue, 13 Sep 2022 14:30:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A190FC433C1; Tue, 13 Sep 2022 14:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079399; bh=kJnMTM4ch+C5OZcgzioPZy99krNqCRBxoSYBe+BzVks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c6dDT8CwM6JfjNWfEvsSuKkF8ZO1So7cZmjWBx169iZGudgZbb/AdpJ6P2EetOgTB 95eXjuo8zYYOjv8gKmdLaEWwnMo1Udaw0W83chzRHQk2jRLTYWtgnziSawUGFe72+h CfB4iONCsNx0ocJ+RiYE35tUw3KQ8kMWI2JeCRC8= 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 4.19 11/79] ieee802154/adf7242: defer destroy_workqueue call Date: Tue, 13 Sep 2022 16:06:29 +0200 Message-Id: <20220913140349.397572900@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140348.835121645@linuxfoundation.org> References: <20220913140348.835121645@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 a686926bba71e..6ef5523f4e717 100644 --- a/drivers/net/ieee802154/adf7242.c +++ b/drivers/net/ieee802154/adf7242.c @@ -1318,10 +1318,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