From 0c8caf3427358134fd72dfd38ac641ee88f1cb7d Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Mon, 6 Jan 2025 14:02:22 -0800 Subject: [PATCH] Fix LUA garbage collector (CVE-2024-46981) (#1513) Reset GC state before closing the lua VM to prevent user data to be wrongly freed while still might be used on destructor callbacks. Created and publish by Redis in their OSS branch. Pulled from Valkey for Redict. Signed-off-by: Madelyn Olson Signed-off-by: Drew DeVault Co-authored-by: YaacovHazan --- src/eval.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/eval.c b/src/eval.c index 336ed9140..8edd58535 100644 --- a/src/eval.c +++ b/src/eval.c @@ -273,6 +273,7 @@ void scriptingInit(int setup) { void freeLuaScriptsSync(dict *lua_scripts, list *lua_scripts_lru_list, lua_State *lua) { dictRelease(lua_scripts); listRelease(lua_scripts_lru_list); + lua_gc(lctx.lua, LUA_GCCOLLECT, 0); lua_close(lua); #if !defined(USE_LIBC)