From: Alexei Starovoitov btf_resolve() does not see this loop: ptr -> typedef -> array -+ ^--------------+ The walk from the pointer stops at the array and marks the typedef as resolved. Only the limits of the later walks end the loop. The walk for special fields is going to lose its limit. Resolve structs and arrays first. Then a type that holds itself is always found. Such BTF does not load any more. Signed-off-by: Alexei Starovoitov --- kernel/bpf/btf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 242b011ba93a..fffde271bbd7 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6015,6 +6015,22 @@ static int btf_check_all_types(struct btf_verifier_env *env) return err; env->phase++; + /* + * Structs and arrays go first. A walk from a pointer stops at them and hides this loop: + * ptr -> typedef -> array -+ + * ^--------------+ + */ + for (i = btf->base_btf ? 0 : 1; i < btf->nr_types; i++) { + type_id = btf->start_id + i; + t = btf_type_by_id(btf, type_id); + + if ((btf_type_is_struct(t) || btf_type_is_array(t)) && + !env_type_is_resolved(env, type_id)) { + err = btf_resolve(env, t, type_id); + if (err) + return err; + } + } for (i = btf->base_btf ? 0 : 1; i < btf->nr_types; i++) { type_id = btf->start_id + i; t = btf_type_by_id(btf, type_id); -- 2.55.0