BUG/MINOR: hlua: improper lock usage in hlua_filter_callback()

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.
This commit is contained in:
Aurelien DARRAGON 2024-03-04 11:06:24 +01:00
parent 9578524091
commit 51f291c795

View File

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