]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bpf: verifier: record original instruction index
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 23 Jan 2019 06:45:23 +0000 (22:45 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 24 Jan 2019 01:35:32 +0000 (17:35 -0800)
The communication between the verifier and advanced JITs is based
on instruction indexes.  We have to keep them stable throughout
the optimizations otherwise referring to a particular instruction
gets messy quickly.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf_verifier.h
kernel/bpf/verifier.c

index 573cca00a0e6cda76014e8a0610aaaf994a78455..f3ae00ee5516e9d176f6f4c8a9faba8a01731952 100644 (file)
@@ -187,6 +187,7 @@ struct bpf_insn_aux_data {
        int sanitize_stack_off; /* stack slot to be cleared */
        bool seen; /* this insn was processed by the verifier */
        u8 alu_state; /* used in combination with alu_limit */
+       unsigned int orig_idx; /* original instruction index */
 };
 
 #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
index f39bca188a5c21643822aea81d0bd5b33c5f259f..f2c49b4235df8d6bdb08ece70e27484cc501f055 100644 (file)
@@ -7371,7 +7371,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
 {
        struct bpf_verifier_env *env;
        struct bpf_verifier_log *log;
-       int ret = -EINVAL;
+       int i, len, ret = -EINVAL;
        bool is_priv;
 
        /* no program is valid */
@@ -7386,12 +7386,14 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
                return -ENOMEM;
        log = &env->log;
 
+       len = (*prog)->len;
        env->insn_aux_data =
-               vzalloc(array_size(sizeof(struct bpf_insn_aux_data),
-                                  (*prog)->len));
+               vzalloc(array_size(sizeof(struct bpf_insn_aux_data), len));
        ret = -ENOMEM;
        if (!env->insn_aux_data)
                goto err_free_env;
+       for (i = 0; i < len; i++)
+               env->insn_aux_data[i].orig_idx = i;
        env->prog = *prog;
        env->ops = bpf_verifier_ops[env->prog->type];