]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: improper lock usage in hlua_filter_callback()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 10:06:24 +0000 (11:06 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 15:47:17 +0000 (16:47 +0100)
In hlua_filter_callback(), some lua stack work is performed under
SET_SAFE_LJMP() guard which also takes care of locking the hlua context
when needed. However, a lua_gettop() call is performed out of the guard,
thus it is unsafe in multithreading context if the script is loaded using
'lua-load' because in this case the main lua stack is shared between
threads and each access to a lua stack must be performed under the lock,
thus we move lua_gettop() call under the lock.

It should be backported up to 2.6.

src/hlua.c

index 6c7a87913482def4b5b94812823f1e70636c692a..1b86e91992993e3a89ac7c9e184eb082a4819fe1 100644 (file)
@@ -12000,7 +12000,7 @@ static int hlua_filter_callback(struct stream *s, struct filter *filter, const c
                goto end;
 
        if (!HLUA_IS_RUNNING(flt_hlua)) {
-               int extra_idx = lua_gettop(flt_hlua->T);
+               int extra_idx;
 
                /* The following Lua calls can fail. */
                if (!SET_SAFE_LJMP(flt_hlua)) {
@@ -12014,6 +12014,8 @@ static int hlua_filter_callback(struct stream *s, struct filter *filter, const c
                        goto end;
                }
 
+               extra_idx = lua_gettop(flt_hlua->T);
+
                /* Check stack size. */
                if (!lua_checkstack(flt_hlua->T, 3)) {
                        SEND_ERR(s->be, "Lua filter '%s': full stack.\n", conf->reg->name);