From 69baa4ac9bf2ef11731783abcc1daf383e957b81 Mon Sep 17 00:00:00 2001 From: therealbobo Date: Fri, 12 Jul 2024 22:10:27 +0200 Subject: [PATCH 1/3] fix(driver/bpf): close maps on cleanup Signed-off-by: Roberto Scolaro --- userspace/libscap/engine/bpf/scap_bpf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/userspace/libscap/engine/bpf/scap_bpf.c b/userspace/libscap/engine/bpf/scap_bpf.c index c0638efd9c..6e883f021e 100644 --- a/userspace/libscap/engine/bpf/scap_bpf.c +++ b/userspace/libscap/engine/bpf/scap_bpf.c @@ -1384,6 +1384,11 @@ int32_t scap_bpf_close(struct scap_engine_handle engine) handle->program_fd = -1; } + for(int i = 0; i < BPF_MAPS_MAX; i++) + { + close(handle->m_bpf_map_fds[i]); + } + return SCAP_SUCCESS; } From 82141f1c33feb653db1bedb82501c0fa7545e277 Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Mon, 15 Jul 2024 13:32:57 +0000 Subject: [PATCH 2/3] chore(libscap/engine/bpf): reset bpf_map_fds to -1 Signed-off-by: Roberto Scolaro --- userspace/libscap/engine/bpf/scap_bpf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/userspace/libscap/engine/bpf/scap_bpf.c b/userspace/libscap/engine/bpf/scap_bpf.c index 6e883f021e..0d4385751c 100644 --- a/userspace/libscap/engine/bpf/scap_bpf.c +++ b/userspace/libscap/engine/bpf/scap_bpf.c @@ -1387,6 +1387,7 @@ int32_t scap_bpf_close(struct scap_engine_handle engine) for(int i = 0; i < BPF_MAPS_MAX; i++) { close(handle->m_bpf_map_fds[i]); + handle->m_bpf_map_fds[i] = -1; } return SCAP_SUCCESS; From 33a0544b9164e12ff0162a5725854be38d08f717 Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Mon, 15 Jul 2024 14:12:52 +0000 Subject: [PATCH 3/3] chore(engine/bpf): close only used fds Signed-off-by: Roberto Scolaro --- userspace/libscap/engine/bpf/scap_bpf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/userspace/libscap/engine/bpf/scap_bpf.c b/userspace/libscap/engine/bpf/scap_bpf.c index 0d4385751c..29430a382f 100644 --- a/userspace/libscap/engine/bpf/scap_bpf.c +++ b/userspace/libscap/engine/bpf/scap_bpf.c @@ -1386,8 +1386,11 @@ int32_t scap_bpf_close(struct scap_engine_handle engine) for(int i = 0; i < BPF_MAPS_MAX; i++) { - close(handle->m_bpf_map_fds[i]); - handle->m_bpf_map_fds[i] = -1; + if(handle->m_bpf_map_fds[i] >= 0) + { + close(handle->m_bpf_map_fds[i]); + handle->m_bpf_map_fds[i] = -1; + } } return SCAP_SUCCESS;