Skip to content

Commit

Permalink
bpf: Fix BPF_PROG_QUERY last field check
Browse files Browse the repository at this point in the history
While working on the cilium/ebpf Go 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 0).

Fixes: e420bed ("bpf: Add fd-based tcx multi-prog infra with link support")
Reported-by: Lorenz Bauer <lmb@isovalent.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
borkmann committed Oct 5, 2023
1 parent 4720852 commit cfa439e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/bpf/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -3913,7 +3913,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)
return ret;
}

#define BPF_PROG_QUERY_LAST_FIELD query.link_attach_flags
#define BPF_PROG_QUERY_LAST_FIELD query.revision

static int bpf_prog_query(const union bpf_attr *attr,
union bpf_attr __user *uattr)
Expand Down

0 comments on commit cfa439e

Please sign in to comment.