Re: [PATCH] bpf: btf: reject division by zero in btf_struct_walk for zero-size flex array elements

Leon Hwang
2026-04-13T10:24:07Z

Hi Dudu,

The "btf:" in the subject should be dropped. "bpf:" is enough.

BTW, a selftest is required to verify the change. If it is a BUG, the
selftest should reproduce it without the fix.

On 13/4/26 17:26, bot+bpf-ci@kernel.org wrote:
>> Fixes: 1dc92851849c ("bpf: kernel side support for BTF Var and DataSec")
[...]
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index a62d78581207..2365d9b1ef27 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -7152,6 +7152,13 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,
>> if (!btf_type_is_struct(t))
>> goto error;
>>
>> + /* Zero-size element type (e.g., empty struct) would cause
>> + * division by zero below. Reject the access.
>> + */
>
> This isn't a bug, but the BPF subsystem uses the style where the
> opening /* is on its own line for multi-line comments:
>
> /*
> * Zero-size element type (e.g., empty struct) would cause
> * division by zero below. Reject the access.
> */
>

AI review of the comment style is correct.

Thanks,
Leon

>> …