]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Plug a race between fd table teardown and several loops
authormarkj <markj@FreeBSD.org>
Wed, 9 Dec 2020 14:05:08 +0000 (14:05 +0000)
committermarkj <markj@FreeBSD.org>
Wed, 9 Dec 2020 14:05:08 +0000 (14:05 +0000)
commitfb0c5761722fa89e4fb1721b608fc125e5b50093
tree578f4cbce2c78cbe7f8c9e1b09040dc7345ae1ee
parent88201c2c756e94de2640cd9089ca7ab9ee6b9c7e
Plug a race between fd table teardown and several loops

To export information from fd tables we have several loops which do
this:

FILDESC_SLOCK(fdp);
for (i = 0; fdp->fd_refcount > 0 && i <= lastfile; i++)
<export info for fd i>;
FILDESC_SUNLOCK(fdp);

Before r367777, fdescfree() acquired the fd table 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 race with teardown of file descriptor tables.

Acquire the exclusive fdtable lock after releasing the final table
reference to provide a barrier synchronizing with these loops.

Reported by: pho
Reviewed by: kib (previous version), mjg
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D27513
sys/kern/kern_descrip.c