From 9406475e8b3ea5593448995104226950635465a6 Mon Sep 17 00:00:00 2001 From: jsing Date: Fri, 10 Aug 2018 15:53:49 +0000 Subject: [PATCH] Update fd_freefile when filtering/closing kqueue descriptors in fdcopy(). Prior to r1.153 of kern_descrip.c, the kqueue descriptors were removed using fdremove(), which reset fd_freefile as appropriate. The new code simply avoids adding the descriptor to the new table, however this means that fd_freefile can be left with an incorrect value, resulting in a file descriptor allocation "hole". Restore the previous behavour by lowering fd_freefile as appropriate when dropping descriptors. Issue found via golang regress tests. ok deraadt@ mpi@ visa@ --- 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 831d8015dd7..4224a87274d 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.177 2018/07/10 08:58:50 mpi Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.178 2018/08/10 15:53:49 jsing Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -1143,8 +1143,11 @@ fdcopy(struct process *pr) * their internal consistency, so close them here. */ if (fp->f_count >= FDUP_MAX_COUNT || - fp->f_type == DTYPE_KQUEUE) + fp->f_type == DTYPE_KQUEUE) { + if (i < newfdp->fd_freefile) + newfdp->fd_freefile = i; continue; + } FREF(fp); newfdp->fd_ofiles[i] = fp; -- 2.20.1