aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-05-13 13:08:31 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-16 13:49:32 -0400
commitd1c55ab5e41fcd72cb0a8bef86d3f652ad9ad9f5 (patch)
tree70d10a938de18a64f103de01ab2ffa8a66e52178 /kernel/bpf
parentc237ee5eb33bf19fe0591c04ff8db19da7323a83 (diff)
bpf: prepare bpf_int_jit_compile/bpf_prog_select_runtime apis
Since the blinding is strictly only called from inside eBPF JITs, we need to change signatures for bpf_int_jit_compile() and bpf_prog_select_runtime() first in order to prepare that the eBPF program we're dealing with can change underneath. Hence, for call sites, we need to return the latest prog. No functional change in this patch. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/core.c18
-rw-r--r--kernel/bpf/syscall.c2
2 files changed, 15 insertions, 5 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 49b5538a5301..70f0821aca47 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -761,15 +761,22 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
761/** 761/**
762 * bpf_prog_select_runtime - select exec runtime for BPF program 762 * bpf_prog_select_runtime - select exec runtime for BPF program
763 * @fp: bpf_prog populated with internal BPF program 763 * @fp: bpf_prog populated with internal BPF program
764 * @err: pointer to error variable
764 * 765 *
765 * Try to JIT eBPF program, if JIT is not available, use interpreter. 766 * Try to JIT eBPF program, if JIT is not available, use interpreter.
766 * The BPF program will be executed via BPF_PROG_RUN() macro. 767 * The BPF program will be executed via BPF_PROG_RUN() macro.
767 */ 768 */
768int bpf_prog_select_runtime(struct bpf_prog *fp) 769struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
769{ 770{
770 fp->bpf_func = (void *) __bpf_prog_run; 771 fp->bpf_func = (void *) __bpf_prog_run;
771 772
772 bpf_int_jit_compile(fp); 773 /* eBPF JITs can rewrite the program in case constant
774 * blinding is active. However, in case of error during
775 * blinding, bpf_int_jit_compile() must always return a
776 * valid program, which in this case would simply not
777 * be JITed, but falls back to the interpreter.
778 */
779 fp = bpf_int_jit_compile(fp);
773 bpf_prog_lock_ro(fp); 780 bpf_prog_lock_ro(fp);
774 781
775 /* The tail call compatibility check can only be done at 782 /* The tail call compatibility check can only be done at
@@ -777,7 +784,9 @@ int bpf_prog_select_runtime(struct bpf_prog *fp)
777 * with JITed or non JITed program concatenations and not 784 * with JITed or non JITed program concatenations and not
778 * all eBPF JITs might immediately support all features. 785 * all eBPF JITs might immediately support all features.
779 */ 786 */
780 return bpf_check_tail_call(fp); 787 *err = bpf_check_tail_call(fp);
788
789 return fp;
781} 790}
782EXPORT_SYMBOL_GPL(bpf_prog_select_runtime); 791EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
783 792
@@ -859,8 +868,9 @@ const struct bpf_func_proto bpf_tail_call_proto = {
859}; 868};
860 869
861/* For classic BPF JITs that don't implement bpf_int_jit_compile(). */ 870/* For classic BPF JITs that don't implement bpf_int_jit_compile(). */
862void __weak bpf_int_jit_compile(struct bpf_prog *prog) 871struct bpf_prog * __weak bpf_int_jit_compile(struct bpf_prog *prog)
863{ 872{
873 return prog;
864} 874}
865 875
866bool __weak bpf_helper_changes_skb_data(void *func) 876bool __weak bpf_helper_changes_skb_data(void *func)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index cf5e9f7ad13a..46ecce4b79ed 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -762,7 +762,7 @@ static int bpf_prog_load(union bpf_attr *attr)
762 fixup_bpf_calls(prog); 762 fixup_bpf_calls(prog);
763 763
764 /* eBPF program is ready to be JITed */ 764 /* eBPF program is ready to be JITed */
765 err = bpf_prog_select_runtime(prog); 765 prog = bpf_prog_select_runtime(prog, &err);
766 if (err < 0) 766 if (err < 0)
767 goto free_used_maps; 767 goto free_used_maps;
768 768