Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: security@nitrohex.com
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] ALSA: timer: Protect the slave instance flags with the timer lock
Date: Thu, 26 Nov 2026 11:00:37 +0100	[thread overview]
Message-ID: <87ld6f6hfe.wl-tiwai@suse.de> (raw)
In-Reply-To: <20261126-alsa-timer-slave-flags-v2-1-8e07a536fea3@nitrohex.com>

On Thu, 26 Nov 2026 10:18:33 +0100,
Rongen Wang via B4 Relay wrote:
> 
> From: Rongen Wang <security@nitrohex.com>
> 
> 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>

Applied now.  Thanks.


Takashi

      reply	other threads:[~2026-11-26 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:18 [PATCH v2] ALSA: timer: Protect the slave instance flags with the timer lock Rongen Wang via B4 Relay
2026-11-26 10:00 ` Takashi Iwai [this message]

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=87ld6f6hfe.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=security@nitrohex.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox