Skip to content

Commit

Permalink
bpf: fix state equivalence
Browse files Browse the repository at this point in the history
Commmits 57a09bf ("bpf: Detect identical PTR_TO_MAP_VALUE_OR_NULL registers")
and 4846113 ("bpf: allow access into map value arrays") by themselves
are correct, but in combination they make state equivalence ignore 'id' field
of the register state which can lead to accepting invalid program.

Fixes: 57a09bf ("bpf: Detect identical PTR_TO_MAP_VALUE_OR_NULL registers")
Fixes: 4846113 ("bpf: allow access into map value arrays")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexei Starovoitov authored and David S. Miller committed Dec 8, 2016
1 parent 3665f38 commit d2a4dd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions include/linux/bpf_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@

struct bpf_reg_state {
enum bpf_reg_type type;
/*
* Used to determine if any memory access using this register will
* result in a bad access.
*/
s64 min_value;
u64 max_value;
u32 id;
union {
/* valid when type == CONST_IMM | PTR_TO_STACK | UNKNOWN_VALUE */
s64 imm;
Expand All @@ -40,6 +33,13 @@ struct bpf_reg_state {
*/
struct bpf_map *map_ptr;
};
u32 id;
/* Used to determine if any memory access using this register will
* result in a bad access. These two fields must be last.
* See states_equal()
*/
s64 min_value;
u64 max_value;
};

enum bpf_stack_slot_type {
Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,7 @@ static bool states_equal(struct bpf_verifier_env *env,
* we didn't do a variable access into a map then we are a-ok.
*/
if (!varlen_map_access &&
rold->type == rcur->type && rold->imm == rcur->imm)
memcmp(rold, rcur, offsetofend(struct bpf_reg_state, id)) == 0)
continue;

/* If we didn't map access then again we don't care about the
Expand Down

0 comments on commit d2a4dd3

Please sign in to comment.