Skip to content

Commit 7701dff

Browse files
committed
fix: guard mount info cache initialization failure
Prevent proc-events from accessing an uninitialized mount info bihash when mount_info_cache_init() fails. Propagate the initialization error from create_and_init_proc_info_caches() and add runtime guards before mount info cache lookup/stat/root-check paths.
1 parent 34b62be commit 7701dff

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

agent/src/ebpf/user/mount.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ int mount_info_cache_init(const char *name)
216216

217217
struct mount_info *mount_info_cache_lookup(pid_t pid, u64 mntns_id)
218218
{
219+
if (!enable_mount_info_cache())
220+
return MOUNT_INFO_INVAL;
221+
219222
if (mntns_id == 0 && pid > 0) {
220223
if (get_mount_ns_id(pid, &mntns_id))
221224
return MOUNT_INFO_INVAL;
@@ -552,6 +555,9 @@ static int check_mount_kvp_cb(mount_info_hash_kv * kvp, void *ctx)
552555

553556
void collect_mount_info_stats(bool output_log)
554557
{
558+
if (!enable_mount_info_cache())
559+
return;
560+
555561
u64 elems_count = 0;
556562
mount_info_hash_t *h = &mount_info_hash;
557563
mount_info_hash_foreach_key_value_pair(h,
@@ -592,6 +598,9 @@ void check_and_cleanup_mount_info(pid_t pid, u64 mntns_id)
592598
// Periodically check whether the host node's mount information has changed.
593599
void check_root_mount_info(bool output_log)
594600
{
601+
if (!enable_mount_info_cache())
602+
return;
603+
595604
u32 new_hash = 0;
596605
hash_mountinfo_file(1, &new_hash);
597606
if (new_hash != 0 && new_hash != host_root_mountinfo_hash) {

agent/src/ebpf/user/proc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ void *get_symbol_cache(pid_t pid, bool new_cache)
762762
int create_and_init_proc_info_caches(void)
763763
{
764764
// Initialize the mount information cache.
765-
mount_info_cache_init("mount-info-cache");
765+
if (mount_info_cache_init("mount-info-cache")) {
766+
ebpf_warning("mount_info_cache_init() failed.\n");
767+
return ETR_NOMEM;
768+
}
766769

767770
/*
768771
* Building a 'proc_event_ring' for handling process events.

agent/src/ebpf/user/socket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,8 @@ int running_socket_tracer(tracer_callback_t handle,
30943094
socket_tracer_set_probes(tps);
30953095
golang_trace_init();
30963096
openssl_trace_init();
3097-
create_and_init_proc_info_caches();
3097+
if ((ret = create_and_init_proc_info_caches()))
3098+
return ret;
30983099

30993100
struct bpf_tracer *tracer =
31003101
setup_bpf_tracer(SK_TRACER_NAME, bpf_load_buffer_name,

0 commit comments

Comments
 (0)