iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

libbpf-tools/ksnoop: perf buffer fix unnecessary junk bits output #4868

Closed linfeng2999 closed 8 months ago

linfeng2999 commented 8 months ago

In output_trace() bpf_perf_event_output determins its even size (trace_len in this function) based on the fact that trace->buf is at the end of struct trace:

trace_len = sizeof(*trace) + trace->buf_len - MAX_TRACE_BUF;

Commit e9f140f0fea0 ("libbpf-tools: Fix memory leaks in ksnoop/gethostlatency") breaks that rule and we will put 2 pointers size more junk bits into perf buffer. Fix this by moving forward the new added tailing pointers to its proper place(commented as readonly segment).

chenhengqi commented 8 months ago

Good catch, thanks.