From 8a6c0b796c8f0816f6117f9eaeaa501bf81ca833 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Mon, 30 Sep 2019 13:58:02 +0000 Subject: [PATCH] fix(userspace/engine): guard lua state into falco engine Co-authored-by: Lorenzo Fontana Signed-off-by: Leonardo Di Donato --- userspace/engine/falco_common.h | 8 ++++---- userspace/engine/falco_engine.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/userspace/engine/falco_common.h b/userspace/engine/falco_common.h index f304b6e5..64659186 100644 --- a/userspace/engine/falco_common.h +++ b/userspace/engine/falco_common.h @@ -21,6 +21,7 @@ limitations under the License. #include #include +#include extern "C" { #include "lua.h" @@ -94,11 +95,10 @@ public: protected: lua_State *m_ls; + std::mutex m_ls_semaphore; + sinsp *m_inspector; private: void add_lua_path(std::string &path); -}; - - - +}; \ No newline at end of file diff --git a/userspace/engine/falco_engine.cpp b/userspace/engine/falco_engine.cpp index e3e8327b..98971be6 100644 --- a/userspace/engine/falco_engine.cpp +++ b/userspace/engine/falco_engine.cpp @@ -287,8 +287,8 @@ unique_ptr falco_engine::process_sinsp_event(sinsp_ev unique_ptr res(new rule_result()); + std::lock_guard guard(m_ls_semaphore); lua_getglobal(m_ls, lua_on_event.c_str()); - if(lua_isfunction(m_ls, -1)) { lua_pushnumber(m_ls, ev->get_check_id()); @@ -335,8 +335,8 @@ unique_ptr falco_engine::process_k8s_audit_event(json unique_ptr res(new rule_result()); + std::lock_guard guard(m_ls_semaphore); lua_getglobal(m_ls, lua_on_event.c_str()); - if(lua_isfunction(m_ls, -1)) { lua_pushnumber(m_ls, ev->get_check_id());