From: Takashi Iwai <tiwai@suse.de>
To: 徐晗翔 <xuhx@hust.edu.cn>
Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Re: sound: timer: snd_utimer_fops lacks .owner, so an open user timer fd does not pin snd-timer
Date: Wed, 25 Nov 2026 15:17:48 +0100 [thread overview]
Message-ID: <87ld6h6lmb.wl-tiwai@suse.de> (raw)
In-Reply-To: <4317d6a0.574.1a212bfe880.Coremail.xuhx@hust.edu.cn>
On Wed, 25 Nov 2026 13:48:16 +0100,
徐晗翔 wrote:
>
> snd_utimer_fops had no .owner, so the anonymous-inode fd created by
> SNDRV_TIMER_IOCTL_CREATE did not hold a reference to the snd-timer
> module: the module could be unloaded while the fd was open, and a
> later SNDRV_TIMER_IOCTL_TRIGGER or close(fd) executed
> snd_utimer_trigger()/snd_utimer_release() from unloaded module
> text. (utimer->timer->module is only consulted by snd_timer_open(),
> which the fd never goes through.)
>
> Add .owner = THIS_MODULE so anon_inode_getfile() pins the module
> for the lifetime of the fd, as upstream does.
Already fixed by the upstream commit f9e882ac8257.
thanks,
Takashi
> ---
> sound/core/timer.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/sound/core/timer.c b/sound/core/timer.c
> --- a/sound/core/timer.c
> +++ b/sound/core/timer.c
> @@ -2173,6 +2173,7 @@
> }
>
> static const struct file_operations snd_utimer_fops = {
> + .owner = THIS_MODULE,
> .llseek = noop_llseek,
> .release = snd_utimer_release,
> .unlocked_ioctl = snd_utimer_ioctl,
>
>
> > -----原始邮件-----
> > 发件人: 徐晗翔 <xuhx@hust.edu.cn>
> > 发送时间:2026-11-22 15:57:29 (星期日)
> > 收件人: perex@perex.cz, tiwai@suse.com
> > 抄送: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
> > 主题: sound: timer: snd_utimer_fops lacks .owner, so an open user timer fd does not pin snd-timer
> >
> > SNDRV_TIMER_IOCTL_CREATE creates a user-driven timer and returns an
> > anonymous inode fd whose file_operations is snd_utimer_fops. That
> > structure has no .owner = THIS_MODULE. anon_inode_getfile() only calls
> > try_module_get(fops->owner) when owner is non-NULL, so the fd does not
> > hold a reference to the snd-timer module. The module can be unloaded
> > while the fd is still open; a later ioctl(SNDRV_TIMER_IOCTL_TRIGGER) or
> > close(fd) calls snd_utimer_trigger()/snd_utimer_release() in unloaded
> > module text.
> >
> > The module field does not save this path: utimer->timer->module is set
> > to THIS_MODULE in snd_timer_new(), but try_module_get() is only called by
> > snd_timer_open(), and a utimer fd never goes through snd_timer_open().
> > snd_utimer_create() also calls snd_timer_new(NULL, ...), so with card ==
> > NULL it does not go through snd_device_new(); snd_timer_global_register()
> > (timer.c:1188-1194) only does the device-list insertion and takes no
> > module reference.
> >
> > This is a static report: the missing .owner and the anon_inode lifetime
> > are unambiguous, but I did not build a dynamic reproducer (it requires
> > CONFIG_SND_TIMER=m together with CONFIG_SND_UTIMER=y).
> >
> > The detailed description:
> >
> > * Test environment / affected version
> >
> > Source analysis against mainline 7.3; no dynamic reproducer was run
> > for this case.
> >
> > * Root cause
> >
> > sound/core/timer.c:2175-2179:
> >
> > static const struct file_operations snd_utimer_fops = {
> > .llseek = noop_llseek,
> > .release = snd_utimer_release,
> > .unlocked_ioctl = snd_utimer_ioctl,
> > };
> >
> > Missing .owner = THIS_MODULE.
> >
> > sound/core/timer.c:2298:
> >
> > timer_fd = anon_inode_getfd(utimer->name, &snd_utimer_fops, utimer,
> > O_RDWR | O_CLOEXEC);
> >
> > fs/anon_inodes.c:141-142:
> >
> > if (fops->owner && !try_module_get(fops->owner))
> > return ERR_PTR(-ENOENT);
> >
> > owner == NULL -> no module reference. utimer->timer->module =
> > THIS_MODULE (timer.c:2252) is only consulted by snd_timer_open(),
> > which the fd does not use; snd_timer_global_register() is just
> > list_add_tail() and does not take a module reference.
> >
> > Upstream snd_utimer_fops has .owner = THIS_MODULE.
> >
> > * Failure model
> >
> > 1. user ioctl SNDRV_TIMER_IOCTL_CREATE -> snd_utimer_create() ->
> > anon_inode_getfd() with the ownerless fops;
> > 2. no other snd-timer user -> rmmod snd-timer succeeds;
> > 3. user calls ioctl(SNDRV_TIMER_IOCTL_TRIGGER) or close(fd);
> > 4. snd_utimer_ioctl()/snd_utimer_release() execute from the unloaded
> > module, and dereference utimer->timer / call snd_timer_interrupt().
> >
> > This is a module-lifetime race, not a data race on a shared field; the
> > concurrency is rmmod vs fd operation.
> >
> > * Trigger model
> >
> > - CONFIG_SND_TIMER=m (module) and CONFIG_SND_UTIMER=y;
> > - a user creates a utimer fd via /dev/snd/timer;
> > - the module is unloaded before the fd is closed;
> > - the fd is used (trigger ioctl) or closed.
> >
> > Requires local access to /dev/snd/timer; no hardware.
> >
> > * Impact
> >
> > - execution of unloaded module code: UAF execution, crash;
> > - if the module address range is reused, potential code execution;
> > - at minimum a local DoS / module-unload race.
> >
> > * Suggested direction
> >
> > Add .owner = THIS_MODULE to snd_utimer_fops. Also consider whether the
> > anon-inode path should hold an explicit module reference for clarity;
> > .owner is the standard fix and matches upstream.
> >
> >
> > Please keep me in Cc; I am not subscribed to the lists.
> >
> > Regards,
> > Hanxiang Xu
> > xuhx@hust.edu.cn
prev parent reply other threads:[~2026-11-25 14:17 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4c7f9772.192e1.1a17d5c2ed5.Coremail.xuhx@hust.edu.cn>
[not found] ` <2026102727-data-sequel-ce41@gregkh>
2026-11-13 11:58 ` ALSA: ctxfi: free atimer only after the timer IRQ is quiesced 徐晗翔
2026-11-13 16:30 ` Takashi Iwai
2026-11-25 12:51 ` [PATCH] Re: " 徐晗翔
2026-11-25 13:00 ` sashiko-bot
2026-11-25 14:33 ` Takashi Iwai
2026-11-13 12:03 ` ALSA: ctxfi: do not free a running system timer when timer_delete_sync_try() returns -1 (UAF) 徐晗翔
2026-11-25 12:51 ` [PATCH] " 徐晗翔
2026-11-25 13:05 ` sashiko-bot
2026-11-25 14:35 ` Takashi Iwai
2026-11-26 2:13 ` 徐晗翔
2026-11-26 2:27 ` sashiko-bot
2026-11-26 7:54 ` Takashi Iwai
2026-11-13 12:04 ` ALSA: asihpi: free IRQ before snd_card_free()/HPI delete on HPI6205 removal (UAF) 徐晗翔
2026-11-25 12:50 ` [PATCH] " 徐晗翔
2026-11-25 13:03 ` sashiko-bot
2026-11-25 14:43 ` Takashi Iwai
2026-11-13 12:06 ` ALSA: asihpi: quiesce PCM timer and IRQ before freeing dpcm on close (UAF) 徐晗翔
2026-11-25 12:50 ` [PATCH] " 徐晗翔
2026-11-25 13:06 ` sashiko-bot
2026-11-25 14:46 ` Takashi Iwai
2026-11-13 12:15 ` ALSA: pcm: link-group walk in timer callback can use a closed substream's freed runtime (UAF) 徐晗翔
2026-11-25 12:55 ` [PATCH] " 徐晗翔
2026-11-25 13:12 ` sashiko-bot
2026-11-25 13:27 ` Takashi Iwai
2026-11-13 12:28 ` ALSA: usb-audio: us144mkii: PCM close frees runtime while playback/feedback URB completion and capture work still use it (UAF) 徐晗翔
2026-11-25 12:48 ` [PATCH] " 徐晗翔
2026-11-25 13:13 ` sashiko-bot
2026-11-25 16:25 ` Takashi Iwai
2026-11-13 12:29 ` ALSA: usb-audio: us144mkii: queued stop_pcm_work calls snd_pcm_stop() after PCM close and dereferences NULL runtime 徐晗翔
2026-11-25 12:49 ` [PATCH] " 徐晗翔
2026-11-25 13:03 ` sashiko-bot
2026-11-22 7:43 ` sound: core: compress offload fd does not pin card or module, so card removal leaves a live fd pointing at freed snd_compr (KASAN UAF) 徐晗翔
2026-11-22 8:07 ` Takashi Iwai
2026-11-25 12:44 ` [PATCH] Re: " 徐晗翔
2026-11-25 14:21 ` Takashi Iwai
2026-11-22 7:48 ` sound: core: jack kcontrol is published before jack_kctl allocation, and the failure path frees it without removing it from card->controls (null-ptr-deref) 徐晗翔
2026-11-24 9:39 ` Sreeraj S Kurup
2026-11-25 12:43 ` 徐晗翔
2026-11-22 7:50 ` sound: core: rawmidi input close can re-queue event_work after cancel_work_sync() (UAF) 徐晗翔
2026-11-24 14:52 ` Krzysztof Kozlowski
2026-11-25 12:45 ` [PATCH] Re: " 徐晗翔
2026-11-25 14:37 ` Takashi Iwai
2026-11-22 7:52 ` sound: core: hwdep DSP_LOAD check-then-act is unlocked, allowing concurrent DSP_LOAD callbacks (UAF) 徐晗翔
2026-11-25 12:46 ` [PATCH] " 徐晗翔
2026-11-25 14:14 ` Takashi Iwai
2026-11-22 7:55 ` sound: core: get_available_index() calls snd_ctl_find_id() without controls_rwsem (UAF risk) 徐晗翔
2026-11-25 12:46 ` [PATCH] " 徐晗翔
2026-11-25 12:51 ` sashiko-bot
2026-11-25 14:18 ` Takashi Iwai
2026-11-22 7:56 ` sound: core: OSS mixer notify callback is invoked without module pin or mutex, racing with rmmod 徐晗翔
2026-11-25 12:47 ` [PATCH] " 徐晗翔
2026-11-25 14:16 ` Takashi Iwai
2026-11-22 7:57 ` sound: timer: snd_utimer_fops lacks .owner, so an open user timer fd does not pin snd-timer 徐晗翔
2026-11-25 12:48 ` [PATCH] " 徐晗翔
2026-11-25 14:17 ` 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=87ld6h6lmb.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=tiwai@suse.com \
--cc=xuhx@hust.edu.cn \
/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