From: William Lallemand Date: Tue, 29 Sep 2026 07:14:18 +0000 (+0200) Subject: BUG/MEDIUM: acme: take the resolvers lock when linking/unlinking DNS requesters X-Git-Url: https://git.kaiwu.me/http/%22../static/%7B@url%7D?a=commitdiff_plain;h=4c6ea859a1e6582c1b36c5ec88c0578a20e2f5a7;p=haproxy.git BUG/MEDIUM: acme: take the resolvers lock when linking/unlinking DNS requesters 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. --- diff --git a/src/acme_resolvers.c b/src/acme_resolvers.c index 26c808ced..0659b757b 100644 --- a/src/acme_resolvers.c +++ b/src/acme_resolvers.c @@ -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;