bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 1/7] bpf: Fix BPF_PROG_QUERY last field check
@ 2023-10-06 22:06 Daniel Borkmann
  2023-10-06 22:06 ` [PATCH bpf 2/7] bpf: Handle bpf_mprog_query with NULL entry Daniel Borkmann
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Daniel Borkmann @ 2023-10-06 22:06 UTC (permalink / raw)
  To: bpf; +Cc: lmb, martin.lau, Daniel Borkmann

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: e420bed02507 ("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>
---
 kernel/bpf/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index eb01c31ed591..453a43695a23 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-07  5:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-06 22:06 [PATCH bpf 1/7] bpf: Fix BPF_PROG_QUERY last field check Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 2/7] bpf: Handle bpf_mprog_query with NULL entry Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 3/7] bpf: Refuse unused attributes in bpf_prog_{attach,detach} Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 4/7] selftests/bpf: Test bpf_mprog query API via libbpf and raw syscall Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 5/7] selftests/bpf: Adapt assert_mprog_count to always expect 0 count Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 6/7] selftests/bpf: Test query on empty mprog and pass revision into attach Daniel Borkmann
2023-10-06 22:06 ` [PATCH bpf 7/7] selftests/bpf: Make seen_tc* variable tests more robust Daniel Borkmann
2023-10-07  5:20 ` [PATCH bpf 1/7] bpf: Fix BPF_PROG_QUERY last field check patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).