]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
DoH: Avoid accessing non-atomic listener socket flags when accepting
authorArtem Boldariev <artem@boldariev.com>
Fri, 2 Dec 2022 08:41:28 +0000 (10:41 +0200)
committerArtem Boldariev <artem@boldariev.com>
Fri, 2 Dec 2022 10:16:12 +0000 (12:16 +0200)
This commit ensures that the non-atomic flags inside a DoH listener
socket object (and associated worker) are accessed when doing accept
for a connection only from within the context of the dedicated thread,
but not other worker threads.

The purpose of this commit is to avoid TSAN errors during
isc__nmsocket_closing() calls. It is a continuation of
4b5559cd8f41e67bf03e92d9d0338dee9d549b48.

lib/isc/netmgr/http.c

index bd4a02ed682d6f278a2c828419ec67c46bdd6da6..7b1d6f7ece66abeed33b7ba177c98373c402da06 100644 (file)
@@ -2459,7 +2459,9 @@ httplisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
         * function gets invoked, so we need to do extra sanity checks to
         * detect this case.
         */
-       if (isc__nmsocket_closing(handle->sock) || httpserver == NULL) {
+       if (isc__nm_closing(handle->sock->worker)) {
+               return (ISC_R_SHUTTINGDOWN);
+       } else if (isc__nmsocket_closing(handle->sock) || httpserver == NULL) {
                return (ISC_R_CANCELED);
        }
 
@@ -2471,9 +2473,7 @@ httplisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
        REQUIRE(VALID_NMSOCK(httplistensock));
        INSIST(httplistensock == httpserver);
 
-       if (isc__nmsocket_closing(httplistensock) ||
-           !atomic_load(&httplistensock->listening))
-       {
+       if (atomic_load(&httplistensock->closing)) {
                return (ISC_R_CANCELED);
        }