Skip to content

Commit 68dc346

Browse files
anakryikogregkh
authored andcommitted
libbpf: Add explicit padding to bpf_xdp_set_link_opts
[ Upstream commit dde7b3f ] 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: bd5ca3e ("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 85f9b06 commit 68dc346

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎tools/lib/bpf/libbpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ struct xdp_link_info {
507507
struct bpf_xdp_set_link_opts {
508508
size_t sz;
509509
int old_fd;
510+
size_t :0;
510511
};
511512
#define bpf_xdp_set_link_opts__last_field old_fd
512513

0 commit comments

Comments
 (0)