Skip to content

Commit

Permalink
remove inproper usage of BPF_F_REUSE_STACKID in examples
Browse files Browse the repository at this point in the history
When the application bundles stack id with process specific
info (like pid, comm, etc.), BPF_F_REUSE_STACKID should not
be used as it may associate wrong stack with processes.

This patch corrected several such uses in examples/
directory.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Dec 6, 2019
1 parent 71f9c2a commit e7ddcbc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/lua/memleak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ return function(BPF, utils)
size_filter = "if (size > %d) return 0;" % args.max_size
end

local stack_flags = "BPF_F_REUSE_STACKID"
local stack_flags = "0"
if args.pid then
stack_flags = stack_flags .. "|BPF_F_USER_STACK"
end
Expand Down
2 changes: 1 addition & 1 deletion examples/lua/offcputime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int oncpu(struct pt_regs *ctx, struct task_struct *prev) {
// create map key
u64 zero = 0, *val;
struct key_t key = {};
int stack_flags = BPF_F_REUSE_STACKID;
int stack_flags = 0;
/*
if (!(prev->flags & PF_KTHREAD))
Expand Down
3 changes: 1 addition & 2 deletions examples/tracing/mallocstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
BPF_STACK_TRACE(stack_traces, """ + stacks + """);
int alloc_enter(struct pt_regs *ctx, size_t size) {
int key = stack_traces.get_stackid(ctx,
BPF_F_USER_STACK|BPF_F_REUSE_STACKID);
int key = stack_traces.get_stackid(ctx, BPF_F_USER_STACK);
if (key < 0)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing/stacksnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
u32 pid = bpf_get_current_pid_tgid();
FILTER
struct data_t data = {};
data.stack_id = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID),
data.stack_id = stack_traces.get_stackid(ctx, 0),
data.pid = pid;
bpf_get_current_comm(&data.comm, sizeof(data.comm));
events.perf_submit(ctx, &data, sizeof(data));
Expand Down

0 comments on commit e7ddcbc

Please sign in to comment.