]> git.hungrycats.org Git - linux/commit
ALSA: timer: Manage timer object with kref
authorTakashi Iwai <tiwai@suse.de>
Tue, 9 Jun 2026 11:50:53 +0000 (13:50 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 10 Jun 2026 07:36:28 +0000 (09:36 +0200)
commitccd0db6671d2cae986b2daa1c538b6d541a9d62c
treec46c45e75df4d63b18a19bdd8ebf02ddf6deacc4
parent98e157916f83c26a41448267180944048d2f1460
ALSA: timer: Manage timer object with kref

So far we've tried to address UAFs in ALSA timer code by applying the
locks at various places, but the fundamental problem is that the timer
object may be released while the belonging timer instance objects are
still present and accessing to it.  This patch is a more proper fix to
address that issue, namely, by refcounting and keeping the timer
object.

The basic implementation is to use kref for the refcount of the timer
object, and take/release the reference at assigning/releasing the
instance, as well as at referring from ioctls or ALSA sequencer code.
The reference from ioctl or ALSA sequencer is abstracted with
snd_timeri_timer auto-cleanup.

Note that this change assumes that the code already took the fix
commit da3039e91d1f ("ALSA: timer: Forcibly close timer instances at
closing"); otherwise the refcount may be unbalanced when the timer is
freed while slave instances are still present.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260609115100.806869-2-tiwai@suse.de
include/sound/timer.h
sound/core/seq/seq_timer.c
sound/core/timer.c
sound/core/timer_compat.c