Re: [PATCH bpf-next v3 1/8] bpf: Add bpf_kallsyms_lookup_name helper
From: Alexei Starovoitov <hidden>
Date: 2021-10-20 18:04:24
Also in:
bpf
From: Alexei Starovoitov <hidden>
Date: 2021-10-20 18:04:24
Also in:
bpf
On Fri, Oct 15, 2021 at 02:26:37AM +0530, Kumar Kartikeya Dwivedi wrote:
This helper allows us to get the address of a kernel symbol from inside a BPF_PROG_TYPE_SYSCALL prog (used by gen_loader), so that we can relocate typeless ksym vars.
...
+BPF_CALL_4(bpf_kallsyms_lookup_name, const char *, name, int, name_sz, int, flags, u64 *, res)
+{
+ if (flags)
+ return -EINVAL;
+
+ if (name_sz <= 1 || name[name_sz - 1])
+ return -EINVAL;
+
+ *res = kallsyms_lookup_name(name);
+ return *res ? 0 : -ENOENT;
+}
+
+const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
+ .func = bpf_kallsyms_lookup_name,
+ .gpl_only = true,When libbpf is processing of typeless ksyms it parses /proc/kallsyms. There is no gpl-ness in the action of reading this file. Hence above should be '= false' for consistency between light and regular skeleton. But different check is necessary. This helper is available to syscall_bpf prog type (which is CAP_BPF) and shouldn't be used to bypass kptr checks. So bpf_kallsyms_lookup_name() should probably have: if (!bpf_dump_raw_ok(current_cred()))) return -EPERM; The rest of the patches look great. Thank you for working on this!