Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4466826rwb; Tue, 6 Sep 2022 07:58:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR5iHG7jDviVUUlOJdmjYzMRpGBS2o5Obg6VlSQaxXV4RT6NewwLQdu8lniFk3dq6goEZnxg X-Received: by 2002:a05:6402:510a:b0:43d:ab25:7d68 with SMTP id m10-20020a056402510a00b0043dab257d68mr47266267edd.102.1662476316471; Tue, 06 Sep 2022 07:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476316; cv=none; d=google.com; s=arc-20160816; b=vdAKxPjrmQlpJ7Rf5qnXy8ge/p0VbCKYpqZbXksHK3LKbNn462pML1xrQhCKLW9Q8n htGCxT3bevZka+lof8NLgYJxTELMuy5g7+fcOn4ieWSbR/ZS+jwBM1snYY3Df4/L+weW uwFjm2pzJzNNXivBQSOYlI2pxFQ7jJGWgGpXs0Ht5sBSs9n+9JUo+n8ZuVYy4pyCJ/Bh gy+TfjVmS7iq4EeSyzxwrultvDLfql4rRboNt77wskzMEgoNkP5mywASCb/sCKWB4/Fq K9GTfNIcLixJz9pkCKV0ETrYkWYruKH5etpiqinHlmZccwqY4vt3GtPXvkcveEGHFlw6 JkKg== 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=H6IDl5s6TpQIelNehIJKB9MSh8OpSIZciP8INROHAqU=; b=nvH0TbARxOqWOZMUFs0P2LL0VR099O3DJ24CV7cFM9G/SRWCI86uT/azyNZsh2hD2W aeobVAkF72mJA05Vx5BV4IR7I3/1ntsddKDro1A0np1B216oUTOIznH/9Ttj0osBBY2p DX42/Z183+gUpBMbD+TUToSVK6i2OPtPSDVcEBHsFaFC/PDQKctArflqbJRe8NVmSNmh fh7A0+4M2tWg3/C2PfGx3GZoxrQrtT7G3fwZpyDKqI9LgowlJMKlWErIY9DWkyvO1mLZ 2BlAkHklQj+OFZw6tJcIL0sUKfsOh6mypY6EeauCrqNwsfd+MkKGs7bHJbOA88H7CBSy ATig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JM8ol1pV; 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 fp32-20020a1709069e2000b00741795a8603si8434078ejc.196.2022.09.06.07.58.10; Tue, 06 Sep 2022 07:58:36 -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=JM8ol1pV; 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 S240694AbiIFNfe (ORCPT + 99 others); Tue, 6 Sep 2022 09:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240486AbiIFNdK (ORCPT ); Tue, 6 Sep 2022 09:33:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2277D77EAE; Tue, 6 Sep 2022 06:32:54 -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 sin.source.kernel.org (Postfix) with ESMTPS id 1432ACE177C; Tue, 6 Sep 2022 13:32:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFCB3C433C1; Tue, 6 Sep 2022 13:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471170; bh=DYrtkXiQza9h+75zfjAgmyJGhHTmwWzGOk0Ftwk6pR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JM8ol1pVZWH/QecONSEZZgdkfFWbWtTNjZIxERVK/KZWUcSj55L6JoqKdVu+GlaTM EWD3i8KiJx2TmAaESk7jeuG47fgAm0jiUWaiOr/f+MZooxqX75f+KO4iFVCBLqUOQp d18WaNpLM95qDRhr/nbyu7wvO8R3iTmUHUCZwdkY= 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.10 08/80] ieee802154/adf7242: defer destroy_workqueue call Date: Tue, 6 Sep 2022 15:30:05 +0200 Message-Id: <20220906132817.269760422@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@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 7db9cbd0f5ded..07adbeec19787 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