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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48F4DC433EF for ; Mon, 30 May 2022 13:53:00 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 654761F78; Mon, 30 May 2022 15:52:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 654761F78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1653918778; bh=wwpmpeKtWdv8Qo+7Qoo8H2U5yxSNp0eT7vNgXTst/RQ=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=i7rcAOMVz3IFw0HwAHI30YdqrY3YzPbtPVrWm+tIubsTiX1LSVCzOHsOmd0JqH9CA d7kKvRvBeYmalyhnI2J/Qzll68kjI6a7bICWS6DxNmLD/crq2WZUi02XwFtLzESk9U XVd9mI9BRxpPkG4yIk8/1qKp0FCTMtQWzU/2XDjw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 09DA3F80124; Mon, 30 May 2022 15:52:08 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3A52CF800E5; Mon, 30 May 2022 15:52:06 +0200 (CEST) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 12FDEF800E5 for ; Mon, 30 May 2022 15:52:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 12FDEF800E5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OFT4gRze" 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 451AEB80DC3; Mon, 30 May 2022 13:51:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1257C3411E; Mon, 30 May 2022 13:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918718; bh=wwpmpeKtWdv8Qo+7Qoo8H2U5yxSNp0eT7vNgXTst/RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFT4gRze98WN9UDJdSzhaR6RpvOlPdn3MPg0pxBIbHLWIsiQ/LS5qMKE0hyEVQEYZ YWjbDcx/KIFERVzizKYL3V1buxgNeA26irO2PZdIGRR6gs+MPBUNXS/IexXtzQPxFm Gb3iCMeQ02Ud8MtVVfGSMnM/yYBlkfUaIR4G79z1xxOJGs8ZWH1Tga3ZC63kPg2krE 08Cb+oQ2S+X7Y/3lxQCD7r7EKISuy+rHuHu3ZdRKwYlCnqOo1wB79dT9tqda34Rtna xNvAmg1tZnoIK/mli/vx6LL7fGTGEdjR+7aFH+mSbPAlGgcXOZTsDYgQ8ZNooU3Plr BZ8J4e3DHfYWA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 24/29] ASoC: rt5645: Fix errorenous cleanup order Date: Mon, 30 May 2022 09:50:51 -0400 Message-Id: <20220530135057.1937286-24-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530135057.1937286-1-sashal@kernel.org> References: <20220530135057.1937286-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Cc: Sasha Levin , oder_chiou@realtek.com, alsa-devel@alsa-project.org, tiwai@suse.com, lgirdwood@gmail.com, Mark Brown , Lin Ma X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Lin Ma [ Upstream commit 2def44d3aec59e38d2701c568d65540783f90f2f ] There is a logic error when removing rt5645 device as the function rt5645_i2c_remove() first cancel the &rt5645->jack_detect_work and delete the &rt5645->btn_check_timer latter. However, since the timer handler rt5645_btn_check_callback() will re-queue the jack_detect_work, this cleanup order is buggy. That is, once the del_timer_sync in rt5645_i2c_remove is concurrently run with the rt5645_btn_check_callback, the canceled jack_detect_work will be rescheduled again, leading to possible use-after-free. This patch fix the issue by placing the del_timer_sync function before the cancel_delayed_work_sync. Signed-off-by: Lin Ma Link: https://lore.kernel.org/r/20220516092035.28283-1-linma@zju.edu.cn Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/rt5645.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index a98647ac497c..01de25813c72 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3972,9 +3972,14 @@ static int rt5645_i2c_remove(struct i2c_client *i2c) if (i2c->irq) free_irq(i2c->irq, rt5645); + /* + * Since the rt5645_btn_check_callback() can queue jack_detect_work, + * the timer need to be delted first + */ + del_timer_sync(&rt5645->btn_check_timer); + cancel_delayed_work_sync(&rt5645->jack_detect_work); cancel_delayed_work_sync(&rt5645->rcclock_work); - del_timer_sync(&rt5645->btn_check_timer); snd_soc_unregister_codec(&i2c->dev); regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); -- 2.35.1