Re: [RFC PATCH v7 5/7] libbpf: Implement BTF type sorting validation for binary search optimization
From: Eduard Zingerman
Date: Fri Nov 21 2025 - 14:42:35 EST
On Thu, 2025-11-20 at 15:25 +0800, Donglin Peng wrote:
[...]
> Additionally, in the linear search branch, I saw there is a NULL check for
> the name returned by btf__name_by_offset. This suggests that checking
> name_off == 0 alone may not be sufficient to identify an anonymous type,
> which is why I used str_is_empty for a more robust check.
btf_str_by_offset(btf, offset) returns NULL only when 'offset' is
larger then 'btf->hdr.str_len'. However, function btf_check_meta()
verifies that this shall not happen by invoking
btf_name_offset_valid() check. The btf_check_meta() is invoked for all
types by btf_check_all_metas() called from btf_parse_base(),
btf_parse_module() and btf_parse_type_sec() -> btf_parse().
So, it appears that kernel protects itself from invalid name_off
values at BTF load time.
[...]