Re: [PATCH bpf-next v3 1/8] bpf: Add bpf_kallsyms_lookup_name helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux