* [PATCH bpf] libbpf: set BTF FD for prog only when there is supported .BTF.ext data
@ 2019-08-01 7:24 Andrii Nakryiko
2019-08-01 15:47 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2019-08-01 7:24 UTC (permalink / raw)
To: bpf, netdev, ast, daniel, rdna
Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
introduced backwards-compatibility issue, manifesting itself as -E2BIG
error returned on program load due to unknown non-zero btf_fd attribute
value for BPF_PROG_LOAD sys_bpf() sub-command.
This patch fixes bug by ensuring that we only ever associate BTF FD with
program if there is a BTF.ext data that was successfully loaded into
kernel, which automatically means kernel supports func_info/line_info
and associated BTF FD for progs (checked and ensured also by BTF
sanitization code).
Fixes: 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
Reported-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/lib/bpf/libbpf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2e84fa5b8479..2b57d7ea7836 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2472,7 +2472,11 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
load_attr.license = license;
load_attr.kern_version = kern_version;
load_attr.prog_ifindex = prog->prog_ifindex;
- btf_fd = bpf_object__btf_fd(prog->obj);
+ /* if .BTF.ext was loaded, kernel supports associated BTF for prog */
+ if (prog->obj->btf_ext)
+ btf_fd = bpf_object__btf_fd(prog->obj);
+ else
+ btf_fd = -1;
load_attr.prog_btf_fd = btf_fd >= 0 ? btf_fd : 0;
load_attr.func_info = prog->func_info;
load_attr.func_info_rec_size = prog->func_info_rec_size;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] libbpf: set BTF FD for prog only when there is supported .BTF.ext data
2019-08-01 7:24 [PATCH bpf] libbpf: set BTF FD for prog only when there is supported .BTF.ext data Andrii Nakryiko
@ 2019-08-01 15:47 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2019-08-01 15:47 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
Andrey Ignatov, Andrii Nakryiko, Kernel Team
On Thu, Aug 1, 2019 at 12:41 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
> introduced backwards-compatibility issue, manifesting itself as -E2BIG
> error returned on program load due to unknown non-zero btf_fd attribute
> value for BPF_PROG_LOAD sys_bpf() sub-command.
>
> This patch fixes bug by ensuring that we only ever associate BTF FD with
> program if there is a BTF.ext data that was successfully loaded into
> kernel, which automatically means kernel supports func_info/line_info
> and associated BTF FD for progs (checked and ensured also by BTF
> sanitization code).
>
> Fixes: 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD")
> Reported-by: Andrey Ignatov <rdna@fb.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Applied. Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-01 15:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 7:24 [PATCH bpf] libbpf: set BTF FD for prog only when there is supported .BTF.ext data Andrii Nakryiko
2019-08-01 15:47 ` Alexei Starovoitov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.