BUG/MEDIUM: lua: Always init the lua stack before referencing the context
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 24 Mar 2021 14:03:01 +0000 (15:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Apr 2021 11:58:14 +0000 (13:58 +0200)
commit59dc1a677ac7ffddbd6b1af340e18875a665b60c
tree02d35fccc25b4fe50bcc89c244ddb1e26a7f3825
parenta6a8692142dd3804c524406e544cc22a8c19623c
BUG/MEDIUM: lua: Always init the lua stack before referencing the context

When a lua context is allocated, its stack must be initialized to NULL
before attaching it to its owner (task, stream or applet).  Otherwise, if
the watchdog is fired before the stack is really created, that may lead to a
segfault because we try to dump the traceback of an uninitialized lua stack.

It is easy to trigger this bug if a lua script do a blocking call while
another thread try to initialize a new lua context. Because of the global
lua lock, the init is blocked before the stack creation. Of course, it only
happens if the script is executed in the shared global context.

This patch must be backported as far as 2.0.

(cherry picked from commit 1e8433f594de4b860e5205fdd6cb40d91ff58f17)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f2e7362e0cf879b3c78b29d3d8406a28668c1e12)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 36cdbeed01a1106c6e1c8efd4f1161721bc51212)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/hlua.c