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.
* 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;