]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: proxy: always detach a proxy from the names tree on free()
authorWilly Tarreau <w@1wt.eu>
Fri, 18 Apr 2025 21:50:13 +0000 (23:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 18 Apr 2025 21:50:13 +0000 (23:50 +0200)
commitd2a9149f09e7fe209b8e59781e82947412b24c66
treee640a03b27aeb71e924fadcc91f590901a14a05e
parent4309a6fbf80240b0880c5adf091f0075c3bcd53f
BUG/MINOR: proxy: always detach a proxy from the names tree on free()

Stephen Farrell reported in issue #2942 that recent haproxy versions
crash if there's no resolv.conf. A quick bisect with his reproducer
showed that it started with commit 4194f75 ("MEDIUM: tree-wide: avoid
manually initializing proxies") which reorders the proxies initialization
sequence a bit. The crash shows a corrupted tree, typically indicating a
use-after-free. With the help of ASAN it was possible to find that a
resolver proxy had been destroyed and freed before the name insertion
that causes the crash, very likely caused by the absence of the needed
resolv.conf:

    #0 0x7ffff72a82f7 in free (/usr/local/lib64/libasan.so.5+0x1062f7)
    #1 0x94c1fd in free_proxy src/proxy.c:436
    #2 0x9355d1 in resolvers_destroy src/resolvers.c:2604
    #3 0x93e899 in resolvers_create_default src/resolvers.c:3892
    #4 0xc6ed29 in httpclient_resolve_init src/http_client.c:1170
    #5 0xc6fbcf in httpclient_create_proxy src/http_client.c:1310
    #6 0x4ae9da in ssl_ocsp_update_precheck src/ssl_ocsp.c:1452
    #7 0xa1b03f in step_init_2 src/haproxy.c:2050

But free_proxy() doesn't delete the ebpt_node that carries the name,
which perfectly explains the situation. This patch simply deletes the
name node and Stephen confirmed that it fixed the problem for him as
well. Let's also free it since the key points to p->id which is never
freed either in this function!

No backport is needed since the patch above was first merged into
3.2-dev10.
src/proxy.c