]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
libbpf: Add explicit padding to btf_dump_emit_type_decl_opts
authorKP Singh <kpsingh@kernel.org>
Fri, 19 Mar 2021 19:21:17 +0000 (19:21 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 08:50:01 +0000 (10:50 +0200)
commit75ad96b0077bd344a667c1fea41076ec82e531ed
tree3f4be2071462baf87e03bdf0bf3ed24f2490f507
parent590c62890cfbf1f54db8ec6775ab37264884f203
libbpf: Add explicit padding to btf_dump_emit_type_decl_opts

[ Upstream commit ea24b19562fe5f72c78319dbb347b701818956d9 ]

Similar to
https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org/

When DECLARE_LIBBPF_OPTS is used with inline field initialization, e.g:

  DECLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts,
    .field_name = var_ident,
    .indent_level = 2,
    .strip_mods = strip_mods,
  );

and compiled in debug mode, the compiler generates code which
leaves the padding uninitialized and triggers errors within libbpf APIs
which require strict zero initialization of OPTS structs.

Adding anonymous padding field fixes the issue.

Fixes: 9f81654eebe8 ("libbpf: Expose BTF-to-C type declaration emitting API")
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: KP Singh <kpsingh@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210319192117.2310658-1-kpsingh@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/btf.h