]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: sink: properly init applet under sft lock
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 24 Jul 2024 13:45:50 +0000 (15:45 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 24 Jul 2024 15:58:24 +0000 (17:58 +0200)
Since 09d69eacf8 ("MEDIUM: sink: start applets asynchronously") the applet
is no longer initialized under the sft lock while it was the case before.

At first it doesn't seem to be an issue, but if we look closer at
sink_forward_session_init(), we can see that sft->appctx is assigned
while it can be accessed at the same time from sink_init_forward().

Let's restore the old guarantees by performing the .init under the sft
lock.

No backport needed unless 09d69eacf8 is.

src/sink.c

index 594ddf46504b00a86db21a67fcedf63c52d2d768..194bd064ec6cfe97c54581bb1151ef1d61d83d1d 100644 (file)
@@ -495,6 +495,11 @@ static int sink_forward_session_init(struct appctx *appctx)
        struct stream *s;
        struct sockaddr_storage *addr = NULL;
 
+       /* sft init is performed asynchronously so <sft> must be manipulated
+        * under the lock
+        */
+       HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
+
        if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
                goto out_error;
        /* srv port should be learned from srv->svc_port not from srv->addr */
@@ -516,11 +521,14 @@ static int sink_forward_session_init(struct appctx *appctx)
        applet_expect_no_data(appctx);
        sft->appctx = appctx;
 
+       HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
+
        return 0;
 
  out_free_addr:
        sockaddr_free(&addr);
  out_error:
+       HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
        return -1;
 }