libbpf: Add explicit padding to bpf_xdp_set_link_opts
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 13 Mar 2021 21:09:17 +0000 (13:09 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 16 Mar 2021 19:26:49 +0000 (12:26 -0700)
commitdde7b3f5f2f458297aeccfd4783e53ab8ca046db
tree4cad154505d73c952a1da9bf073d3d90739d990c
parent4d0b93896ff8d6795ad8d1b604e41aa850d5a635
libbpf: Add explicit padding to bpf_xdp_set_link_opts

Adding such anonymous padding fixes the issue with uninitialized portions of
bpf_xdp_set_link_opts when using LIBBPF_DECLARE_OPTS macro with inline field
initialization:

DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1);

When such code is compiled in debug mode, compiler is generating code that
leaves padding bytes uninitialized, which triggers error inside libbpf APIs
that do strict zero initialization checks for OPTS structs.

Adding anonymous padding field fixes the issue.

Fixes: bd5ca3ef93cd ("libbpf: Add function to set link XDP fd while specifying old program")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org
tools/lib/bpf/libbpf.h