aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2026-11-12 19:25:58 +0000
committerMark Johnston <markj@FreeBSD.org>2026-11-16 21:25:03 +0000
commit2c29a955d3143c4916b2a7d002979386f428b15b (patch)
treed9080967a4881f5fb911dda797858806ab036662
parentde7f7d5ea9595bfc504fc491c898cd5ca4b6c429 (diff)
sound: Improve interlocking in chn_resizebuf()
chn_resizebuf() fails if the channel's software buffer is mapped, but does not take into account the fact that channel I/O drops the channel lock when copying from or to user memory. During the window where the lock is dropped, a resize may free the old buffer, causing userspace to access freed kernel memory. This can be exploited to escalate privileges. Fix this by disallowing resizing when I/O is in progress. Approved by: so Security: FreeBSD-SA-26:88.sound Security: CVE-2026-127741 Reviewed by: christos, kib Reported by: OpenAI Security Research Team Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D61446
-rw-r--r--sys/dev/sound/pcm/buffer.c1
-rw-r--r--sys/dev/sound/pcm/channel.c16
2 files changed, 12 insertions, 5 deletions
diff --git a/sys/dev/sound/pcm/buffer.c b/sys/dev/sound/pcm/buffer.c
index 9e212f646737..c81876758c6f 100644
--- a/sys/dev/sound/pcm/buffer.c
+++ b/sys/dev/sound/pcm/buffer.c
@@ -94,6 +94,7 @@ sndbuf_busy(struct snd_dbuf *b)
return (refcount_load(&b->refcount) > 1 ||
(b->flags & SNDBUF_F_DETACHED) != 0 ||
+ b->channel->inprog != 0 ||
/*
* XXX-MJ CHN_F_MMAP is not reliable, but for software buffers the
* refcount accurately reflects whether the buffer is mapped.
diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
index dfebdaefbaeb..7dcf6a2e58d0 100644
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -1814,9 +1814,15 @@ chn_calclatency(int dir, int latency, int bps, u_int32_t datarate,
return blksz << blkcnt;
}
+static bool
+chn_may_resizebuf(struct pcm_channel *c)
+{
+ return ((c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED)) == 0 &&
+ c->inprog == 0);
+}
+
static int
-chn_resizebuf(struct pcm_channel *c, int latency,
- int blkcnt, int blksz)
+chn_resizebuf(struct pcm_channel *c, int latency, int blkcnt, int blksz)
{
struct snd_dbuf *b, *bs, *pb;
int sblksz, sblkcnt, hblksz, hblkcnt, limit = 0, nsblksz, nsblkcnt;
@@ -1825,7 +1831,7 @@ chn_resizebuf(struct pcm_channel *c, int latency,
if (!(c->direction == PCMDIR_PLAY || c->direction == PCMDIR_REC))
return EINVAL;
- if ((c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED)) != 0)
+ if (!chn_may_resizebuf(c))
return EINVAL;
if (latency == -1) {
@@ -1883,7 +1889,7 @@ chn_resizebuf(struct pcm_channel *c, int latency,
CHN_UNLOCK(c->parentchannel);
CHN_LOCK(c);
/* Revalidate. */
- if ((c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED)) != 0)
+ if (!chn_may_resizebuf(c))
return EINVAL;
if (c->direction == PCMDIR_PLAY) {
limit = (pb != NULL) ?
@@ -1941,7 +1947,7 @@ chn_resizebuf(struct pcm_channel *c, int latency,
}
CHN_LOCK(c);
/* Revalidate. */
- if ((c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED)) != 0)
+ if (!chn_may_resizebuf(c))
return EINVAL;
if (!CHN_EMPTY(c, children)) {