[DragonFlyBSD - Bug #3474] (New) sound: resizing a channel's buffer can free it under a read() or write()

tuxillo bugtracker-admin at leaf.dragonflybsd.org
Thu Nov 19 16:03:08 PST 2026


Issue #3474 has been reported by tuxillo.

----------------------------------------
Bug #3474: sound: resizing a channel's buffer can free it under a read() or write()
http://bugs.dragonflybsd.org/issues/3474

* Author: tuxillo
* Status: New
* Priority: Normal
* Target version: 6.6
* Start date: 2026-11-20
----------------------------------------
As of master d37499e259, an ioctl that resizes a pcm channel's buffer can
free it while a read() or write() on the same channel is still copying to
or from it.

chn_read() and chn_write() drop the channel lock around uiomove(), with
only c->inprog bumped. SNDCTL_DSP_SETBLKSIZE (also SETFRAGMENT, SPEED,
SETFMT and CHANNELS) goes through chn_resizebuf() into sndbuf_remalloc(),
which kfree()s b->buf. chn_resizebuf() only refuses MMAP and TRIGGERED
channels, and only on entry, though it drops the lock twice itself, and
sndbuf_remalloc() drops it again around kmalloc(). So a second thread can
free the buffer from under a copy. Anyone who can open /dev/dsp can do
this, and it's a kernel use-after-free.

FreeBSD had the same problem in FreeBSD-SA-26:88.sound (CVE-2026-127741)
and fixed it in f3afd16367. The attached patch does the same here:
chn_resizebuf() and sndbuf_remalloc() refuse to resize while inprog is
set, including after each place they take the lock back.

The attached blksize_inprog.c blocks a write() in one thread and calls
SETBLKSIZE from another. With the patch the block size stays the same
during the write. With nothing in progress the same ioctl still changes
it (2048 to 8192). I didn't run it on an unpatched kernel, because there
the resize under the writer is the bug itself.

---Files--------------------------------
blksize_inprog.c (2.33 KB)
0001-sound-don-t-resize-a-channel-s-buffer-during-a-read-.patch (3.93 KB)


-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account


More information about the Bugs mailing list