Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eBPF] Fix memory leak when reading lost statistics from perf buffer #6218

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

yinjiping
Copy link
Contributor

@yinjiping yinjiping commented Apr 23, 2024

This PR is for:

Caused a memory leak problem in the optimization PR(#5669) submitted earlier. When the user-mode program receives data from the perf buffer, the address of the handle is fwd_info instead of tracer. In this case, an error occurs when tracer->lost is read.

Here is the memory check information:

==16372== Invalid write of size 8
==16372==    at 0xC33AF4: atomic64_add (atomic.h:138)
==16372==    by 0xC33AF4: reader_lost_cb_a (perf_profiler.c:298)
==16372==    by 0xC3ACD5: perf_reader_event_read (perf_reader.c:205)
==16372==    by 0xC34AFD: reader_event_read (perf_reader.h:76)
==16372==    by 0xC34AFD: process_bpf_stacktraces (perf_profiler.c:985)
==16372==    by 0xC34AFD: cp_reader_work (perf_profiler.c:1076)
==16372==    by 0x4C51AC2: start_thread (pthread_create.c:442)
==16372==    by 0x4CE2A03: clone (clone.S:100)
==16372==  Address 0x40970898 is 24 bytes inside a block of size 30 alloc'd
==16372==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==16372==    by 0x65F333: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc.rs:98)
==16372==    by 0x6B9A7E: <deepflow_agent::flow_generator::protocol_logs::sql::mysql::MysqlLog as deepflow_agent::common::l7_protocol_log::L7ProtocolParserInterface>::parse_payload (raw_vec.rs:145)
==16372==    by 0x9F2E6A: deepflow_agent::flow_generator::perf::FlowLog::l7_parse_log (l7_protocol_log.rs:218)
==16372==    by 0x9ED85C: deepflow_agent::flow_generator::flow_map::FlowMap::collect_metric (mod.rs:455)
==16372==    by 0x9EA3F6: deepflow_agent::flow_generator::flow_map::FlowMap::inject_meta_packet (flow_map.rs:869)
==16372==    by 0x9DFBB2: deepflow_agent::ebpf_dispatcher::ebpf_dispatcher::EbpfDispatcher::run (ebpf_dispatcher.rs:251)
==16372==    by 0x855337: std::sys_common::backtrace::__rust_begin_short_backtrace (ebpf_dispatcher.rs:736)
==16372==    by 0x8694AD: core::ops::function::FnOnce::call_once{{vtable.shim}} (mod.rs:529)
==16372==    by 0x1765694: std::sys::pal::unix::thread::Thread::new::thread_start (boxed.rs:2015)
==16372==    by 0x4C51AC2: start_thread (pthread_create.c:442)
==16372==    by 0x4CE2A03: clone (clone.S:100)
  • Agent

Affected branches

  • main
  • v6.4

@yinjiping yinjiping linked an issue Apr 23, 2024 that may be closed by this pull request
Caused a memory leak problem in the optimization PR(#5669) submitted earlier. When the user-mode program receives data from the perf buffer, the address of the handle is fwd_info instead of tracer. In this case, an error occurs when tracer->lost is read.

Here is the memory check information:

==16372== Invalid write of size 8
==16372==    at 0xC33AF4: atomic64_add (atomic.h:138)
==16372==    by 0xC33AF4: reader_lost_cb_a (perf_profiler.c:298)
==16372==    by 0xC3ACD5: perf_reader_event_read (perf_reader.c:205)
==16372==    by 0xC34AFD: reader_event_read (perf_reader.h:76)
==16372==    by 0xC34AFD: process_bpf_stacktraces (perf_profiler.c:985)
==16372==    by 0xC34AFD: cp_reader_work (perf_profiler.c:1076)
==16372==    by 0x4C51AC2: start_thread (pthread_create.c:442)
==16372==    by 0x4CE2A03: clone (clone.S:100)
==16372==  Address 0x40970898 is 24 bytes inside a block of size 30 alloc'd
==16372==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==16372==    by 0x65F333: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc.rs:98)
==16372==    by 0x6B9A7E: <deepflow_agent::flow_generator::protocol_logs::sql::mysql::MysqlLog as deepflow_agent::common::l7_protocol_log::L7ProtocolParserInterface>::parse_payload (raw_vec.rs:145)
==16372==    by 0x9F2E6A: deepflow_agent::flow_generator::perf::FlowLog::l7_parse_log (l7_protocol_log.rs:218)
==16372==    by 0x9ED85C: deepflow_agent::flow_generator::flow_map::FlowMap::collect_metric (mod.rs:455)
==16372==    by 0x9EA3F6: deepflow_agent::flow_generator::flow_map::FlowMap::inject_meta_packet (flow_map.rs:869)
==16372==    by 0x9DFBB2: deepflow_agent::ebpf_dispatcher::ebpf_dispatcher::EbpfDispatcher::run (ebpf_dispatcher.rs:251)
==16372==    by 0x855337: std::sys_common::backtrace::__rust_begin_short_backtrace (ebpf_dispatcher.rs:736)
==16372==    by 0x8694AD: core::ops::function::FnOnce::call_once{{vtable.shim}} (mod.rs:529)
==16372==    by 0x1765694: std::sys::pal::unix::thread::Thread::new::thread_start (boxed.rs:2015)
==16372==    by 0x4C51AC2: start_thread (pthread_create.c:442)
==16372==    by 0x4CE2A03: clone (clone.S:100)
==16372==
@yinjiping yinjiping changed the title [eBPF] Fix memory leak when reading perf buffer lost data [eBPF] Fix memory leak when reading lost-statistics from perf buffer Apr 23, 2024
@yinjiping yinjiping changed the title [eBPF] Fix memory leak when reading lost-statistics from perf buffer [eBPF] Fix memory leak when reading lost statistics from perf buffer Apr 23, 2024
@sharang sharang enabled auto-merge (rebase) April 23, 2024 11:56
@sharang sharang merged commit c0f4cd0 into main Apr 23, 2024
7 checks passed
@sharang sharang deleted the fix_buffer_mem_leak branch April 23, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants