bpf: fix states equal logic for varlen access
authorJosef Bacik <jbacik@fb.com>
Tue, 29 Nov 2016 17:27:09 +0000 (12:27 -0500)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Nov 2016 19:50:52 +0000 (14:50 -0500)
commite2d2afe15ed452f91797a80dbc0a17838ba03ed4
tree44cb85851f4f9aebe00a6405197e4766bed2cf83
parent0fcba2894c6b370ebf4b49099d20ff6333a430f7
bpf: fix states equal logic for varlen access

If we have a branch that looks something like this

int foo = map->value;
if (condition) {
  foo += blah;
} else {
  foo = bar;
}
map->array[foo] = baz;

We will incorrectly assume that the !condition branch is equal to the condition
branch as the register for foo will be UNKNOWN_VALUE in both cases.  We need to
adjust this logic to only do this if we didn't do a varlen access after we
processed the !condition branch, otherwise we have different ranges and need to
check the other branch as well.

Fixes: 484611357c19 ("bpf: allow access into map value arrays")
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Acked-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