git: 4d7f2bc4142f - stable/15 - fdcopy(): properly update fd_freefile when skipping non-copyable fd

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 03 Nov 2026 09:02:02 UTC
The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=4d7f2bc4142f5feac9d0e4302b433af0392e9e24

commit 4d7f2bc4142f5feac9d0e4302b433af0392e9e24
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-30 16:02:34 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-03 09:01:13 +0000

    fdcopy(): properly update fd_freefile when skipping non-copyable fd
    
    PR:     300234
    
    (cherry picked from commit 99a58803f9a306253df36c82f11991bc1e36e5a5)
---
 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 90e0a5c8d2e0..764368b36cd3 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2616,13 +2616,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;
 		}