From: Christopher Faulet Date: Thu, 19 Nov 2026 18:00:00 +0000 (+0100) Subject: BUG/MEDIUM: stconn: Do not install an applet on a busy stream connector X-Git-Url: https://git.kaiwu.me/http/%22../static/%7B@url%7D?a=commitdiff_plain;h=99d3da756567622447c9dbc256102dad0295883f;p=haproxy.git BUG/MEDIUM: stconn: Do not install an applet on a busy stream connector It is possible to install an applet on a stream connector with an applet already attached. This could happen with a "http-request cache-use" rule followed by a matching "http-request use-service" rule, when the cache-use rule hits. The use-service rule installs a second applet on the same stream connector, replacing the cache one, which is leaked with its retained cache row. The commit a72de1022 ("BUG/MEDIUM: cache: do not create a second applet when two cache-use rules hit") only fixed the case of two cache-use rules. The use-service rules are still vulnerable. To fix the issue, sc_applet_create() now checks the SE_FL_DETACHED flag and fails if it is not set. This flag is set when the stream connector is created and it is cleared when an endpoint is attached, a mux or an applet, and it is set again by sc_reset_endp() when the endpoint is reset, to be able to retry a connection. Thus, it is not possible to install an applet on a stream connector with an applet already attached anymore. This patch should be backported to all supported versions. The commit a72de1022 is not present in the stable branches and the same weakness exists there since sc_applet_create() was introduced in 2.6. --- diff --git a/src/stconn.c b/src/stconn.c index 3aa5be486..b2c096c74 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -530,11 +530,19 @@ int sc_reset_endp(struct stconn *sc) * handler using sc_replace_endp(), possibly from within the function itself. * It also pre-initializes the applet's context and returns it (or NULL in case * it could not be allocated). + * + * It must only be called on a detached stream connector, with no endpoint + * attached. It fails if the SE_FL_DETACHED flag is not set, because it is + * cleared when an applet is attached. This way, it is not possible to install + * an applet on a stream connector with an applet already attached. */ struct appctx *sc_applet_create(struct stconn *sc, struct applet *app) { struct appctx *appctx; + if (!sc_ep_test(sc, SE_FL_DETACHED)) + return NULL; + appctx = appctx_new_here(app, sc->sedesc); if (!appctx) return NULL;