Skip to content

Commit a4fe783

Browse files
borkmannMartin KaFai Lau
authored and
Martin KaFai Lau
committed
bpf: Fix BPF_PROG_QUERY last field check
While working on the ebpf-go [0] library integration for bpf_mprog and tcx, Lorenz noticed that two subsequent BPF_PROG_QUERY requests currently fail. A typical workflow is to first gather the bpf_mprog count without passing program/ link arrays, followed by the second request which contains the actual array pointers. The initial call populates count and revision fields. The second call gets rejected due to a BPF_PROG_QUERY_LAST_FIELD bug which should point to query.revision instead of query.link_attach_flags since the former is really the last member. It was not noticed in libbpf as bpf_prog_query_opts() always calls bpf(2) with an on-stack bpf_attr that is memset() each time (and therefore query.revision was reset to zero). [0] https://ebpf-go.dev Fixes: e420bed ("bpf: Add fd-based tcx multi-prog infra with link support") Reported-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent c4d4919 commit a4fe783

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3913,7 +3913,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)
39133913
return ret;
39143914
}
39153915

3916-
#define BPF_PROG_QUERY_LAST_FIELD query.link_attach_flags
3916+
#define BPF_PROG_QUERY_LAST_FIELD query.revision
39173917

39183918
static int bpf_prog_query(const union bpf_attr *attr,
39193919
union bpf_attr __user *uattr)

0 commit comments

Comments
 (0)