Skip to content

Commit

Permalink
fix(userspace/libscap): prevent libbf stats from being collected with…
Browse files Browse the repository at this point in the history
… no bpf stats

Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Nov 15, 2023
1 parent 477b6a0 commit 1b68561
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions userspace/libscap/engine/bpf/scap_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,12 @@ const struct scap_stats_v2* scap_bpf_get_stats_v2(struct scap_engine_handle engi
return NULL;
}

// we can't collect libbpf stats if bpf stats are not enabled
if (!(handle->m_flags & ENGINE_FLAG_BPF_STATS_ENABLED))
{
flags &= ~PPM_SCAP_STATS_LIBBPF_STATS;
}

if ((flags & PPM_SCAP_STATS_KERNEL_COUNTERS) && (BPF_MAX_KERNEL_COUNTERS_STATS <= nstats_allocated))
{
/* KERNEL SIDE STATS COUNTERS */
Expand Down
6 changes: 6 additions & 0 deletions userspace/libscap/engine/modern_bpf/scap_modern_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ int32_t scap_modern_bpf__get_stats(struct scap_engine_handle engine, OUT scap_st

const struct scap_stats_v2* scap_modern_bpf__get_stats_v2(struct scap_engine_handle engine, uint32_t flags, OUT uint32_t* nstats, OUT int32_t* rc)
{
struct modern_bpf_engine* handle = engine.m_handle;
if (!(handle->m_flags & ENGINE_FLAG_BPF_STATS_ENABLED))
{
// we can't collect libbpf stats if bpf stats are not enabled
flags &= ~PPM_SCAP_STATS_LIBBPF_STATS;
}
return pman_get_scap_stats_v2(flags, nstats, rc);
}

Expand Down

0 comments on commit 1b68561

Please sign in to comment.