提交 1f43f0ba 编写于 作者: J Jonathan Edwards 提交者: Zheng Zengkai

libbpf: Add extra BPF_PROG_TYPE check to bpf_object__probe_loading

mainline inclusion
from mainline-5.14-rc1
commit 5c10a3db
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5c10a3dbe9220ca7bcee716c13c8a8563bcb010a

-------------------------------------------------

eBPF has been backported for RHEL 7 w/ kernel 3.10-940+ [0]. However only
the following program types are supported [1]:

  BPF_PROG_TYPE_KPROBE
  BPF_PROG_TYPE_TRACEPOINT
  BPF_PROG_TYPE_PERF_EVENT

For libbpf this causes an EINVAL return during the bpf_object__probe_loading
call which only checks to see if programs of type BPF_PROG_TYPE_SOCKET_FILTER
can load.

The following will try BPF_PROG_TYPE_TRACEPOINT as a fallback attempt before
erroring out. BPF_PROG_TYPE_KPROBE was not a good candidate because on some
kernels it requires knowledge of the LINUX_VERSION_CODE.

  [0] https://www.redhat.com/en/blog/introduction-ebpf-red-hat-enterprise-linux-7
  [1] https://access.redhat.com/articles/3550581Signed-off-by: NJonathan Edwards <jonathan.edwards@165gc.onmicrosoft.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210619151007.GA6963@165gc.onmicrosoft.com
(cherry picked from commit 5c10a3db)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 22a2708d
...@@ -4039,6 +4039,10 @@ bpf_object__probe_loading(struct bpf_object *obj) ...@@ -4039,6 +4039,10 @@ bpf_object__probe_loading(struct bpf_object *obj)
attr.license = "GPL"; attr.license = "GPL";
ret = bpf_load_program_xattr(&attr, NULL, 0); ret = bpf_load_program_xattr(&attr, NULL, 0);
if (ret < 0) {
attr.prog_type = BPF_PROG_TYPE_TRACEPOINT;
ret = bpf_load_program_xattr(&attr, NULL, 0);
}
if (ret < 0) { if (ret < 0) {
ret = errno; ret = errno;
cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册