@@ -24,16 +24,31 @@ thread_local crab::lazy_allocator<program_info> thread_local_program_info;
24
24
thread_local ebpf_verifier_options_t thread_local_options;
25
25
void ebpf_verifier_clear_before_analysis ();
26
26
27
+ // Note:
28
+ // The check is intended to find abstract state values that violate the constraints of the
29
+ // pre or post invariant. The check is done by the crab library.
30
+ // There are 4 possible outcomes:
31
+ // 1. The abstract state contains an invariant that is not present in the pre or post invariant.
32
+ // 2. The pre or post invariant contains an invariant that is not present in the abstract state.
33
+ // 3. The abstract state contains an invariant that is present in the pre or post invariant and
34
+ // the value of the invariant is within the constraints of the pre or post invariant.
35
+ // 4. The abstract state contains an invariant that is present in the pre or post invariant, but the
36
+ // value of the invariant is not within the constraints of the pre or post invariant.
37
+ // The check should return false only for the 4th case where there is a violation of the constraints.
38
+ // Usage of <= doesn't work as there are cases where the externally provided state contains constraints
39
+ // that the pre and post invariant doesn't have. Examples are the registers where the pre and post invariant
40
+ // have 'havoc'ed the constraints, but the externally provided state has constraints on the registers.
41
+
27
42
bool Invariants::is_valid_after (const label_t & label, const string_invariant& state) const {
28
43
const ebpf_domain_t abstract_state =
29
44
ebpf_domain_t::from_constraints (state.value (), thread_local_options.setup_constraints );
30
- return abstract_state <= invariants.at (label).post ;
45
+ return !( abstract_state & invariants.at (label).post ). is_bottom () ;
31
46
}
32
47
33
48
bool Invariants::is_valid_before (const label_t & label, const string_invariant& state) const {
34
49
const ebpf_domain_t abstract_state =
35
50
ebpf_domain_t::from_constraints (state.value (), thread_local_options.setup_constraints );
36
- return abstract_state <= invariants.at (label).pre ;
51
+ return !( abstract_state & invariants.at (label).pre ). is_bottom () ;
37
52
}
38
53
39
54
string_invariant Invariants::invariant_at (const label_t & label) const { return invariants.at (label).post .to_set (); }
0 commit comments