bpf: Add array support to btf_struct_access
authorMartin KaFai Lau <kafai@fb.com>
Thu, 7 Nov 2019 18:09:03 +0000 (10:09 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 7 Nov 2019 18:59:08 +0000 (10:59 -0800)
commit7e3617a72df32341fea6d226cd6bb21de40c558d
treeda83dde50a5e7873bd6689b70ff8539973841714
parent30ee348c1267f5e69875a953e3b9cd5da83252a4
bpf: Add array support to btf_struct_access

This patch adds array support to btf_struct_access().
It supports array of int, array of struct and multidimensional
array.

It also allows using u8[] as a scratch space.  For example,
it allows access the "char cb[48]" with size larger than
the array's element "char".  Another potential use case is
"u64 icsk_ca_priv[]" in the tcp congestion control.

btf_resolve_size() is added to resolve the size of any type.
It will follow the modifier if there is any.  Please
see the function comment for details.

This patch also adds the "off < moff" check at the beginning
of the for loop.  It is to reject cases when "off" is pointing
to a "hole" in a struct.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191107180903.4097702-1-kafai@fb.com
kernel/bpf/btf.c