Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAML witness validation by invariant checking #745

Merged
merged 26 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cd1af7a
Add yaml witness parsing prototype
sim642 May 24, 2022
7a85a96
Add yaml witness assert evaluation
sim642 May 24, 2022
d0d7558
Split conjunctions in yaml witness output to work around misparsing
sim642 May 24, 2022
f15bd32
Fix yaml witness validate not handling formals
sim642 May 24, 2022
f2acf16
Merge branch 'yaml-witness' into yaml-witness-validate
sim642 May 24, 2022
b6b8449
Use messages for yaml witness validation output
sim642 May 24, 2022
a3d3264
Validate yaml witnesses context sensitively
sim642 May 24, 2022
a92600d
Check parsed yaml witness invariants to avoid downstream crashing
sim642 May 25, 2022
7d3cd2f
Clean up YamlWitness.Validator
sim642 May 25, 2022
14c5129
Locate yaml witness invariants efficiently and inexactly
sim642 May 25, 2022
3841fe7
Hide mutex structure contents in base analysis
sim642 May 25, 2022
db1ce04
Insert explicit casts in IntDomain invariants
sim642 May 25, 2022
53495c1
Use long long zero in apron invariants to match lhs
sim642 May 25, 2022
1fa8d17
Use bot instead of top for base mutex contents
sim642 May 25, 2022
4c8d769
Use Frontc to parse yaml witness invariants
sim642 May 26, 2022
4e5e10c
Fix Cabs2cil mangling fundec locals during yaml witness invariant par…
sim642 May 26, 2022
b42da55
Use logical operators in yaml witness invariant parsing
sim642 May 26, 2022
4e99727
Add Question exp handling
sim642 May 26, 2022
f8f3984
Expand and fix exp pattern matching
sim642 May 26, 2022
7407e48
Add yaml witness certification
sim642 May 26, 2022
eb371f5
Deduplicate yaml witness entry creation
sim642 May 26, 2022
f2ff5f9
Aggregate yaml witness invariant results over lvars
sim642 May 26, 2022
79d2abe
Merge branch 'master' into yaml-witness-validate
sim642 May 27, 2022
a4937cf
Revert "Use bot instead of top for base mutex contents"
sim642 May 27, 2022
4bc3f35
Revert "Hide mutex structure contents in base analysis"
sim642 May 27, 2022
8b2cccf
Update CIL opam pin
sim642 May 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goblint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
# also remember to generate/adjust goblint.opam.locked!
pin-depends: [
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2" ]
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#fe7da7b4203735d84670e68f3044a9bf33bd6e65" ]
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
# quoter workaround reverted for release, so no pin needed
Expand Down
2 changes: 1 addition & 1 deletion goblint.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ version: "dev"
pin-depends: [
[
"goblint-cil.1.8.2"
"git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2"
"git+https://github.com/goblint/cil.git#fe7da7b4203735d84670e68f3044a9bf33bd6e65"
]
[
"apron.v0.9.13"
Expand Down
2 changes: 1 addition & 1 deletion goblint.opam.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
# also remember to generate/adjust goblint.opam.locked!
pin-depends: [
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2" ]
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#fe7da7b4203735d84670e68f3044a9bf33bd6e65" ]
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
# quoter workaround reverted for release, so no pin needed
Expand Down
12 changes: 11 additions & 1 deletion src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ struct
let x = Pretty.sprint ~width:80 (d_const () c) in (* escapes, see impl. of d_const in cil.ml *)
let x = String.sub x 2 (String.length x - 3) in (* remove surrounding quotes: L"foo" -> foo *)
`Address (AD.from_string x) (* `Address (AD.str_ptr ()) *)
| Const _ -> VD.top ()
(* Variables and address expressions *)
| Lval (Var v, ofs) -> do_offs (get a gs st (eval_lv a gs st (Var v, ofs)) (Some exp)) ofs
(*| Lval (Mem e, ofs) -> do_offs (get a gs st (eval_lv a gs st (Mem e, ofs))) ofs*)
Expand Down Expand Up @@ -797,7 +798,16 @@ struct
| CastE (t, exp) ->
let v = eval_rv a gs st exp in
VD.cast ~torg:(Cilfacade.typeOf exp) t v
| _ -> VD.top ()
| SizeOf _
| Real _
| Imag _
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _
| Question _
| AddrOfLabel _ ->
VD.top ()
in
if M.tracing then M.traceu "evalint" "base eval_rv_base %a -> %a\n" d_exp exp VD.pretty r;
r
Expand Down
16 changes: 14 additions & 2 deletions src/analyses/malloc_null.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ struct
| _ -> ()
in
match e with
| Lval (Var v, offs) -> ()
| Const _
| SizeOf _
| SizeOfStr _
| AlignOf _
| AddrOfLabel _
| Lval (Var _, _) -> ()
| AddrOf (Var _, _)
| StartOf (Var _, _) -> warn_lval_mem e NoOffset
| AddrOf (Mem e, offs)
Expand All @@ -77,9 +82,16 @@ struct
warn_deref_exp a st e1;
warn_deref_exp a st e2
| UnOp (_,e,_)
| Real e
| Imag e
| SizeOfE e
| AlignOfE e
| CastE (_,e) ->
warn_deref_exp a st e
| _ -> ()
| Question (b, t, f, _) ->
warn_deref_exp a st b;
warn_deref_exp a st t;
warn_deref_exp a st f

let may (f: 'a -> 'b) (x: 'a option) : unit =
match x with
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/tutorials/taint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct
| CastE (_,e)
| UnOp (_,e,_) -> is_exp_tainted state e
| SizeOf _ | SizeOfStr _ | Const _ | AlignOf _ | AddrOfLabel _ -> false
| Question _ -> failwith "should be optimized away by CIL"
| Question (b, t, f, _) -> is_exp_tainted state b || is_exp_tainted state t || is_exp_tainted state f
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
and is_lval_tainted state = function
| (Var v, _) ->
(* TODO: Check whether variable v is tainted *)
Expand Down
18 changes: 13 additions & 5 deletions src/analyses/uninit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,31 @@ struct

let rec access_one_byval a rw (exp:exp) =
match exp with
(* Integer literals *)
| Const _ -> []
| Const _
| SizeOf _
| SizeOfStr _
| AlignOf _
| AddrOfLabel _ -> []
(* Variables and address expressions *)
| Lval lval -> access_address a rw lval @ (access_lv_byval a lval)
(* Binary operators *)
| BinOp (op,arg1,arg2,typ) ->
let a1 = access_one_byval a rw arg1 in
let a2 = access_one_byval a rw arg2 in
a1 @ a2
(* Unary operators *)
| UnOp (op,arg1,typ) -> access_one_byval a rw arg1
| UnOp (_,e,_)
| Real e
| Imag e
| SizeOfE e
| AlignOfE e ->
access_one_byval a rw e
(* The address operators, we just check the accesses under them *)
| AddrOf lval -> access_lv_byval a lval
| StartOf lval -> access_lv_byval a lval
(* Most casts are currently just ignored, that's probably not a good idea! *)
| CastE (t, exp) -> access_one_byval a rw exp
| _ -> []
| Question (b, t, f, _) ->
access_one_byval a rw b @ access_one_byval a rw t @ access_one_byval a rw f
(* Accesses during the evaluation of an lval, not the lval itself! *)
and access_lv_byval a (lval:lval) =
let rec access_offset (ofs: offset) =
Expand Down
54 changes: 33 additions & 21 deletions src/analyses/varEq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ struct
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _ -> false
| UnOp (_,e,_) -> type_may_change_t e bt
| AlignOfE _
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
| UnOp (_,e,_)
| Real e
| Imag e -> type_may_change_t e bt
| BinOp (_,e1,e2,_) -> type_may_change_t e1 bt || type_may_change_t e2 bt
| Lval (Var _,o)
| AddrOf (Var _,o)
Expand All @@ -145,8 +148,7 @@ struct
| AddrOf (Mem e,o)
| StartOf (Mem e,o) -> may_change_t_offset o || type_may_change_t e bt
| CastE (t,e) -> type_may_change_t e bt
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."
| Question (b, t, f, _) -> type_may_change_t b bt || type_may_change_t t bt || type_may_change_t f bt
in
let bt = unrollTypeDeep (Cilfacade.typeOf b) in
type_may_change_t a bt
Expand All @@ -168,8 +170,11 @@ struct
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _ -> false
| UnOp (_,e,_) -> lval_may_change_pt e bl
| AlignOfE _
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
| UnOp (_,e,_)
| Real e
| Imag e -> lval_may_change_pt e bl
| BinOp (_,e1,e2,_) -> lval_may_change_pt e1 bl || lval_may_change_pt e2 bl
| Lval (Var _,o)
| AddrOf (Var _,o)
Expand All @@ -178,8 +183,7 @@ struct
| AddrOf (Mem e,o)
| StartOf (Mem e,o) -> may_change_pt_offset o || lval_may_change_pt e bl
| CastE (t,e) -> lval_may_change_pt e bl
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."
| Question (b, t, f, _) -> lval_may_change_pt t bl || lval_may_change_pt t bl || lval_may_change_pt f bl
in
let bls = pt b in
if Queries.LS.is_top bls
Expand Down Expand Up @@ -235,8 +239,11 @@ struct
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _ -> false
| UnOp (_,e,_) -> type_may_change_t deref e
| AlignOfE _
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
| UnOp (_,e,_)
| Real e
| Imag e -> type_may_change_t deref e
| BinOp (_,e1,e2,_) -> type_may_change_t deref e1 || type_may_change_t deref e2
| Lval (Var _,o)
| AddrOf (Var _,o)
Expand All @@ -245,8 +252,7 @@ struct
| AddrOf (Mem e,o) -> (*Messages.warn "Addr" ;*) may_change_t_offset o || type_may_change_t false e
| StartOf (Mem e,o) -> (*Messages.warn "Start";*) may_change_t_offset o || type_may_change_t false e
| CastE (t,e) -> type_may_change_t deref e
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."
| Question (b, t, f, _) -> type_may_change_t deref b || type_may_change_t deref t || type_may_change_t deref f

and lval_may_change_pt a bl : bool =
let rec may_change_pt_offset o =
Expand Down Expand Up @@ -301,8 +307,11 @@ struct
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _ -> false
| UnOp (_,e,_) -> lval_may_change_pt e bl
| AlignOfE _
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
| UnOp (_,e,_)
| Real e
| Imag e -> lval_may_change_pt e bl
| BinOp (_,e1,e2,_) -> lval_may_change_pt e1 bl || lval_may_change_pt e2 bl
| Lval (Var _,o)
| AddrOf (Var _,o)
Expand All @@ -311,8 +320,7 @@ struct
| AddrOf (Mem e,o)
| StartOf (Mem e,o) -> may_change_pt_offset o || lval_may_change_pt e bl
| CastE (t,e) -> lval_may_change_pt e bl
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."
| Question (b, t, f, _) -> lval_may_change_pt b bl || lval_may_change_pt t bl || lval_may_change_pt f bl
in
let r =
if Queries.LS.is_top bls || Queries.LS.mem (dummyFunDec.svar, `NoOffset) bls
Expand Down Expand Up @@ -350,7 +358,11 @@ struct
| AlignOf _
| AlignOfE _
| UnOp _
| BinOp _ -> None
| BinOp _
| Question _
| AddrOfLabel _
| Real _
| Imag _ -> None
| Const _ -> Some false
| Lval (Var v,_) ->
Some (v.vglob || (ask.f (Queries.IsMultiple v)))
Expand All @@ -365,8 +377,6 @@ struct
| AddrOf lv -> Some false (* TODO: sound?! *)
| StartOf (Var v,_) -> Some (ask.f (Queries.IsMultiple v)) (* Taking an address of a global is fine*)
| StartOf lv -> Some false (* TODO: sound?! *)
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."

(* Set given lval equal to the result of given expression. On doubt do nothing. *)
let add_eq ask (lv:lval) (rv:Exp.t) st =
Expand Down Expand Up @@ -528,6 +538,10 @@ struct
| AlignOfE _
| UnOp _
| BinOp _
| Question _
| AddrOfLabel _
| Real _
| Imag _
| AddrOf (Var _,_)
| StartOf (Var _,_)
| Lval (Var _,_) -> eq_set e s
Expand All @@ -539,8 +553,6 @@ struct
Queries.ES.map (fun e -> Lval (mkMem ~addr:e ~off:ofs)) (eq_set_clos e s)
| CastE (t,e) ->
Queries.ES.map (fun e -> CastE (t,e)) (eq_set_clos e s)
| Question _ -> failwith "Logical operations should be compiled away by CIL."
| _ -> failwith "Unmatched pattern."


let query ctx (type a) (x: a Queries.t): a Queries.result =
Expand Down
2 changes: 1 addition & 1 deletion src/cdomains/apron/apronDomain.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ struct


let cil_exp_of_lincons1 fundec (lincons1:Lincons1.t) =
let zero = Cil.zero in
let zero = Cil.kinteger ILongLong 0 in
sim642 marked this conversation as resolved.
Show resolved Hide resolved
try
let linexpr1 = Lincons1.get_linexpr1 lincons1 in
let cilexp = cil_exp_of_linexpr1 fundec linexpr1 in
Expand Down
30 changes: 25 additions & 5 deletions src/cdomains/basetype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,20 @@ struct
match e with
| Lval l -> occurs_lv l
| AddrOf l -> occurs_lv l
| UnOp (_,e,_) -> occurs x e
| StartOf l -> occurs_lv l
| UnOp (_,e,_)
| Real e
| Imag e
| SizeOfE e
| AlignOfE e -> occurs x e
| BinOp (_,e1,e2,_) -> occurs x e1 || occurs x e2
| CastE (_,e) -> occurs x e
| _ -> false
| Question (b, t, f, _) -> occurs x b || occurs x t || occurs x f
| Const _
| SizeOf _
| SizeOfStr _
| AlignOf _
| AddrOfLabel _ -> false

let replace (x:varinfo) (exp: exp) (e:exp): exp =
let rec replace_lv (v,offs): lval =
Expand All @@ -119,11 +129,21 @@ struct
match e with
| Lval (Var y, NoOffset) when Variables.equal x y -> exp
| Lval l -> Lval (replace_lv l)
| AddrOf l -> Lval (replace_lv l)
| AddrOf l -> Lval (replace_lv l) (* TODO: should be AddrOf? *)
| StartOf l -> StartOf (replace_lv l)
| UnOp (op,e,t) -> UnOp (op, replace_rv e, t)
| BinOp (op,e1,e2,t) -> BinOp (op, replace_rv e1, replace_rv e2, t)
| CastE (t,e) -> CastE(t, replace_rv e)
| x -> x
| Real e -> Real (replace_rv e)
| Imag e -> Imag (replace_rv e)
| SizeOfE e -> SizeOfE (replace_rv e)
| AlignOfE e -> AlignOfE (replace_rv e)
| Question (b, t, f, typ) -> Question (replace_rv b, replace_rv t, replace_rv f, typ)
| Const _
| SizeOf _
| SizeOfStr _
| AlignOf _
| AddrOfLabel _ -> e
in
constFold true (replace_rv e)

Expand All @@ -138,7 +158,7 @@ struct
| AlignOf _
| Question _
| AddrOf _
| StartOf _ -> []
| StartOf _ -> [] (* TODO: return not empty, some may contain vars! *)
| UnOp (_, e, _ )
| CastE (_, e)
| Real e
Expand Down
Loading