Re: [PATCH] bpf: validate bpf_func when BPF_JIT is enabled

From: Sami Tolvanen
Date: Wed Sep 11 2019 - 16:30:10 EST


On Wed, Sep 11, 2019 at 12:43 AM Yonghong Song <yhs@xxxxxx> wrote:
> How about this:
>
> if (!IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON) && !prog->jited)
> goto out;
>
> if (unlikely(hdr->magic != BPF_BINARY_HEADER_MAGIC ||
> !arch_bpf_jit_check_func(prog))) {
> WARN(1, "attempt to jump to an invalid address");
> return 0;
> }
> out:
> return prog->bpf_func(ctx, prog->insnsi);

Sure, that does look cleaner. I'll use this in the next version. Thanks.

Sami