From nobody Tue Nov 17 17:05:17 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTWM15nCnz71Rjp for ; Tue, 17 Nov 2026 17:05:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTWM13ndTz4Gy0 for ; Tue, 17 Nov 2026 17:05:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dmWZs0MCOjgfQ20w87GXcT2xzV5AtN+XUJZWn4hYx84=; b=VD8IJ1tk1OzS25e6oIplU0J4Sd6J4BbnQck8ecAvJx6CCsc2I/k5um9eA9lTCfBb5olaEa 6/Nd2PWiCZMlvGPbbcZ2LqEWeKVtaZbX/omLLjc+KfK+QF5dfGXhGyUwqIs+xx8pi90+3I RLYjTJTUu/9TASfFLp1uEZ0G4bCw0D8y5egUZrlRn3KFSAgTev9H4U9ynl4XoT5ACoPw53 4CK3x0cSb5rRLpUKfJ2b4gRvMpx4+xw5Co+Ew6xb/2rLMK4giv731E1XMcaOlp7xByo5GX auA7XH5S4YGX+/NyG4rGu17eCFcDWyhxLKxbkx+odMwglauETiOOXK+5c6p1ng== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935117; b=jFf2haZjKr1u1k4tgHt6yQMQLhF8pb1xemetgMrKDh3c7u7cU89HGFTzxBPy1gc6i6yUf7 5nwelH2/nNFp0J5vQ8L9Ym8h4XP8sPI4STE0NDv4uuQAQKXqyooFkG63ZQnFadfQCQZ2zL VBqn04HpT9cfhZ+zPSBZSaPQOJn9UO6gicSYQ8M6V14A5x3mJ9LTCQIeLFEeN85Lb99YnK QQMC1Zz5yQRQ9HQJlBYeU/qyJdIoxPO80AeUvbB/KpVmqrNdYSXF5uL+IqYk8d4yDKmf2F kIRj6MJJAGcTzg4pjgiQmB0Gn8d0O7sVzBJR7+3LQZYuGQp5FoHs2I8kiGA2CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dmWZs0MCOjgfQ20w87GXcT2xzV5AtN+XUJZWn4hYx84=; b=jFRq3Xz7P3gUdOeW3sxZr5LCJt3YB6fiy+AnV8OW0VZS4RjdYb0UMZ7ebS+6zwuTjef18E f5GXS0+VFr6ToKM1VlQ767q9mmLybgiu8MMHBrT0XucEuzwJKx6n3dBKof12dEnGLMXvTZ lPuZ7lf3TjcBtiuEXSVIiTXzVxEQrVX2GS36mtUMGSomXbd/cMFFQjit/aVfs1UhrPYKES 7ppgwupopq/dfcZ/7OndmQ7msEiBRSyxHiHaujXji3otdyiMM3ihyHjOljMp9dQuMqOUv2 6THjVDG4IQCmzIsv4SFz4CacpEUqtRQ+zb2TXcAlUliBFnf9QkFB9PgMZaoCMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTWM11plNzrgw for ; Tue, 17 Nov 2026 17:05:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1efd2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:05:17 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: ec58c6a8ca80 - releng/14.5 - so_splice: Serialize teardowns of splices List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.5 X-Git-Reftype: branch X-Git-Commit: ec58c6a8ca809111e09096e6e4728d0c8039c05b Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:05:17 +0000 Message-Id: <6afc894d.1efd2.5661f0e1@gitrepo.freebsd.org> The branch releng/14.5 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ec58c6a8ca809111e09096e6e4728d0c8039c05b commit ec58c6a8ca809111e09096e6e4728d0c8039c05b Author: Mark Johnston AuthorDate: 2026-11-12 19:23:32 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:17:13 +0000 so_splice: Serialize teardowns of splices A socket splice can be configured with a timeout; once the timeout expires, the splice is automatically undone. The implementation of an unsplice operation detaches each socket from the splice structure, and then drains the timeout task. The timeout task takes the splice structure as an argument, and passes the source socket to so_unsplice(). It is possible for two threads to race with the task thread: one removes the source socket from the splice associated with currently running task, and the other thread splices that socket again, creating a new splice structure. The timeout thread may then unsplice the source socket even though it doesn't own that socket's current splice. The resulting use-after-free can be exploited by a local user to escalate privileges. Fix the problem by serializing teardowns of splices: make so_unsplice() callers specify the cause of the teardown, and ensure that threads can't race to destroy a splice after an error occurs. Approved by: so Security: FreeBSD-SA-26:87.socket Security: CVE-2026-127740 Reviewed by: gallatin Reported by: OpenAI Security Research Team Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D61443 --- sys/kern/uipc_socket.c | 84 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index f181872cebcb..52a23d961e65 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -345,7 +345,13 @@ static uint32_t splice_index = 0; static void so_splice_timeout(void *arg, int pending); static void so_splice_xfer(struct so_splice *s); -static int so_unsplice(struct socket *so, bool timeout); +enum so_unsplice_reason { + SO_UNSPLICE_SETSOCKOPT, + SO_UNSPLICE_TIMEOUT, + SO_UNSPLICE_EXCEPTION, +}; +static int so_unsplice(struct socket *so, struct so_splice *sp, + enum so_unsplice_reason why); static void splice_work_thread(void *ctx) @@ -653,7 +659,7 @@ closing: sp->state = SPLICE_EXCEPTION; soref(so_src); mtx_unlock(&sp->mtx); - (void)so_unsplice(so_src, false); + (void)so_unsplice(so_src, sp, SO_UNSPLICE_EXCEPTION); sorele(so_src); } else { /* @@ -1638,7 +1644,7 @@ so_splice_timeout(void *arg, int pending __unused) struct so_splice *sp; sp = arg; - (void)so_unsplice(sp->src, true); + (void)so_unsplice(sp->src, sp, SO_UNSPLICE_TIMEOUT); } /* @@ -1711,7 +1717,7 @@ so_splice(struct socket *so, struct socket *so2, struct splice *splice) sp->dst = NULL; sp->state = SPLICE_EXCEPTION; mtx_unlock(&sp->mtx); - so_unsplice(so, false); + (void)so_unsplice(so, sp, SO_UNSPLICE_EXCEPTION); return (error); } SOCK_SENDBUF_LOCK(so2); @@ -1722,7 +1728,7 @@ so_splice(struct socket *so, struct socket *so2, struct splice *splice) sp->dst = NULL; sp->state = SPLICE_EXCEPTION; mtx_unlock(&sp->mtx); - so_unsplice(so, false); + (void)so_unsplice(so, sp, SO_UNSPLICE_EXCEPTION); return (EINVAL); } so2->so_snd.sb_flags |= SB_SPLICED; @@ -1748,10 +1754,11 @@ so_splice(struct socket *so, struct socket *so2, struct splice *splice) } static int -so_unsplice(struct socket *so, bool timeout) +so_unsplice(struct socket *so, struct so_splice *sp, + enum so_unsplice_reason why) { struct socket *so2; - struct so_splice *sp; + int error; bool drain; /* @@ -1770,18 +1777,47 @@ so_unsplice(struct socket *so, bool timeout) SOCK_UNLOCK(so); return (ENOTCONN); } - sp = so->so_splice; + if (sp == NULL) { + sp = so->so_splice; + } else if (sp != so->so_splice) { + SOCK_RECVBUF_UNLOCK(so); + SOCK_UNLOCK(so); + return (EINVAL); + } + error = 0; mtx_lock(&sp->mtx); - if (sp->state == SPLICE_INIT) { + switch (sp->state) { + case SPLICE_INIT: /* * A splice is in the middle of being set up. */ - mtx_unlock(&sp->mtx); + error = ENOTCONN; + break; + case SPLICE_EXCEPTION: + /* + * Make sure that unsplicing is serialized. + */ + if (why != SO_UNSPLICE_EXCEPTION) { + error = ENOTCONN; + break; + } + /* FALLTHROUGH */ + case SPLICE_IDLE: + sp->state = SPLICE_CLOSED; + break; + case SPLICE_QUEUED: + case SPLICE_RUNNING: + sp->state = SPLICE_CLOSING; + break; + default: + __assert_unreachable(); + } + mtx_unlock(&sp->mtx); + if (error != 0) { SOCK_RECVBUF_UNLOCK(so); SOCK_UNLOCK(so); - return (ENOTCONN); + return (error); } - mtx_unlock(&sp->mtx); so->so_rcv.sb_flags &= ~SB_SPLICED; so->so_splice = NULL; SOCK_RECVBUF_UNLOCK(so); @@ -1808,22 +1844,11 @@ so_unsplice(struct socket *so, bool timeout) * finish before proceeding. */ mtx_lock(&sp->mtx); - switch (sp->state) { - case SPLICE_QUEUED: - case SPLICE_RUNNING: - sp->state = SPLICE_CLOSING; - while (sp->state == SPLICE_CLOSING) - msleep(sp, &sp->mtx, PSOCK, "unsplice", 0); - break; - case SPLICE_INIT: - case SPLICE_IDLE: - case SPLICE_EXCEPTION: - sp->state = SPLICE_CLOSED; - break; - default: - __assert_unreachable(); - } - if (!timeout) { + while (sp->state == SPLICE_CLOSING) + msleep(sp, &sp->mtx, PSOCK, "unsplice", 0); + KASSERT(sp->state == SPLICE_CLOSED, + ("%s: splice %p state %d", __func__, sp, sp->state)); + if (why != SO_UNSPLICE_TIMEOUT) { drain = taskqueue_cancel_timeout(taskqueue_thread, &sp->timeout, NULL) != 0; } else { @@ -4026,7 +4051,8 @@ sosetopt(struct socket *so, struct sockopt *sopt) error = so_splice(so, so2, &splice); fdrop(fp, sopt->sopt_td); } else { - error = so_unsplice(so, false); + error = so_unsplice(so, NULL, + SO_UNSPLICE_SETSOCKOPT); } break; }