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

Dereferencing pointes via [0] fails to load the program #3016

Closed
viktormalik opened this issue Feb 22, 2024 · 0 comments · Fixed by #3024
Closed

Dereferencing pointes via [0] fails to load the program #3016

viktormalik opened this issue Feb 22, 2024 · 0 comments · Fixed by #3024
Assignees
Labels
bug Something isn't working

Comments

@viktormalik
Copy link
Contributor

When trying to dereference a kernel pointer with [0], the BPF verifier refuses to load the program.

This program:

#! /usr/bin/bpftrace

struct ib_gid_table_entry {
        struct kref                     kref;
        struct work_struct              del_work;
        struct ib_gid_attr              attr;
};

kfunc:find_gid
{
        print(args.table->data_vec[0]->attr.gid.raw);
}

triggers a verifier error:

$ sudo test.bt
INFO: node count: 15
Attaching 1 probe...

Error log: 
reg type unsupported for arg#0 function kfunc_ib_core_find_gid#22
0: R1=ctx(off=0,imm=0) R10=fp0
0: (79) r1 = *(u64 *)(r1 +0)
func 'find_gid' arg0 has btf_id 134135 type STRUCT 'ib_gid_table'
1: R1_w=ptr_ib_gid_table(off=0,imm=0)
1: (79) r1 = *(u64 *)(r1 +48)         ; R1_w=scalar()
2: (79) r3 = *(u64 *)(r1 +0)
R1 invalid mem access 'scalar'
processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

ERROR: Error loading program: kfunc:ib_core:find_gid

However, this works fine:

#! /usr/bin/bpftrace

struct ib_gid_table_entry {
        struct kref                     kref;
        struct work_struct              del_work;
        struct ib_gid_attr              attr;
};

kfunc:find_gid
{
        print((*args.table->data_vec)->attr.gid.raw);
}

Interestingly, the second example works even without the definition of struct ib_gid_table_entry (it's pulled from BTF of the ib_core module), omitting the struct def from the first example yields a different error:

$ bpftrace -e 'kfunc:find_gid { print(args.table->data_vec[0]->attr.gid.raw); }'
stdin:1:18-53: ERROR: Struct/union of type 'struct ib_gid_table_entry' does not contain a field named 'attr'
kfunc:find_gid { print(args.table->data_vec[0]->attr.gid.raw); }
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The issues are very likely connected (I suspect incorrect handling of [0] for pointer types in both field analyser and codegen).

@viktormalik viktormalik added the bug Something isn't working label Feb 22, 2024
@viktormalik viktormalik self-assigned this Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant