bpf: Populate field_offs for inner_map_meta
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 18 Nov 2022 01:55:54 +0000 (07:25 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 18 Nov 2022 03:11:32 +0000 (19:11 -0800)
commitf73e601aafb2ad9f2b2012b969f86f4a41141a7d
treecd2a208ade233b9f7a94c0eb6f8bb79ec24d37cd
parentd48995723c9a1c4896206be382c72d722accbfbc
bpf: Populate field_offs for inner_map_meta

Far too much code simply assumes that both btf_record and btf_field_offs
are set to valid pointers together, or both are unset. They go together
hand in hand as btf_record describes the special fields and
btf_field_offs is compact representation for runtime copying/zeroing.

It is very difficult to make this clear in the code when the only
exception to this universal invariant is inner_map_meta which is used
as reg->map_ptr in the verifier. This is simply a bug waiting to happen,
as in verifier context we cannot easily distinguish if PTR_TO_MAP_VALUE
is coming from an inner map, and if we ever end up using field_offs for
any reason in the future, we will silently ignore the special fields for
inner map case (as NULL is not an error but unset field_offs).

Hence, simply copy field_offs from inner map together with btf_record.

While at it, refactor code to unwind properly on errors with gotos.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20221118015614.2013203-5-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/map_in_map.c