Skip to content

Commit b3b36e1

Browse files
committed
Switch to intersection of the two states
Signed-off-by: Alan Jowett <[email protected]>
1 parent c48889c commit b3b36e1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/crab_verifier.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,31 @@ thread_local crab::lazy_allocator<program_info> thread_local_program_info;
2424
thread_local ebpf_verifier_options_t thread_local_options;
2525
void ebpf_verifier_clear_before_analysis();
2626

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+
2742
bool Invariants::is_valid_after(const label_t& label, const string_invariant& state) const {
2843
const ebpf_domain_t abstract_state =
2944
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();
3146
}
3247

3348
bool Invariants::is_valid_before(const label_t& label, const string_invariant& state) const {
3449
const ebpf_domain_t abstract_state =
3550
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();
3752
}
3853

3954
string_invariant Invariants::invariant_at(const label_t& label) const { return invariants.at(label).post.to_set(); }

0 commit comments

Comments
 (0)