Re: [RFC/PATCH bpf-next 2/3] mm/bpf: Add bpf_get_kmem_cache() kfunc
From: Alexei Starovoitov
Date: Sun Sep 29 2024 - 13:06:40 EST
On Fri, Sep 27, 2024 at 11:41 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> +__bpf_kfunc struct kmem_cache *bpf_get_kmem_cache(u64 addr)
> +{
> + struct slab *slab;
> +
> + slab = virt_to_slab((void *)(long)addr);
> + return slab ? slab->slab_cache : NULL;
> +}
I think this needs more safety guards on 'addr'.
It needs to check the valid range of 'addr' before doing virt_to_slab.