* FAILED: patch "[PATCH] ALSA: timer: Protect the slave instance flags with the timer" failed to apply to 6.6-stable tree
@ 2026-12-03 3:44 gregkh
2026-12-04 13:23 ` [PATCH 6.6.y] ALSA: timer: Protect the slave instance flags with the timer lock Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2026-12-03 3:44 UTC (permalink / raw)
To: security, tiwai; +Cc: stable
The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 8e324d767bdc5ab38b0e1e921e786ff9ea514188
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120318-sushi-relax-0fc7@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8e324d767bdc5ab38b0e1e921e786ff9ea514188 Mon Sep 17 00:00:00 2001
From: Rongen Wang <security@nitrohex.com>
Date: Thu, 26 Nov 2026 18:18:33 +0900
Subject: [PATCH] ALSA: timer: Protect the slave instance flags with the timer
lock
snd_timer_start_slave() and snd_timer_stop_slave() set and clear
SNDRV_TIMER_IFLG_RUNNING in timeri->flags while holding only
timeri_lock. For a slave that is linked to a master, the interrupt
path updates the same word under timer->lock:
snd_timer_process_callbacks() sets SNDRV_TIMER_IFLG_CALLBACK before it
calls the instance callback and clears it afterwards. Both sides do a
plain read-modify-write, so when they overlap one of the two updates is
lost.
If the set of SNDRV_TIMER_IFLG_CALLBACK is lost,
snd_timer_close_locked() does not wait for the callback that is still
running, the owner frees the instance, and the interrupt path clears
the flag in the freed object:
BUG: KASAN: slab-use-after-free in snd_timer_process_callbacks+0x269/0x2b0
Read of size 4 at addr ffff888007e5cc10 by task poc/90
snd_timer_process_callbacks+0x269/0x2b0
snd_timer_interrupt+0x7b8/0x1100
snd_utimer_ioctl+0x7c/0xb0
Freed by task 91:
kfree+0x127/0x3b0
__snd_timer_user_ioctl.isra.0+0xe93/0x28f0
If the clear is lost instead, the flag stays set: the instance gets no
further callbacks, and closing it spins in the drain loop of
snd_timer_close_locked() with register_mutex held, which blocks every
other open and close of an ALSA timer.
Take timer->lock around the whole flag update of a linked slave, as
snd_timer_start1() and snd_timer_stop1() do for master instances. The
callers hold timeri_lock, so timeri->timer is stable, and the lock
order is the one these functions already use. A slave that is not
linked to a master cannot be reached from any timer and needs no
additional protection.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Rongen Wang <security@nitrohex.com>
Link: https://patch.msgid.link/20261126-alsa-timer-slave-flags-v2-1-8e07a536fea3@nitrohex.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 905176bf6948..50e31827d9ff 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -657,9 +657,12 @@ static int snd_timer_start1(struct snd_timer_instance *timeri,
return result;
}
-/* start/continue a slave timer */
-static int snd_timer_start_slave(struct snd_timer_instance *timeri,
- bool start)
+/*
+ * start/continue a slave timer;
+ * called with timer->lock held when the slave is linked to a master
+ */
+static int __snd_timer_start_slave(struct snd_timer_instance *timeri,
+ bool start)
{
if (timeri->flags & SNDRV_TIMER_IFLG_DEAD)
return -EINVAL;
@@ -667,7 +670,6 @@ static int snd_timer_start_slave(struct snd_timer_instance *timeri,
return -EBUSY;
timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
if (timeri->master && timeri->timer) {
- guard(spinlock)(&timeri->timer->lock);
list_add_tail(&timeri->active_list,
&timeri->master->slave_active_head);
snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START :
@@ -676,6 +678,27 @@ static int snd_timer_start_slave(struct snd_timer_instance *timeri,
return 1; /* delayed start */
}
+/*
+ * start/continue a slave timer
+ *
+ * The flags of a slave linked to a master are updated also from the timer
+ * interrupt (SNDRV_TIMER_IFLG_CALLBACK in snd_timer_process_callbacks())
+ * under timer->lock. Change them only under the same lock, otherwise one
+ * of the two read-modify-write updates may get lost. The caller holds
+ * timeri_lock, hence timeri->timer can't change here; an unlinked slave is
+ * not reachable from any timer and needs no further protection.
+ */
+static int snd_timer_start_slave(struct snd_timer_instance *timeri,
+ bool start)
+{
+ struct snd_timer *timer = timeri->timer;
+
+ if (!timer)
+ return __snd_timer_start_slave(timeri, start);
+ guard(spinlock)(&timer->lock);
+ return __snd_timer_start_slave(timeri, start);
+}
+
/* stop/pause a master timer */
static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop)
{
@@ -718,15 +741,17 @@ static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop)
return 0;
}
-/* stop/pause a slave timer */
-static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
+/*
+ * stop/pause a slave timer;
+ * called with timer->lock held when the slave is linked to a master
+ */
+static int __snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
{
bool running;
running = timeri->flags & SNDRV_TIMER_IFLG_RUNNING;
timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
if (timeri->timer) {
- guard(spinlock)(&timeri->timer->lock);
list_del_init(&timeri->ack_list);
list_del_init(&timeri->active_list);
if (running)
@@ -736,6 +761,17 @@ static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
return running ? 0 : -EBUSY;
}
+/* stop/pause a slave timer; see snd_timer_start_slave() for the locking */
+static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
+{
+ struct snd_timer *timer = timeri->timer;
+
+ if (!timer)
+ return __snd_timer_stop_slave(timeri, stop);
+ guard(spinlock)(&timer->lock);
+ return __snd_timer_stop_slave(timeri, stop);
+}
+
/*
* start the timer instance
*/
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH 6.6.y] ALSA: timer: Protect the slave instance flags with the timer lock
2026-12-03 3:44 FAILED: patch "[PATCH] ALSA: timer: Protect the slave instance flags with the timer" failed to apply to 6.6-stable tree gregkh
@ 2026-12-04 13:23 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-12-04 13:23 UTC (permalink / raw)
To: stable; +Cc: Rongen Wang, Takashi Iwai, Sasha Levin
From: Rongen Wang <security@nitrohex.com>
[ Upstream commit 8e324d767bdc5ab38b0e1e921e786ff9ea514188 ]
snd_timer_start_slave() and snd_timer_stop_slave() set and clear
SNDRV_TIMER_IFLG_RUNNING in timeri->flags while holding only
timeri_lock. For a slave that is linked to a master, the interrupt
path updates the same word under timer->lock:
snd_timer_process_callbacks() sets SNDRV_TIMER_IFLG_CALLBACK before it
calls the instance callback and clears it afterwards. Both sides do a
plain read-modify-write, so when they overlap one of the two updates is
lost.
If the set of SNDRV_TIMER_IFLG_CALLBACK is lost,
snd_timer_close_locked() does not wait for the callback that is still
running, the owner frees the instance, and the interrupt path clears
the flag in the freed object:
BUG: KASAN: slab-use-after-free in snd_timer_process_callbacks+0x269/0x2b0
Read of size 4 at addr ffff888007e5cc10 by task poc/90
snd_timer_process_callbacks+0x269/0x2b0
snd_timer_interrupt+0x7b8/0x1100
snd_utimer_ioctl+0x7c/0xb0
Freed by task 91:
kfree+0x127/0x3b0
__snd_timer_user_ioctl.isra.0+0xe93/0x28f0
If the clear is lost instead, the flag stays set: the instance gets no
further callbacks, and closing it spins in the drain loop of
snd_timer_close_locked() with register_mutex held, which blocks every
other open and close of an ALSA timer.
Take timer->lock around the whole flag update of a linked slave, as
snd_timer_start1() and snd_timer_stop1() do for master instances. The
callers hold timeri_lock, so timeri->timer is stable, and the lock
order is the one these functions already use. A slave that is not
linked to a master cannot be reached from any timer and needs no
additional protection.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Rongen Wang <security@nitrohex.com>
Link: https://patch.msgid.link/20261126-alsa-timer-slave-flags-v2-1-8e07a536fea3@nitrohex.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
[ sashal: Inlined the slave locking in the start and stop paths, taking slave_active_lock then timer->lock, because this tree has no guard() helpers or timeri_lock for upstream's wrappers. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
sound/core/timer.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/sound/core/timer.c b/sound/core/timer.c
index e7cf47104257f..fc208d2bce178 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -596,10 +596,14 @@ static int snd_timer_start1(struct snd_timer_instance *timeri,
static int snd_timer_start_slave(struct snd_timer_instance *timeri,
bool start)
{
+ struct snd_timer *timer;
unsigned long flags;
int err;
spin_lock_irqsave(&slave_active_lock, flags);
+ timer = timeri->timer;
+ if (timer)
+ spin_lock(&timer->lock);
if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) {
err = -EINVAL;
goto unlock;
@@ -609,16 +613,16 @@ static int snd_timer_start_slave(struct snd_timer_instance *timeri,
goto unlock;
}
timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
- if (timeri->master && timeri->timer) {
- spin_lock(&timeri->timer->lock);
+ if (timeri->master && timer) {
list_add_tail(&timeri->active_list,
&timeri->master->slave_active_head);
snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START :
SNDRV_TIMER_EVENT_CONTINUE);
- spin_unlock(&timeri->timer->lock);
}
err = 1; /* delayed start */
unlock:
+ if (timer)
+ spin_unlock(&timer->lock);
spin_unlock_irqrestore(&slave_active_lock, flags);
return err;
}
@@ -674,20 +678,23 @@ static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop)
/* stop/pause a slave timer */
static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
{
+ struct snd_timer *timer;
unsigned long flags;
bool running;
spin_lock_irqsave(&slave_active_lock, flags);
+ timer = timeri->timer;
+ if (timer)
+ spin_lock(&timer->lock);
running = timeri->flags & SNDRV_TIMER_IFLG_RUNNING;
timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
- if (timeri->timer) {
- spin_lock(&timeri->timer->lock);
+ if (timer) {
list_del_init(&timeri->ack_list);
list_del_init(&timeri->active_list);
if (running)
snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP :
SNDRV_TIMER_EVENT_PAUSE);
- spin_unlock(&timeri->timer->lock);
+ spin_unlock(&timer->lock);
}
spin_unlock_irqrestore(&slave_active_lock, flags);
return running ? 0 : -EBUSY;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 13:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 3:44 FAILED: patch "[PATCH] ALSA: timer: Protect the slave instance flags with the timer" failed to apply to 6.6-stable tree gregkh
2026-12-04 13:23 ` [PATCH 6.6.y] ALSA: timer: Protect the slave instance flags with the timer lock Sasha Levin
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.