Re: UBSAN: array-index-out-of-bounds in kernel/bpf/arraymap.c:177

From: Qian Cai
Date: Tue May 19 2020 - 21:55:51 EST




> On May 19, 2020, at 7:23 PM, Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote:
>
> I agree, it's bad to have this noise. But again, there is nothing
> wrong with the way it's used in BPF code base. We'd gladly use
> flexible array, if we could. But given we can't, I'd say the proper
> solution (in order of my preference) would be:
>
> - don't trigger false error, if zero-sized array is the member of union;
> - or have some sort of annotation at field declaration site (not a
> field access site).
>
> Is that possible?

I am not a compiler expert, but with my experience with all those compiler instrumental technology like KCSAN, KASAN and UBSAN, it seems both options you prop need to modify compilers, i.e., -fsanitize=undefined