]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: hlua: fix possible crash in hlua_filter_new() under load
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 08:39:58 +0000 (09:39 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 15:47:03 +0000 (16:47 +0100)
commit957852409177efb36171f718ffef2be0fd919588
treea4e26fe57538215790010596eebcd702dcabdafb
parent369bfa0b50396a496a03fad59844196a3287784e
BUG/MINOR: hlua: fix possible crash in hlua_filter_new() under load

hlua_filter_new() handles memory allocation errors by jumping to the
"end:" cleanup label in case of errors. Such errors may happen when the
system is heavily loaded for instance.

In hlua_filter_new(), we try to allocate two hlua contexts in a row before
checking if one of them failed (in which case we jump to the cleanup part
of the function), and only then we initialize them both.

If a memory allocation failure happens for only one out of the two
flt_ctx->hlua[] contexts pair, we still jump to the cleanup part.
It means that the hlua context that was successfully allocated and wasn't
initialized yet will be passed to hlua_ctx_destroy(), resulting in invalid
reads in the cleanup function, which may ultimately cause the process to
crash.

To fix the issue: we make sure flt_ctx hlua contexts are initialized right
after they are allocated, that is before any error handling condition that
may force the cleanup.

This bug was discovered when trying to reproduce GH #2467 with haproxy
started with "-dMfail" argument.

It should be backported up to 2.6.
src/hlua.c