Skip to content
Snippets Groups Projects
Commit b1ed7a57 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Greg Kroah-Hartman
Browse files

libbpf: Add explicit padding to bpf_xdp_set_link_opts


[ Upstream commit dde7b3f5 ]

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: bd5ca3ef ("libbpf: Add function to set link XDP fd while specifying old program")
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent f72e3d81
No related branches found
No related tags found
No related merge requests found
...@@ -507,6 +507,7 @@ struct xdp_link_info { ...@@ -507,6 +507,7 @@ struct xdp_link_info {
struct bpf_xdp_set_link_opts { struct bpf_xdp_set_link_opts {
size_t sz; size_t sz;
int old_fd; int old_fd;
size_t :0;
}; };
#define bpf_xdp_set_link_opts__last_field old_fd #define bpf_xdp_set_link_opts__last_field old_fd
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment