All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
	oder_chiou@realtek.com, alsa-devel@alsa-project.org,
	tiwai@suse.com, lgirdwood@gmail.com,
	Mark Brown <broonie@kernel.org>, Lin Ma <linma@zju.edu.cn>
Subject: [PATCH AUTOSEL 4.14 24/29] ASoC: rt5645: Fix errorenous cleanup order
Date: Mon, 30 May 2022 09:50:51 -0400	[thread overview]
Message-ID: <20220530135057.1937286-24-sashal@kernel.org> (raw)
In-Reply-To: <20220530135057.1937286-1-sashal@kernel.org>

From: Lin Ma <linma@zju.edu.cn>

[ 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 <linma@zju.edu.cn>
Link: https://lore.kernel.org/r/20220516092035.28283-1-linma@zju.edu.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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


WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Lin Ma <linma@zju.edu.cn>, Mark Brown <broonie@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	oder_chiou@realtek.com, lgirdwood@gmail.com, perex@perex.cz,
	tiwai@suse.com, alsa-devel@alsa-project.org
Subject: [PATCH AUTOSEL 4.14 24/29] ASoC: rt5645: Fix errorenous cleanup order
Date: Mon, 30 May 2022 09:50:51 -0400	[thread overview]
Message-ID: <20220530135057.1937286-24-sashal@kernel.org> (raw)
In-Reply-To: <20220530135057.1937286-1-sashal@kernel.org>

From: Lin Ma <linma@zju.edu.cn>

[ 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 <linma@zju.edu.cn>
Link: https://lore.kernel.org/r/20220516092035.28283-1-linma@zju.edu.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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


  parent reply	other threads:[~2022-05-30 13:53 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 13:50 [PATCH AUTOSEL 4.14 01/29] drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes Sasha Levin
2022-05-30 13:50 ` Sasha Levin
2022-05-30 13:50 ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 02/29] mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 03/29] b43legacy: Fix assigning negative value to unsigned variable Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 04/29] b43: " Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 05/29] ipw2x00: Fix potential NULL dereference in libipw_xmit() Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 06/29] ACPICA: Avoid cache flush inside virtual machines Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 07/29] ALSA: jack: Access input_dev under mutex Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 08/29] drm/amd/pm: fix double free in si_parse_power_table() Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 09/29] ath9k: fix QCA9561 PA bias level Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 10/29] media: venus: hfi: avoid null dereference in deinit Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 11/29] media: pci: cx23885: Fix the error handling in cx23885_initdev() Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 12/29] media: cx25821: Fix the warning when removing the module Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 13/29] scsi: megaraid: Fix error check return value of register_chrdev() Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 14/29] drm/amd/pm: fix the compile warning Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 15/29] ipv6: Don't send rs packets to the interface of ARPHRD_TUNNEL Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 16/29] ASoC: dapm: Don't fold register value changes into notifications Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 17/29] net: remove two BUG() from skb_checksum_help() Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 18/29] s390/preempt: disable __preempt_count_add() optimization for PROFILE_ALL_BRANCHES Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 19/29] dma-debug: change allocation mode from GFP_NOWAIT to GFP_ATIOMIC Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 20/29] ipmi:ssif: Check for NULL msg when handling events and messages Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 21/29] rtlwifi: Use pr_warn instead of WARN_ONCE Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 22/29] openrisc: start CPU timer early in boot Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 23/29] nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags Sasha Levin
2022-05-30 13:50 ` Sasha Levin [this message]
2022-05-30 13:50   ` [PATCH AUTOSEL 4.14 24/29] ASoC: rt5645: Fix errorenous cleanup order Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 25/29] net: phy: micrel: Allow probing without .driver_data Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 26/29] media: exynos4-is: Fix compile warning Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 27/29] ARM: 9201/1: spectre-bhb: rely on linker to emit cross-section literal loads Sasha Levin
2022-05-30 13:50   ` Sasha Levin
2022-05-30 13:52   ` Ard Biesheuvel
2022-05-30 13:52     ` Ard Biesheuvel
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 28/29] rxrpc: Return an error to sendmsg if call failed Sasha Levin
2022-05-30 13:50 ` [PATCH AUTOSEL 4.14 29/29] eth: tg3: silence the GCC 12 array-bounds warning Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530135057.1937286-24-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linma@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.