examples/c: Fix ringbuf leaks in C libbpf examples#367
Open
vdasu wants to merge 1 commit intolibbpf:masterfrom
Open
examples/c: Fix ringbuf leaks in C libbpf examples#367vdasu wants to merge 1 commit intolibbpf:masterfrom
vdasu wants to merge 1 commit intolibbpf:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three libbpf-bootstrap examples (
bootstrap,profile, andsockfilter) callbpf_ringbuf_reserve()to obtain an event buffer, populate a subset of the event's fields, and emit the fullsizeof(*event)bytes viabpf_ringbuf_submit().bpf_ringbuf_reserve()does not zero-initialize the returned memory. Any bytes the source-level path leaves unwritten retain whatever the slot held previously. This can leak previously emitted record content back to userspace on subsequent events.The
bootstrapleak was tested on Linux 6.8.struct eventis written by two asymmetric handlers (handle_execandhandle_exit), each of which leaves the other handler's fields untouched, plus a 4-byte padding hole that neither handler writes. Across 3,000 captured events, exit events leaked prior exec records'filenamepaths and exec events leaked prior exit records'exit_code/duration_nsbytes.__builtin_memset(event, 0, sizeof(*event))does not work forprofilesince the struct (2080 bytes) exceeds LLVM's inline-store budget. LLVM lowers this memset to a libcall, which BPF programs do not support. BPF cannot link against libc and the BPF backend has nomemsetsymbol to resolve, which causes compilation to fail. The addedzero_buf()helper avoids this by writing the byte loop explicitly in a__noinlinesubprogram, so it lands as a single BPF-to-BPF call, and by usingvolatilewrites so LLVM's loop-idiom recognition does not re-lower it back into__builtin_memset.