]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix a possible race between udp dispatch and socket code
authorWitold Kręcicki <wpk@isc.org>
Fri, 31 May 2019 08:40:52 +0000 (10:40 +0200)
committerEvan Hunt <each@isc.org>
Fri, 31 May 2019 18:21:28 +0000 (11:21 -0700)
There's a small possibility of race between udp dispatcher and
socket code - socket code can still hold internal reference to a
socket while dispatcher calls isc_socket_open, which can cause
an assertion failure. Fix it by relaxing the assertion test, and
instead simply locking the socket in isc_socket_open.

lib/isc/unix/socket.c

index 2c97e6e697d25ac8e89b44db96a114d8ba604d1c..fc93d369b531594cb87621c213cbbbe17b0d9c4c 100644 (file)
@@ -2596,15 +2596,16 @@ isc_socket_open(isc_socket_t *sock0) {
 
        REQUIRE(VALID_SOCKET(sock));
 
-       REQUIRE(isc_refcount_current(&sock->references) == 1);
-       /*
-        * We don't need to retain the lock hereafter, since no one else has
-        * this socket.
-        */
+       LOCK(&sock->lock);
+
+       REQUIRE(isc_refcount_current(&sock->references) >= 1);
        REQUIRE(sock->fd == -1);
        REQUIRE(sock->threadid == -1);
 
        result = opensocket(sock->manager, sock, NULL);
+
+       UNLOCK(&sock->lock);
+
        if (result != ISC_R_SUCCESS) {
                sock->fd = -1;
        } else {