bpf: fix state equivalence
Subsystems (4)
PATCH 1/1 bpf: fix state equivalence
Commmits 57a09bf0a416 ("bpf: Detect identical PTR_TO_MAP_VALUE_OR_NULL registers") and 484611357c19 ("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.
---
this fix has to be done before net-next closes next week, so sending it now. Will add the test to test_verifier later.
include/linux/bpf_verifier.h | 14 +++++++------- kernel/bpf/verifier.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-)
include/linux/bpf_verifier.h +7 -7
@@ -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;
@@ -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 {
kernel/bpf/verifier.c +1 -1
@@ -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
Signature · 1 line
2.8.0
Quoted 9 lines · Alexei Starovoitov
Commmits
57a09bf0a416("bpf: Detect identicalPTR_TO_MAP_VALUE_OR_NULLregisters") and484611357c19("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 57a09bf0a416 ("bpf: Detect identical PTR_TO_MAP_VALUE_OR_NULL registers")Fixes 484611357c19 ("bpf: allow access into map value arrays")Signed-off-by Alexei Starovoitov <[email protected]>Acked-by Daniel Borkmann <[email protected]>
From: Alexei Starovoitov <[email protected]>
Date: Wed, 7 Dec 2016 10:57:59 -0800
Quoted 9 lines
Commmits
57a09bf0a416("bpf: Detect identicalPTR_TO_MAP_VALUE_OR_NULLregisters") and484611357c19("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 57a09bf0a416 ("bpf: Detect identical PTR_TO_MAP_VALUE_OR_NULL registers")Fixes 484611357c19 ("bpf: allow access into map value arrays")Signed-off-by Alexei Starovoitov <[email protected]>Acked-by Daniel Borkmann <[email protected]>
Applied.