* [PATCH] ALSA: timer: Clear SNDRV_TIMER_IFLG_DEAD once the close completes
@ 2026-07-26 8:01 Norbert Szetei
2026-07-26 14:12 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Norbert Szetei @ 2026-07-26 8:01 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Iwai, Jaroslav Kysela
snd_timer_close_locked() marks an instance with SNDRV_TIMER_IFLG_DEAD
and returns early when the flag is already set, but the flag is never
cleared again. A completed close ends in remove_slave_links(), which
leaves timeri->timer NULL, so a second close is already harmless through
the timer == NULL path; the early return can only be reached by an
instance that was opened again in between. For such an instance the
close unlinks nothing, so snd_timer_instance_free() frees an object that
is still on timer->open_list_head, still on snd_timer_master_list if it
was opened with a slave key, still owns any adopted slaves, and still
holds its timer and module references.
snd_seq_timer_open() reopens an instance exactly like that: it retries
its fallback open on the same object after a failure that has already
run snd_timer_close_locked() internally. An unprivileged user with
access to /dev/snd/timer and /dev/snd/seq can force that failure, since
snd_timer_check_master() returns -EBUSY when a pending slave matches the
new master's (slave_class, slave_id) key and the target timer has
reached max_instances, and SNDRV_TIMER_IOCTL_SELECT with dev_class =
SNDRV_TIMER_CLASS_SLAVE keeps the caller-supplied dev_sclass, so a
sequencer queue's key can be forged. The freed instance is afterwards
dereferenced by any further snd_timer_open() on that timer, by
snd_timer_check_slave(), and by /proc/asound/timers, which faults on the
stale ti->owner pointer.
The flag only has to be visible while the close is in progress, which is
all its other users need. Clear it in remove_slave_links(), under the
same timer->lock that sets it, once the instance is off every list.
Fixes: da3039e91d1f ("ALSA: timer: Forcibly close timer instances at closing")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
---
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 07ef127b29e1..9407954034cf 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -458,6 +458,8 @@ static void remove_slave_links(struct snd_timer_instance *timeri,
list_del_init(&slave->ack_list);
list_del_init(&slave->active_list);
}
+ /* the close is done; a reopen must not see the mark */
+ timeri->flags &= ~SNDRV_TIMER_IFLG_DEAD;
}
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: timer: Clear SNDRV_TIMER_IFLG_DEAD once the close completes
2026-07-26 8:01 [PATCH] ALSA: timer: Clear SNDRV_TIMER_IFLG_DEAD once the close completes Norbert Szetei
@ 2026-07-26 14:12 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-07-26 14:12 UTC (permalink / raw)
To: Norbert Szetei; +Cc: linux-sound, Takashi Iwai, Jaroslav Kysela
On Sun, 26 Jul 2026 10:01:45 +0200,
Norbert Szetei wrote:
>
> snd_timer_close_locked() marks an instance with SNDRV_TIMER_IFLG_DEAD
> and returns early when the flag is already set, but the flag is never
> cleared again. A completed close ends in remove_slave_links(), which
> leaves timeri->timer NULL, so a second close is already harmless through
> the timer == NULL path; the early return can only be reached by an
> instance that was opened again in between. For such an instance the
> close unlinks nothing, so snd_timer_instance_free() frees an object that
> is still on timer->open_list_head, still on snd_timer_master_list if it
> was opened with a slave key, still owns any adopted slaves, and still
> holds its timer and module references.
>
> snd_seq_timer_open() reopens an instance exactly like that: it retries
> its fallback open on the same object after a failure that has already
> run snd_timer_close_locked() internally. An unprivileged user with
> access to /dev/snd/timer and /dev/snd/seq can force that failure, since
> snd_timer_check_master() returns -EBUSY when a pending slave matches the
> new master's (slave_class, slave_id) key and the target timer has
> reached max_instances, and SNDRV_TIMER_IOCTL_SELECT with dev_class =
> SNDRV_TIMER_CLASS_SLAVE keeps the caller-supplied dev_sclass, so a
> sequencer queue's key can be forged. The freed instance is afterwards
> dereferenced by any further snd_timer_open() on that timer, by
> snd_timer_check_slave(), and by /proc/asound/timers, which faults on the
> stale ti->owner pointer.
>
> The flag only has to be visible while the close is in progress, which is
> all its other users need. Clear it in remove_slave_links(), under the
> same timer->lock that sets it, once the instance is off every list.
>
> Fixes: da3039e91d1f ("ALSA: timer: Forcibly close timer instances at closing")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Norbert Szetei <norbert@doyensec.com>
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-26 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-26 8:01 [PATCH] ALSA: timer: Clear SNDRV_TIMER_IFLG_DEAD once the close completes Norbert Szetei
2026-07-26 14:12 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox