git: 4cbd89510ee2 - releng/14.4 - freebsd32: Avoid modifying a shared control message
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 17:04:15 UTC
The branch releng/14.4 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=4cbd89510ee2e3b344b523185c5b1e35de26b442
commit 4cbd89510ee2e3b344b523185c5b1e35de26b442
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-12 19:18:29 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-16 21:16:22 +0000
freebsd32: Avoid modifying a shared control message
freebsd32_copy_msg_out() copies out received control messages. The
cmsg ABI differs between the 32-bit and native ABIs in that the 32-bit
ABI requires only 4-byte alignment for message bodies, see CMSG_ALIGN.
When the control message is read from the socket buffer with MSG_PEEK,
short messages which fit into an mbuf are copied into private storage,
but larger messages are returned by acquiring a counted reference on the
underlying mbuf cluster still attached to the socket buffer.
When the underlying storage is shared, the non-atomic, temporary
modification of the control message header in freebsd32_copy_msg_out()
can be abused to corrupt the message queue; this can be leveraged to
escalate privileges.
Approved by: so
Security: FreeBSD-SA-26:86.freebsd32
Security: CVE-2026-101321
Reported by: OpenAI Security Research Team
Reviewed by: brooks, kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61355
---
sys/compat/freebsd32/freebsd32_misc.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index df388a7d67d1..d3917b8a6dff 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -1474,9 +1474,9 @@ freebsd32_cmsg_convert(const struct cmsghdr *cm, void *data, socklen_t datalen)
static int
freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
{
- struct cmsghdr *cm;
+ struct cmsghdr *cm, cm_out;
void *data;
- socklen_t clen, datalen, datalen_out, oldclen;
+ socklen_t clen, datalen, datalen_out;
int error;
caddr_t ctlbuf;
int len, copylen;
@@ -1502,9 +1502,10 @@ freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
datalen_out = freebsd32_cmsg_convert(cm, data, datalen);
/*
- * Copy out the message header. Preserve the native
- * message size in case we need to inspect the message
- * contents later.
+ * Copy out the message header. Adjust it first to
+ * satisfy the 32-bit ABI's alignment requirements.
+ * Note that the underlying storage may still be
+ * resident in the socket buffer.
*/
copylen = sizeof(struct cmsghdr);
if (len < copylen) {
@@ -1512,11 +1513,11 @@ freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
m_dispose_extcontrolm(m);
goto exit;
}
- oldclen = cm->cmsg_len;
- cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
+ memcpy(&cm_out, cm, copylen);
+ cm_out.cmsg_len =
+ FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
datalen_out;
- error = copyout(cm, ctlbuf, copylen);
- cm->cmsg_len = oldclen;
+ error = copyout(&cm_out, ctlbuf, copylen);
if (error != 0)
goto exit;