To export info from an fd table we have several loops which do this:
FILDESC_SLOCK(fdp); for (i = 0; fdp->fd_refcount > 0 && i < fdp->fd_lastfile; i++) { <export info for fd i>; } FILDESC_SUNLOCK(fdp);
Before r367777, fdescfree() acquired the fdtable exclusive lock between
decrementing fdp->fd_refcount and freeing table entries. This
serialized with the loop above, so the file at descriptor i would remain
valid until the lock is dropped. Now there is no serialization, so the
loops may access freed entries.
Restore the previous synchronization to fix the bug. This could be
micro-optimized to reduce the number of atomic operations but for now I
would just like to fix the bug.
Reported by: pho