]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
bpf: simplify verifier register state assignments
authorAlexei Starovoitov <ast@fb.com>
Thu, 7 Apr 2016 02:39:21 +0000 (19:39 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Apr 2016 02:43:18 +0000 (22:43 -0400)
verifier is using the following structure to track the state of registers:
struct reg_state {
    enum bpf_reg_type type;
    union {
        int imm;
        struct bpf_map *map_ptr;
    };
};
and later on in states_equal() does memcmp(&old->regs[i], &cur->regs[i],..)
to find equivalent states.
Throughout the code of verifier there are assignements to 'imm' and 'map_ptr'
fields and it's not obvious that most of the assignments into 'imm' don't
need to clear extra 4 bytes (like mark_reg_unknown_value() does) to make sure
that memcmp doesn't go over junk left from 'map_ptr' assignment.

Simplify the code by converting 'int' into 'long'

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/verifier.c

index 8233021538d34fcf024904eb1e794526d9776e18..6c5d7cd4cb0ee9a12c8b82c946cb8319054531f3 100644 (file)
@@ -142,7 +142,7 @@ struct reg_state {
        enum bpf_reg_type type;
        union {
                /* valid when type == CONST_IMM | PTR_TO_STACK */
-               int imm;
+               long imm;
 
                /* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
                 *   PTR_TO_MAP_VALUE_OR_NULL
@@ -263,7 +263,7 @@ static void print_verifier_state(struct verifier_env *env)
                        continue;
                verbose(" R%d=%s", i, reg_type_str[t]);
                if (t == CONST_IMM || t == PTR_TO_STACK)
-                       verbose("%d", env->cur_state.regs[i].imm);
+                       verbose("%ld", env->cur_state.regs[i].imm);
                else if (t == CONST_PTR_TO_MAP || t == PTR_TO_MAP_VALUE ||
                         t == PTR_TO_MAP_VALUE_OR_NULL)
                        verbose("(ks=%d,vs=%d)",
@@ -480,7 +480,6 @@ static void init_reg_state(struct reg_state *regs)
        for (i = 0; i < MAX_BPF_REG; i++) {
                regs[i].type = NOT_INIT;
                regs[i].imm = 0;
-               regs[i].map_ptr = NULL;
        }
 
        /* frame pointer */
@@ -495,7 +494,6 @@ static void mark_reg_unknown_value(struct reg_state *regs, u32 regno)
        BUG_ON(regno >= MAX_BPF_REG);
        regs[regno].type = UNKNOWN_VALUE;
        regs[regno].imm = 0;
-       regs[regno].map_ptr = NULL;
 }
 
 enum reg_arg_type {