From acc8800b6f4380b6f4c7f04ee9a1263cf11deb35 Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Tue, 20 Dec 2022 11:33:51 +0100 Subject: [PATCH] tools: nfsslower: fix an uninitialized struct error Fixes the following error: bpf: Failed to load program: Permission denied reg type unsupported for arg#0 function trace_read_return#22 0: R1=ctx(off=0,imm=0) R10=fp0 ; int trace_read_return(struct pt_regs *ctx) 0: (bf) r6 = r1 ; R1=ctx(off=0,imm=0) R6_w=ctx(off=0,imm=0) [...] ; bpf_probe_read_kernel(&data.file, sizeof(data.file), (void *)qs.name); 75: (b7) r2 = 32 ; R2_w=32 76: (85) call bpf_probe_read_kernel#113 ; R0_w=scalar() fp-16=????mmmm fp-24=mmmmmmmm fp-32=mmmmmmmm fp-40=mmmmmmmm fp-48=mmmmmmmm ; bpf_perf_event_output(ctx, (void *)bpf_pseudo_fd(1, -2), CUR_CPU_IDENTIFIER, &data, sizeof(data)); 77: (18) r2 = 0xffff9a0a42177200 ; R2_w=map_ptr(off=0,ks=4,vs=4,imm=0) 79: (bf) r4 = r10 ; R4_w=fp0 R10=fp0 ; bpf_probe_read_kernel(&data.file, sizeof(data.file), (void *)qs.name); 80: (07) r4 += -104 ; R4_w=fp-104 ; bpf_perf_event_output(ctx, (void *)bpf_pseudo_fd(1, -2), CUR_CPU_IDENTIFIER, &data, sizeof(data)); 81: (bf) r1 = r6 ; R1_w=ctx(off=0,imm=0) R6=ctx(off=0,imm=0) 82: (18) r3 = 0xffffffff ; R3_w=4294967295 84: (b7) r5 = 96 ; R5_w=96 85: (85) call bpf_perf_event_output#25 invalid indirect read from stack R4 off -104+92 size 96 processed 82 insns (limit 1000000) max_states_per_insn 0 total_states 4 peak_states 4 mark_read 3 Traceback (most recent call last): File "/usr/share/bcc/tools/nfsslower", line 283, in b.attach_kretprobe(event="nfs_file_read", fn_name="trace_read_return") File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 872, in attach_kretprobe fn = self.load_func(fn_name, BPF.KPROBE) File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 523, in load_func raise Exception("Failed to load BPF program %s: %s" % Exception: Failed to load BPF program b'trace_read_return': Permission denied --- tools/nfsslower.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/nfsslower.py b/tools/nfsslower.py index b5df8f19..682a3fb7 100755 --- a/tools/nfsslower.py +++ b/tools/nfsslower.py @@ -179,8 +179,12 @@ static int trace_exit(struct pt_regs *ctx, int type) // populate output struct u32 size = PT_REGS_RC(ctx); - struct data_t data = {.type = type, .size = size, .delta_us = delta_us, - .pid = pid}; + struct data_t data; + __builtin_memset(&data, 0, sizeof(data)); + data.type = type; + data.size = size; + data.delta_us = delta_us; + data.pid = pid; data.ts_us = ts / 1000; data.offset = valp->offset; bpf_get_current_comm(&data.task, sizeof(data.task)); -- 2.38.1