Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/c/bootstrap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ int handle_exec(struct trace_event_raw_sched_process_exec *ctx)
if (!e)
return 0;

/* zero out buffer to avoid leaking prior record bytes */
__builtin_memset(e, 0, sizeof(*e));

/* fill out the sample with data */
task = (struct task_struct *)bpf_get_current_task();

Expand Down Expand Up @@ -95,6 +98,9 @@ int handle_exit(struct trace_event_raw_sched_process_template *ctx)
if (!e)
return 0;

/* zero out buffer to avoid leaking prior record bytes */
__builtin_memset(e, 0, sizeof(*e));

/* fill out the sample with data */
task = (struct task_struct *)bpf_get_current_task();

Expand Down
11 changes: 11 additions & 0 deletions examples/c/profile.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ struct {
__uint(max_entries, 256 * 1024);
} events SEC(".maps");

/* zero out buffer (manual byte loop, struct is too big for inline memset) */
static __noinline void zero_buf(void *p, __u64 sz)
{
for (__u64 i = 0; i < sz; i++)
*(volatile char *)((char *)p + i) = 0;
}

SEC("perf_event")
int profile(void *ctx)
{
Expand All @@ -26,6 +33,10 @@ int profile(void *ctx)
if (!event)
return 1;

/* zero out buffer to avoid leaking prior record bytes (kstack/ustack
* tail past *_sz is only partially written by bpf_get_stack) */
zero_buf(event, sizeof(*event));

event->pid = pid;
event->cpu_id = cpu_id;

Expand Down
4 changes: 4 additions & 0 deletions examples/c/sockfilter.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ int socket_handler(struct __sk_buff *skb)
if (!e)
return 0;

/* zero out buffer to avoid leaking prior record bytes (the GRE
* branch below skips writing src_addr/dst_addr) */
__builtin_memset(e, 0, sizeof(*e));

bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, protocol), &e->ip_proto, 1);

if (e->ip_proto != IPPROTO_GRE) {
Expand Down