Additional checks during cgroup discovery (#21148)
Limit cgroup discovery to a maximum number of entries and log a warning if exceeded
Stelios Fragkakis committed
Oct 15, 2025 at 11:16 UTC
211b482e962625602f0b604972aa69bcffed006f
1 file changed
+8
-1
src/collectors/cgroups.plugin/cgroup-discovery.c
+8
-1
@@ -823,7 +823,7 @@ static inline void discovery_share_cgroups_with_ebpf() {
823
}
824
sem_wait(shm_mutex_cgroup_ebpf);
825
826
- for (cg = cgroup_root, count = 0; cg; cg = cg->next, count++) {
826
+ for (cg = cgroup_root, count = 0; cg && count < cgroup_root_max; cg = cg->next, count++) {
827
netdata_ebpf_cgroup_shm_body_t *ptr = &shm_cgroup_ebpf.body[count];
828
char *prefix = (is_cgroup_systemd_service(cg)) ? services_chart_id_prefix : cgroup_chart_id_prefix;
829
snprintfz(ptr->name, CGROUP_EBPF_NAME_SHARED_LENGTH - 1, "%s%s", prefix, cg->chart_id);
@@ -843,6 +843,13 @@ static inline void discovery_share_cgroups_with_ebpf() {
843
netdata_log_debug(D_CGROUP, "cgroup shared: NAME=%s, ENABLED=%d", ptr->name, ptr->enabled);
844
}
845
846
+ if (unlikely(cg != NULL)) {
847
+ nd_log_limit_static_global_var(erl, 3600, 0);
848
+ nd_log_limit(&erl, NDLS_COLLECTORS, NDLP_WARNING,
849
+ "CGROUP: shared memory buffer full (%d cgroups). Some cgroups were not shared with eBPF.",
850
+ cgroup_root_max);
851
+ }
852
+
853
shm_cgroup_ebpf.header->cgroup_root_count = count;
854
sem_post(shm_mutex_cgroup_ebpf);
855
}