]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: acme: take the resolvers lock when linking/unlinking DNS requesters
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 29 Sep 2026 07:14:18 +0000 (09:14 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 23 Nov 2026 10:27:14 +0000 (11:27 +0100)
The dns-01 pre-check links an ACME requester to a resolution in
acme_rslv_start() and unlinks it in acme_rslv_free(), both called from
the ACME task, which runs on any thread. But resolv_link_resolution() and
resolv_unlink_resolution() manipulate the resolvers' resolution lists and
the resolutions' requester lists, which are also manipulated by the
resolvers task and the response handlers on the resolvers' thread under
resolvers->lock. Other requesters (do-resolve in streams, stream_free(),
CLI actions on servers) always take this lock around these calls, but
the ACME code never does.

Among the possible consequences, the requester callbacks are called on
the resolvers' thread while it iterates over the resolution's requesters
under the lock. The last callback wakes the ACME task up, which may then
immediately call acme_rslv_free() on another thread and unlink the last
requester, which aborts and frees the resolution in leave_resolver_code(),
while the resolvers' thread continues to use it (resolv_reset_resolution(),
LIST_DEL_INIT() etc). Concurrent insertions into the resolutions lists
with process_resolvers() may also corrupt them.

This requires an ACME dns-01 challenge with a multi-threaded process and
was only found by code review: there is currently no way to test ACME
here, but the rules are the same as for all other requesters.

Let's take the lock around the link+trigger and the unlink operations.

This was introduced in 3.4 with commit 631fd5f99 ("MEDIUM: acme: add dns-01
DNS propagation pre-check"), so this must be backported to 3.4.

src/acme_resolvers.c

index 26c808ced14647911c8712acf1c09f181465c402..0659b757b3b162eb446d7494964dfaca2993f513 100644 (file)
@@ -82,8 +82,11 @@ void acme_rslv_free(struct acme_rslv *rslv)
 {
        if (!rslv)
                return;
-       if (rslv->requester)
+       if (rslv->requester) {
+               HA_SPIN_LOCK(DNS_LOCK, &rslv->resolvers->lock);
                resolv_unlink_resolution(rslv->requester);
+               HA_SPIN_UNLOCK(DNS_LOCK, &rslv->resolvers->lock);
+       }
        free(rslv->hostname_dn);
        istfree(&rslv->txt);
        free(rslv);
@@ -145,12 +148,18 @@ struct acme_rslv *acme_rslv_start(struct acme_auth *auth, unsigned int *dnstasks
                goto error;
        }
 
+       /* the resolution is processed by the resolvers' thread, which
+        * requires its lock to be held.
+        */
+       HA_SPIN_LOCK(DNS_LOCK, &resolvers->lock);
        if (resolv_link_resolution(rslv, OBJ_TYPE_ACME_RSLV, 0) < 0) {
+               HA_SPIN_UNLOCK(DNS_LOCK, &resolvers->lock);
                memprintf(errmsg, "Could not create resolution task for \"%.*s\"\n", hostname_len, hostname);
                goto error;
        }
 
        resolv_trigger_resolution(rslv->requester);
+       HA_SPIN_UNLOCK(DNS_LOCK, &resolvers->lock);
 
        return rslv;