From ed5ff005c74b6076eea1092a7a5ad8d6f3604787 Mon Sep 17 00:00:00 2001 From: Lorenzo Susini Date: Thu, 12 Oct 2023 12:29:13 +0000 Subject: [PATCH] update(userspace/libsinsp): check correct allocation of thread info, remove useless forward decl Signed-off-by: Lorenzo Susini --- userspace/libscap/linux/scap_procs.c | 1 + userspace/libscap/scap_platform_api.h | 1 - userspace/libscap/scap_platform_impl.h | 1 - userspace/libsinsp/parsers.cpp | 7 ++++++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/userspace/libscap/linux/scap_procs.c b/userspace/libscap/linux/scap_procs.c index 0338c44948..c624bf9a3c 100644 --- a/userspace/libscap/linux/scap_procs.c +++ b/userspace/libscap/linux/scap_procs.c @@ -1385,6 +1385,7 @@ int32_t scap_linux_get_fdlist(struct scap_platform* platform, struct scap_thread struct scap_ns_socket_list* sockets_by_ns = NULL; struct scap_linux_platform* linux_platform = (struct scap_linux_platform*)platform; + // We collect file descriptors only for the main thread snprintf(proc_dir, sizeof(proc_dir), "%s/proc/%d/", scap_get_host_root(), tinfo->pid); return scap_fd_scan_fd_dir(linux_platform, &platform->m_proclist, proc_dir, tinfo, &sockets_by_ns, &num_fds_ret, lasterr); diff --git a/userspace/libscap/scap_platform_api.h b/userspace/libscap/scap_platform_api.h index 838aa18c81..15e32b1678 100644 --- a/userspace/libscap/scap_platform_api.h +++ b/userspace/libscap/scap_platform_api.h @@ -30,7 +30,6 @@ extern "C" { struct ppm_proclist_info; struct scap; -struct scap_fdinfo; struct scap_addrlist; struct _scap_machine_info; struct scap_threadinfo; diff --git a/userspace/libscap/scap_platform_impl.h b/userspace/libscap/scap_platform_impl.h index a9a02176d1..78248709e3 100644 --- a/userspace/libscap/scap_platform_impl.h +++ b/userspace/libscap/scap_platform_impl.h @@ -42,7 +42,6 @@ struct scap_open_args; struct scap_platform; struct scap_proclist; struct scap_userlist; -struct scap_fdinfo; struct ppm_proclist_info; // a method table for platform-specific operations diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index d9ab0f1e86..ab89391af4 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -4937,13 +4937,18 @@ void sinsp_parser::parse_rw_exit(sinsp_evt *evt) if(cmsg->cmsg_type == SCM_RIGHTS) { auto scap_tinfo = scap_proc_alloc(m_inspector->m_h); + if (scap_tinfo == NULL) + { + g_logger.format(sinsp_logger::SEV_CRITICAL, "scap_proc_alloc failed, proc table will not be updated with new fds."); + return; + } m_inspector->m_thread_manager->thread_to_scap(*evt->m_tinfo, scap_tinfo); // Get the new fds. The callbacks we have registered populate the fd table // with the new file descriptors. if (scap_get_fdlist(m_inspector->m_h, scap_tinfo) != SCAP_SUCCESS) { - g_logger.format(sinsp_logger::SEV_DEBUG, "scap_get_fdlist failed, proc table will not be updated with new fds."); + g_logger.format(sinsp_logger::SEV_ERROR, "scap_get_fdlist failed, proc table will not be updated with new fds."); } scap_proc_free(m_inspector->m_h, scap_tinfo);