From ccd44b69e5774ca7158c7445fa8c619a91840b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Tue, 10 Dec 2019 10:05:15 +0100 Subject: [PATCH] Fix a potential lock-order-inversion in tcp listening code --- lib/isc/netmgr/tcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index a996acfb01..e1bbeab48e 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -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); }