From nobody Fri Oct 30 19:08:28 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 4jGVxS3Qdpz6xPPv for ; Fri, 30 Oct 2026 19:08:28 +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 4jGVxS2V2xz3KHX for ; Fri, 30 Oct 2026 19:08:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793387308; 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=b9hJCHL6mMIailAw7vd8dl9ga92uRMFRD39IoRC7grA=; b=ORUnIuKGat9WuN25wtUtIOOUo4KeigFY4q3crDqpGIyOQ+Tyak9pd0AoSwahQF0qIAV42z lviUH21VvOpeas5kJ6bcshx6IuIC4sEahdMeLDj9fvgfmmXVn/FuCE7/aAYWTMNM1C26wT XqHEzLkjYG5pYrAbnqbpFNtSL5aY22c5aNsBeVOHukfGckMHMA6/fXXEhIc4gZsJUY2zWG IuY+YwsVvslg43mjS4dxJiqp9Qy2t9kvfBOASHz21258u67wMopvAmr4RCK3JRI8nxp7oB yZqj7vpYcUt75mgv4NYWhIb7tdjMF6NPzv4BOXQRKr0RnV/dgxVwImpCD0GISw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793387308; b=YGB1J04GvV5+Bl+Rg3wRJLFj+KoSqt41VFnjvVASRvH4Kk7PXTrGuIK1YjmkRwajvbHbLv IHAh1KnN66Xwo310QqeTo9lo4Cn3+WaZQMfRjiV0rDSn5sjN33CbujD60HVlv2GZPIwZqL 3yS95UEcC3VgLz66ObdK3/b2FoATimcO/q2a/Ll0UTTX/R2JnPit1AVkZrpi1Ywr98tMqg xDYxE5BGOeAiMQrY2XwJ/UPbsFcnkYursUkfM0MwdmqILbHSGGvR8CbNFr8wf+JeEMNx39 stodb2ettpXIo52v+5ZBAac/QO+kC/Zf9iVf6Eq2xnNXfw/cvmNqafQ2wNSyIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793387308; 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=b9hJCHL6mMIailAw7vd8dl9ga92uRMFRD39IoRC7grA=; b=AcFk6Y4lpZdUHEhscRWCjgstwvs8VC7yp6MafQL7jwUVo4QNmvt8NnBmqf5EE/w/qCFYLG U0k05WkEUx4qzoWyvUMGtxdmNZgOfSG+/Qqn/cmaFI8mORIyhwgknKnW2upxWRR0ai8kvf tOXzRsMVu93Pcsbs5iOOZt8L4UREAQ6jlhn4sgKh93I4bgas2z6NdnxX13XkuPVoxP2H6/ WRd31OchOYj3BLVMf6u4ko8Zly2ieB4J9cegXAO3cJ0AGwdL90ZQJsqbH5DJkEuy/MFeLo f93QJ4LNAPPEdbn0yWMZf7ZZPwu65M04Vyu2VKeoxvgtExk2q6zHpBo5OgCTJw== 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 4jGVxS1sLmzgt1 for ; Fri, 30 Oct 2026 19:08:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1908c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 19:08:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 99a58803f9a3 - main - fdcopy(): properly update fd_freefile when skipping non-copyable fd List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 99a58803f9a306253df36c82f11991bc1e36e5a5 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 19:08:28 +0000 Message-Id: <6ae4eb2c.1908c.77d5a071@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=99a58803f9a306253df36c82f11991bc1e36e5a5 commit 99a58803f9a306253df36c82f11991bc1e36e5a5 Author: Konstantin Belousov AuthorDate: 2026-10-30 16:02:34 +0000 Commit: Konstantin Belousov CommitDate: 2026-10-30 19:07:39 +0000 fdcopy(): properly update fd_freefile when skipping non-copyable fd fd_freefile is maintained to fulfill the POSIX guarantee that the lowest possible file descriptor is allocated on open. If we skip copying an fd, it is a possible candidate for the lowest index. First, the file descriptor installed with a kqueue created without KQUEUE_CPONFORK missed this handling [*]. Second, fd_freefile should be updated only when the current fd index is below it. A skipped fd above fd_freefile could raise it past a free slot. PR: 300234 [*] Reported by: Andrea Venturoli Reviewed by: markj Fixes: 1265516c5c61 ("struct file: add DFLAG_FORK, indicate copying on fork") Fixes: 809f3121be66 ("fd: assign fd_freefile early when copying") MFC after: 1 week Differential revision: https://reviews.freebsd.org/D61054 --- sys/kern/kern_descrip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 80735e0b4c0c..0aafaa8bdb9f 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2644,13 +2644,16 @@ fdcopy(struct filedesc *fdp, struct proc *p1) if ((ops->fo_flags & DFLAG_FORK) != 0 && (ofde->fde_flags & UF_FOCLOSE) == 0) { if (ops->fo_fork(newfdp, ofde->fde_file, &fp, p1, - curthread) != 0) + curthread) != 0) { + if (newfdp->fd_freefile > i) + newfdp->fd_freefile = i; continue; + } fork_pass = true; } else if ((ops->fo_flags & DFLAG_PASSABLE) == 0 || (ofde->fde_flags & UF_FOCLOSE) != 0 || !fhold(ofde->fde_file)) { - if (newfdp->fd_freefile == fdp->fd_freefile) + if (newfdp->fd_freefile > i) newfdp->fd_freefile = i; continue; }