]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: improper lock usage in hlua_filter_new()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 10:25:47 +0000 (11:25 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 15:47:18 +0000 (16:47 +0100)
In hlua_filter_new(), after each hlua resume, we systematically try to
empty the stack by calling lua_settop(). However we're doing this without
locking the lua context, so it is unsafe in multithreading context if the
script is loaded using 'lua-load'. To fix the issue, we protect the call
with hlua_{lock,unlock}() helpers.

This should be backported up to 2.6.

src/hlua.c

index 1b86e91992993e3a89ac7c9e184eb082a4819fe1..2339711a38af2f7b372f1107a458f247feb85cea 100644 (file)
@@ -11956,8 +11956,11 @@ static int hlua_filter_new(struct stream *s, struct filter *filter)
        }
 
   end:
-       if (s->hlua)
+       if (s->hlua) {
+               hlua_lock(s->hlua);
                lua_settop(s->hlua->T, 0);
+               hlua_unlock(s->hlua);
+       }
        if (ret <= 0) {
                if (flt_ctx) {
                        hlua_ctx_destroy(flt_ctx->hlua[0]);