[PATCH 2/2] x86/cfi,bpf: Fix BPF JIT call
Alexei Starovoitov
alexei.starovoitov at gmail.com
Wed Nov 22 16:51:23 PST 2023
On Wed, Nov 22, 2023 at 4:41 AM Peter Zijlstra <peterz at infradead.org> wrote:
>
>
> +/*
> + * Emit the various CFI preambles, see the large comment about FineIBT
> + * in arch/x86/kernel/alternative.c
.. and in cfi.h ..
which will have a copy-paste from your other email?
> prog->bpf_func = (void *)image + ctx.prog_offset;
> prog->jited = 1;
> prog->jited_len = proglen - ctx.prog_offset; // XXX?
Just drop XXX.
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1431,6 +1431,9 @@ struct bpf_prog_aux {
> struct bpf_kfunc_desc_tab *kfunc_tab;
> struct bpf_kfunc_btf_tab *kfunc_btf_tab;
> u32 size_poke_tab;
> +#ifdef CONFIG_FINEIBT
> + struct bpf_ksym ksym_prefix;
> +#endif
> struct bpf_ksym ksym;
> const struct bpf_prog_ops *ops;
> struct bpf_map **used_maps;
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -683,6 +683,23 @@ void bpf_prog_kallsyms_add(struct bpf_pr
> fp->aux->ksym.prog = true;
>
> bpf_ksym_add(&fp->aux->ksym);
> +
> +#ifdef CONFIG_FINEIBT
> + /*
> + * When FineIBT, code in the __cfi_foo() symbols can get executed
> + * and hence unwinder needs help.
> + */
I like the idea!
> + if (cfi_mode != CFI_FINEIBT)
> + return;
The cfi_mode var needs to be global along with enum ?
Or some new helper function from arch/x86 ?
> +
> + snprintf(fp->aux->ksym_prefix.name, KSYM_NAME_LEN,
> + "__cfi_%s", fp->aux->ksym.name);
> +
> + prog->aux->ksym_prefix.start = (unsigned long) prog->bpf_func - 16;
> + prog->aux->ksym_prefix.end = (unsigned long) prog->bpf_func;
> +
> + bpf_ksym_add(&fp->aux->ksym_prefix);
> +#endif
> }
>
> void bpf_prog_kallsyms_del(struct bpf_prog *fp)
and handle deletion of ksym_prefix here.
I think it's shaping up nicely.
Pls resend both patches as a set and cc bpf @ vger.
BPF CI will pick it up and test on arm64, x86-64, s390 with gcc and clang.
We don't do CONFIG_*IBT testing automatically, but
I can manually try that after the holidays.
More information about the linux-riscv
mailing list