OSDN Git Service

bpf, libbpf: handle old kernels more graceful wrt global data sections
authorDaniel Borkmann <daniel@iogearbox.net>
Tue, 23 Apr 2019 22:45:56 +0000 (00:45 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 25 Apr 2019 20:47:29 +0000 (13:47 -0700)
commit8837fe5dd09bd0331b3e2d1b6e400b7fcda8963a
tree7582c3fbf5373b27befd235747ac44a58d083514
parenta21b48a2f2afa53bbc989cce6fc81edbed39eab0
bpf, libbpf: handle old kernels more graceful wrt global data sections

Andrii reported a corner case where e.g. global static data is present
in the BPF ELF file in form of .data/.bss/.rodata section, but without
any relocations to it. Such programs could be loaded before commit
d859900c4c56 ("bpf, libbpf: support global data/bss/rodata sections"),
whereas afterwards if kernel lacks support then loading would fail.

Add a probing mechanism which skips setting up libbpf internal maps
in case of missing kernel support. In presence of relocation entries,
we abort the load attempt.

Fixes: d859900c4c56 ("bpf, libbpf: support global data/bss/rodata sections")
Reported-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c