From nobody Tue Nov 17 17:02:09 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 4jTWHQ0yPrz71QCG for ; Tue, 17 Nov 2026 17:02:10 +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 4jTWHP5L6hz3QLh for ; Tue, 17 Nov 2026 17:02:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934929; 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=cFzGObohKpWVGPVIa7YODL+LSMsdLxaDhNK7s9D7lBQ=; b=xcEJklOPtSK2J2/uTDs808FyZn1Pnu1eCCLOom7+FA82lnbA/0zyXbI3fTJHqaUMAYBxEt sty3WmOVihKdlYJgsGAqYHmHaTksHyYAPG9tz3JjCpdCENF+qYu6TJypawBRoxz/XmSz0c q1KUCQQmx83F6ACfLWQmliu177PusA/IfaAP+gwJIAS9n2uKvJuU0CGMFH5eDz6CCsr4ON Skg3qlKpLH2zNcKz3jbDavBOYEipPUCMTEiGuap8AxVc5LNfVoXGs6JEl6JPJCuHKee8ZM GpV+myGlqu5HD9lKt94gnVXUvj6S8z9Ell/Tim/CrdbK9ZHK+de1ZJWjxANfCw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934929; b=AbaHv3WNXr7RT9+dVgyMT8PFFucNEl6h3jDM0B/axSpsXkt559IiXs5kXqG7uRxHCWuyFV giOQaU8kNe+Neq5liVS5gjKjWbeSs3ivCeOEcKtNc4Lwq3kLJAIg3WuUjA4SoK9REAqj0p 6z2qtzJ9XYuBpqpfHdiH+5S2nYGqNgxS8lTEfQcfLI4gYS2NM0JAMA8GzIxT+MWBXcHI99 dO9FqAkoBVnd9ZohaNHFCogwnCXre1zqrkW4+Eixwc7WvHV/RW8eEaGVf7hShS6iuwcoR7 IopRVPhz9RDBGIMCZBN9RDh/fMbE2Pxh/WNk1W+YAQ43gDp1V8MaM7cyRUD3gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934929; 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=cFzGObohKpWVGPVIa7YODL+LSMsdLxaDhNK7s9D7lBQ=; b=EYa4aDdvINbzBfWVBp7Qhlj1PEHdpjUKwsoOnXnKEG9X43XrIqUC96QHOm9/ICxbxW5IEr LffNsH4cyr0G7KvrzNQ2b+fwjdTT3jW2ng19oAg3QBJkWyyHGn/Rc9sufyuhxIl59Kl6Xv GvImeWJkztYP+R1mKVpf+qDsmOXpJAgzfVMH7xNeDpBiQJ7SqHoyKPvT0WfLJceUDjCqbC e2UIc5rh8OuPtoaUabv2wrC2K/MVgb/HMctUOo1NT9PDG/i5ZBmSfxwTnhU2G3EefKEhLO 95WzOFzWxUc950Xjj1o0XeB7RuaJjr91A34kT8Ang2XocODi0x3WvPws2SRQdg== 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 4jTWHP4hkxzr8K for ; Tue, 17 Nov 2026 17:02:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e983 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:02:09 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Konstantin Belousov From: Mark Johnston Subject: git: 6f5458cc9a75 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6f5458cc9a75e220a5af9d864c007bbf71a4bb0f Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:02:09 +0000 Message-Id: <6afc8891.1e983.1f9e9d9@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=6f5458cc9a75e220a5af9d864c007bbf71a4bb0f commit 6f5458cc9a75e220a5af9d864c007bbf71a4bb0f Author: Konstantin Belousov AuthorDate: 2026-11-14 00:30:36 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:02 +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 --- 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 400996f6f32a..629ecdb57e47 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3233,6 +3233,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, @@ -3248,10 +3249,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]. @@ -3262,14 +3274,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); }