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@
-/* $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 $ */
/*
* 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;