]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix a potential lock-order-inversion in tcp listening code
authorWitold Kręcicki <wpk@isc.org>
Tue, 10 Dec 2019 09:05:15 +0000 (10:05 +0100)
committerWitold Kręcicki <wpk@isc.org>
Tue, 10 Dec 2019 09:05:15 +0000 (10:05 +0100)
lib/isc/netmgr/tcp.c

index a996acfb01c3517daf46a489f7528d0a6885962c..e1bbeab48e25f9385769a3dd9dea3c6ecc90c17f 100644 (file)
@@ -186,10 +186,13 @@ isc_nm_listentcp(isc_nm_t *mgr, isc_nmiface_t *iface,
                isc__nm_put_ievent(mgr, ievent);
        } else {
                nsock->tid = isc_random_uniform(mgr->nworkers);
-               LOCK(&nsock->lock);
                isc__nm_enqueue_ievent(&mgr->workers[nsock->tid],
                                       (isc__netievent_t *) ievent);
-               WAIT(&nsock->cond, &nsock->lock);
+
+               LOCK(&nsock->lock);
+               while (!atomic_load(&nsock->listening)) {
+                       WAIT(&nsock->cond, &nsock->lock);
+               }
                UNLOCK(&nsock->lock);
        }