opnsense-src/sys/dev/sound
Mark Johnston cf42166fdd sound: Revalidate after reacquiring locks when resizing buffers
sndbuf_resize() and sndbuf_remalloc() drop the channel lock in order to
allocate the new buffer(s) with M_WAITOK.  Before doing that they verify
that the buffer is not mapped, but this could change while the lock is
dropped, as there is no higher-level synchronization which prevents
buffer resize (e.g., via the SNDCTL_DSP_SETBLKSIZE ioctl) from happening
concurrently with mmap.  Thus, these checks are insufficient.

Modify sndbuf_resize() and sndbuf_remalloc() to revalidate after
reacquiring the lock.  Extend them to check for a couple of channel
flags, mirroring the check in chn_resizebuf().  Modify chn_resizebuf()
to revalidate state after reacquiring the channel lock.

We could also allocate new buffers with M_NOWAIT and so avoid dropping
the lock.  Then, I think we could go even further and invoke
CHANNEL_SETBLOCKSIZE and CHANNEL_SETFRAGMENTS with the channel lock
held.  But really it would be better to ensure that dsp operations are
serialized; there is no reason for mmap and chn_resizebuf() to be able
to run in parallel, we should not be relying on the channel lock for
this.  So, let's keep a more minimal approach here.

Add a simple regression test.

Approved by:	so
Security:	FreeBSD-SA-26:71.sound
Security:	CVE-2026-101308
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D60554
2026-10-15 11:28:55 +02:00
..
fdt sound: Do not check for NULL before free() 2026-01-10 00:27:24 +01:00
isa
macio chore: replace {0, 0} with {DEV,KOBJ}METHOD_END 2026-04-25 09:46:07 -07:00
midi sound: Match midi_write() return values with midi_read() 2026-03-31 11:53:16 +02:00
pci sound: Check for errors from sndbuf_resize() 2026-10-15 11:28:53 +02:00
pcm sound: Revalidate after reacquiring locks when resizing buffers 2026-10-15 11:28:55 +02:00
usb sound: Check for errors from sndbuf_resize() 2026-10-15 11:28:53 +02:00
driver.c sound: Include ai2s and davbus for PowerPC 2024-11-10 02:44:14 +00:00
dummy.c sound: Do not check for NULL before free() 2026-01-10 00:27:24 +01:00
sndstat.c sound: Retire CHN_GETVOLUME() and use chn_getvolume_matrix() 2026-03-31 11:53:17 +02:00
sndstat.h sound: Take device type into account in sndstat 2026-01-10 00:27:24 +01:00