]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: hlua: fix use-after-free of HTTP reason string
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Apr 2026 11:06:44 +0000 (13:06 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 10 Apr 2026 08:18:27 +0000 (10:18 +0200)
commit4ad200f2767901fb041112021f742c514c2a8997
tree68e84f1e219ea648d2e29eb9cb1b3991cac94e93
parent0aeae230560cab23c575ee611b35ad194880cb68
BUG/MINOR: hlua: fix use-after-free of HTTP reason string

hlua_applet_http_status() stored the result of luaL_optlstring()
directly in http_ctx->reason. The pointer references Lua-managed
string storage which is only guaranteed valid until the C function
returns to Lua. If the GC runs between applet:set_status(200, str)
and applet:start_response(), the pointer dangles.

hlua_applet_http_send_response() then calls ist(http_ctx->reason)
which does strlen() on freed memory, followed by memcpy into the
HTX status line. The freed-and-reallocated chunk contents are sent
verbatim to the HTTP client.

Trigger:

    applet:set_status(200, table.concat({"Reason ", str:rep(50)}))
    collectgarbage("collect"); collectgarbage("collect")
    applet:start_response()

With heap grooming, adjacent allocation contents (session data, TLS
material from the same thread) leak into the response status line.

Anchor the Lua string in the registry keyed by the http_ctx field
address so it survives until the applet is done with it. The
registry entry is overwritten on each call (handles repeated
set_status) and naturally cleaned up when the lua_State is closed.

This patch should be backported to all stable versions.
src/hlua.c