From nobody Tue Nov 17 17:06:22 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 4jTWNH054kz71Rsf for ; Tue, 17 Nov 2026 17:06:23 +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 4jTWNG53Qdz4JrH for ; Tue, 17 Nov 2026 17:06:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4AecVwp0zUcwQ7HjaCVTWfj2XOet65403/9xTCO/V6E=; b=JpmVApJiWOMZhWV+irL3f+9VuU8lce61CK8YKbcnuSjWXfWpkDlkwyD8CAj++UQ1noMfE3 8647axsEDZOo372VW8biWijfS3YzQDxy70KjgAkBw7N4mlwdXejEVNt/Od6Jk0h9C06rpb NZ0Vcn2Y3X6S9i15az05IEjMDLFSeDjg9BTbpCT9ZlYZUwG/Pf22jjADB5zIJE3vzOQSNx 32Or8IB2BiSpmSC8UTiEu260q+DWHnsbgZlFEx2M/7Iz3+wr5yYRkak3PSoHKt/qNvI9NC z8chOhyYkoBTTMBVum7+7ON077+EIgElCEni9KgZz/8zM3CfgfhaG3mAUSqw9w== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935182; b=MJ9HSGZA+waHHB0D8sumBSCarN4luKJkKZ5et2WAvfBfxyXl16HitigapMO3ekCz6TQpjj F/BwjFTsQqrlEeds5fDKVn+gcEqq2uEuHu1D5eGyOInsy5ISf8+/o9KlRVlbfy1MP1pPVV R+Ni+lW9CPPOD0RRBr6HUsYpkdp3Ek/2nyG2c1vGZqxVcpotcWUDAGKY/1L9yUDVFhiLqQ GqIhxCOMapgeK5dhnZkRNoqJTIVs2h3y9KGaggLSNBBuYTwSG4+Hihh1xTKz3/BBAaRJXp wr7WAqUZz/5cRuctd1NxS+aUdEN8HdF/EIRv2h8Itw3+ut+49h2WIpBZJsjAww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4AecVwp0zUcwQ7HjaCVTWfj2XOet65403/9xTCO/V6E=; b=QZ3xlbaQWZtu88ZVd21j3DwF3tUjQLyx9U2sdrmSd40KCLkc4y1ORC1f5s7W02V9fBSt1A QShatPif72buQyMlqHwrg2kVqknk4Bw0YrNDXI8IM6BvR1cr9UQylW6ZebrettXt8Fye6O EzlzPPVYBFQ1cGpPK/1vXs79Kgr2p0EjODD2PL5ayXGU7LTzH2FLTH65f8x1ULKSKlz1kR fb5qcxNQSTTaLWTwl69cqR88/VaVpz69+pVWzY5bseXZRqLv60EahbW2a7M2M/c7sOZ6Qq PPrXszsyGmOtBa5aG2PRFtppCTSw15RgOzgStr92XflFP6rNCzS2xHlTDlVCPw== 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 4jTWNG4j3mzrjw for ; Tue, 17 Nov 2026 17:06:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1dfbb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:06:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Konstantin Belousov From: Mark Johnston Subject: git: cfd6ff1fe5ca - stable/15 - fget_remote(9): recheck remote process fdp after holding the file 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/stable/15 X-Git-Reftype: branch X-Git-Commit: cfd6ff1fe5ca4fe238a764b3a9594fe316b313d1 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:06:22 +0000 Message-Id: <6afc898e.1dfbb.567c9951@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cfd6ff1fe5ca4fe238a764b3a9594fe316b313d1 commit cfd6ff1fe5ca4fe238a764b3a9594fe316b313d1 Author: Konstantin Belousov AuthorDate: 2026-11-14 00:30:36 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 17:02:15 +0000 fget_remote(9): recheck remote process fdp after holding the file kern_pddupfd() grants access to the process named by a process descriptor with p_candebug(), then calls fget_remote() to duplicate a descriptor from that process's current filedesc. The check remains stable against an execve() by that one process, but the implementation does not keep the held filedesc semantically bound to that process. If the authorized process P shares its descriptor table with another process Q, P can detach from the table with rfork(RFCFDG) after fget_remote() has held the old table but before it acquires the table lock. After P detaches, Q is the sole process-reference owner of the old table; fget_remote() retains only a separate lifetime hold. When Q executes a setuid program, the normal fdunshare() call observes fd_refcnt == 1 and does not copy the table. Privileged descriptors are therefore installed in the held old table. The waiting pddupfd() call accepts that table because its process reference count is nonzero and can return a descriptor opened by Q even though the security check was performed against P. Recheck the file descriptor table of the remote process after the hold, and refuse to dup if the table changed. Reported by: Reo Shiseki working with TrendAI Zero Day Initiative Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D61520 (cherry picked from commit 6f5458cc9a75e220a5af9d864c007bbf71a4bb0f) --- sys/kern/kern_descrip.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ea033a7f598a..b5799a827e6d 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3204,6 +3204,7 @@ fget_remote(struct thread *td, struct proc *p, int fd, struct filecaps *fcaps, struct file *fp; int error; bool copied __diagused; + bool drop_fp; /* * Both fcaps and fd_flags must be either requested together, @@ -3219,10 +3220,21 @@ fget_remote(struct thread *td, struct proc *p, int fd, struct filecaps *fcaps, PROC_UNLOCK(p); if (fdp == NULL) return (ENOENT); + drop_fp = false; FILEDESC_SLOCK(fdp); if (refcount_load(&fdp->fd_refcnt) != 0) { fp = fget_noref(fdp, fd); - if (fp != NULL && fhold(fp)) { + error = fp != NULL && fhold(fp) ? 0 : EBADF; + } else { + error = ENOENT; + } + if (error == 0) { + PROC_LOCK(p); + /* Guard against a race with rfork(RFCFDG). */ + if (fdp != atomic_load_ptr(&p->p_fd)) + error = EBADF; + PROC_UNLOCK(p); + if (error == 0) { *fpp = fp; if (fd_flags != NULL) { *fd_flags = fde_to_fd_flags(fdp->fd_ofiles[fd]. @@ -3233,14 +3245,13 @@ fget_remote(struct thread *td, struct proc *p, int fd, struct filecaps *fcaps, &fdp->fd_ofiles[fd].fde_caps, fcaps, true); MPASS(copied); } - error = 0; } else { - error = EBADF; + drop_fp = true; } - } else { - error = ENOENT; } FILEDESC_SUNLOCK(fdp); + if (drop_fp) + fdrop(fp, td); fddrop(fdp); return (error); }