-
Notifications
You must be signed in to change notification settings - Fork 4
/
nibridge_helper.v
20439 lines (19950 loc) · 668 KB
/
nibridge_helper.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import id_and_loc augmented mmemory mimperative language mlattice bridge types bijection Coq.Program.Tactics Coq.Program.Equality Arith Omega tactics low_equivalence decision preservation Coq.Program.Basics Coq.Logic.FunctionalExtensionality.
Require Import LibTactics.
Set Implicit Arguments.
Module NIBridgeHelper (L : Lattice) (M: Memory L).
Module Preserve := Preservation L M.
Import Preserve LowEq B Aug Imp TDefs M T MemProp LatProp Lang L.
Inductive contains_low_backat: level_proj1 -> cmd -> Prop :=
| ContainsLowBackAt:
forall ℓ l n,
l ⊑ ℓ ->
contains_low_backat ℓ (BackAt l n)
| ContainsLowBackAtSeq_left:
forall ℓ c1 c2,
contains_low_backat ℓ c1 -> contains_low_backat ℓ (c1;; c2)
| ContainsLowBackAtSeq_right:
forall ℓ c1 c2,
contains_low_backat ℓ c2 -> contains_low_backat ℓ (c1;; c2)
| ContainsLowBackAtIf_1:
forall ℓ e c1 c2,
contains_low_backat ℓ c1 -> contains_low_backat ℓ (If e c1 c2)
| ContainsLowBackAtIf_2:
forall ℓ e c1 c2,
contains_low_backat ℓ c2 -> contains_low_backat ℓ (If e c1 c2)
| ContainsLowBackAtWhile:
forall ℓ e c,
contains_low_backat ℓ c -> contains_low_backat ℓ (While e c)
| ContainsLowBackAtAt:
forall ℓ ℓ_at e c,
contains_low_backat ℓ c -> contains_low_backat ℓ (At ℓ_at e c).
Hint Constructors contains_low_backat.
Inductive ends_with_low_backat : level_proj1 -> cmd -> Prop :=
EndsWithLowBackAtBackAt:
forall ℓ l n,
l ⊑ ℓ ->
ends_with_low_backat ℓ (BackAt l n)
| EndsWithLowBackAtSeq:
forall ℓ c1 c2,
~ contains_low_backat ℓ c1 ->
ends_with_low_backat ℓ c2 -> ends_with_low_backat ℓ (c1;; c2)
| EndsWithLowBackAtAt:
forall ℓ c1 c2 pc e,
~ contains_low_backat ℓ c1 ->
ends_with_low_backat ℓ c2 -> ends_with_low_backat ℓ (At pc e c1).
Ltac invert_ends_with_backat :=
match goal with
[H: ends_with_low_backat _ _ |- _] =>
inverts H
end.
Lemma not_contains_low_backat_if:
forall ℓ e c1 c2,
~ contains_low_backat ℓ (If e c1 c2) ->
~ contains_low_backat ℓ c1 /\
~ contains_low_backat ℓ c2.
Proof.
intros.
splits*.
Qed.
Hint Resolve not_contains_low_backat_if.
Lemma not_contains_low_backat_seq:
forall ℓ c1 c2,
~ contains_low_backat ℓ c1 ->
~ contains_low_backat ℓ c2 ->
~ contains_low_backat ℓ (c1 ;; c2).
Proof.
intros.
intro.
inverts H1; contradiction.
Qed.
Hint Resolve not_contains_low_backat_seq.
Inductive high : level_proj1 -> Memory -> Heap -> loc -> Prop :=
| HighReachable:
forall ℓ_adv m h loc,
reach m h loc ->
high ℓ_adv m h loc
| HighHeapLevel:
forall ℓ_adv m h loc ℓ μ,
heap_lookup loc h = Some (ℓ, μ) ->
~ ℓ ⊑ ℓ_adv ->
high ℓ_adv m h loc.
Hint Constructors high.
Definition wf_taint_bijection ℓ_adv (Φ : bijection loc loc) m h :=
forall loc, (exists loc', left Φ loc = Some loc') <-> high ℓ_adv m h loc.
Hint Unfold wf_taint_bijection.
Inductive val_taint_eq: bijection loc loc -> sectype -> value -> value -> Prop :=
ValUntatedNum:
forall ℓ n Φ,
val_taint_eq Φ (SecType Int (ℓ, ∘)) (ValNum n) (ValNum n)
| ValUntaintedLoc:
forall τ ℓ ℓ_p loc loc' Φ,
left Φ loc = Some loc' ->
val_taint_eq Φ (SecType (Array τ ℓ_p) (ℓ, ∘)) (ValLoc loc) (ValLoc loc')
| ValTaintedNum:
forall ℓ n1 n2 Φ,
val_taint_eq Φ (SecType Int (ℓ, •)) (ValNum n1) (ValNum n2)
| ValTaintedLoc:
forall τ ℓ ℓ_p loc1 loc2 Φ,
val_taint_eq Φ (SecType (Array τ ℓ_p) (ℓ, •)) (ValLoc loc1) (ValLoc loc2).
Hint Constructors val_taint_eq.
Definition taint_eq_mem Φ Γ m1 m2 :=
(forall x, (exists v, memory_lookup m1 x = Some v) <-> (exists v, memory_lookup m2 x = Some v))
/\
(forall x τ v1 v2,
Γ x = Some τ ->
memory_lookup m1 x = Some v1 ->
memory_lookup m2 x = Some v2 ->
val_taint_eq Φ τ v1 v2).
Hint Unfold taint_eq_mem.
Definition taint_eq_heap ℓ_adv Φ Σ1 Σ2 m1 h1 m2 h2 :=
forall loc loc' ℓ1 ℓ2 μ1 μ2 τ,
left Φ loc = Some loc' ->
high ℓ_adv m1 h1 loc ->
high ℓ_adv m2 h2 loc' ->
heap_lookup loc h1 = Some (ℓ1, μ1) ->
heap_lookup loc' h2 = Some (ℓ2, μ2) ->
Σ1 loc = Some τ ->
Σ2 loc' = Some τ ->
ℓ1 = ℓ2 /\
length_of loc h1 = length_of loc' h2 /\
(forall n, (exists v, lookup μ1 n = Some v) <-> (exists v, lookup μ2 n = Some v)) /\
(forall n v1 v2,
reach m1 h1 loc ->
reach m2 h2 loc' ->
lookup μ1 n = Some v1 ->
lookup μ2 n = Some v2 ->
val_taint_eq Φ τ v1 v2).
Hint Unfold taint_eq_heap.
Definition taint_eq_heap_domain_eq (ℓ_adv : level_proj1) (Φ: bijection loc loc)
(m1 m2 : Memory) (h1 h2 : Heap) :=
forall l1 l2 ℓ,
left Φ l1 = Some l2 ->
((exists μ, heap_lookup l1 h1 = Some (ℓ, μ)) /\ high ℓ_adv m1 h1 l1)
<->
((exists ν, heap_lookup l2 h2 = Some (ℓ, ν)) /\ high ℓ_adv m2 h2 l2).
Hint Unfold taint_eq_heap_domain_eq.
Definition taint_eq_reach Φ m1 h1 m2 h2 :=
forall loc loc',
left Φ loc = Some loc' ->
reach m1 h1 loc <-> reach m2 h2 loc'.
Hint Unfold taint_eq_reach.
Definition taint_eq_stenv (Φ : bijection loc loc) (Σ1 Σ2 : stenv) :=
forall loc1 loc2 τ,
left Φ loc1 = Some loc2 ->
(Σ1 loc1 = Some τ <-> Σ2 loc2 = Some τ).
Hint Unfold taint_eq_stenv.
Definition taint_eq_heap_size ℓ_adv h1 h2 :=
forall l, ~ l ⊑ ℓ_adv -> size l h1 = size l h2.
Hint Unfold taint_eq_heap_size.
Lemma val_taint_eq_plus:
forall ℓ1 ℓ2 Φ ι1 ι2 n1 n1' n2 n2',
val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n1) (ValNum n1') ->
val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n2) (ValNum n2') ->
val_taint_eq Φ (SecType Int (ℓ1 ⊔ ℓ2, LH.join ι1 ι2)) (ValNum (n1 + n2))
(ValNum (n1' + n2')).
Proof.
intros.
destruct (LH.join ι1 ι2) eqn:H_ι.
- assert (ι1 = ∘).
{
destruct ι1.
- reflexivity.
- discriminate.
}
subst.
assert (ι2 = ∘).
{
destruct ι2.
- reflexivity.
- discriminate.
}
subst.
inverts H; inverts H0.
eauto.
- eauto.
Qed.
Hint Resolve val_taint_eq_plus.
Lemma val_taint_eq_times:
forall ℓ1 ℓ2 Φ ι1 ι2 n1 n1' n2 n2',
val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n1) (ValNum n1') ->
val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n2) (ValNum n2') ->
val_taint_eq Φ (SecType Int (ℓ1 ⊔ ℓ2, LH.join ι1 ι2)) (ValNum (n1 * n2))
(ValNum (n1' * n2')).
Proof.
intros.
destruct (LH.join ι1 ι2) eqn:H_ι.
- assert (ι1 = ∘).
{
destruct ι1.
- reflexivity.
- discriminate.
}
subst.
assert (ι2 = ∘).
{
destruct ι2.
- reflexivity.
- discriminate.
}
subst.
inverts H; inverts H0.
eauto.
- eauto.
Qed.
Hint Resolve val_taint_eq_times.
Lemma val_taint_eq_num_refl:
forall Φ n ε,
val_taint_eq Φ (SecType Int ε) (ValNum n) (ValNum n).
Proof.
intros.
destruct ε as [ℓ ι].
destruct ι; eauto.
Qed.
Hint Resolve val_taint_eq_num_refl.
Lemma val_taint_eq_loc_refl:
forall loc' ℓ τ ε,
val_taint_eq (identity_bijection loc)
(SecType (Array τ ℓ) ε) (ValLoc loc') (ValLoc loc').
Proof.
intros.
destruct ε as [ℓ' ι'].
destruct ι'; eauto.
Qed.
Hint Resolve val_taint_eq_loc_refl.
Lemma val_taint_eq_refl:
forall τ v ε,
(τ = Int -> exists n, v = ValNum n) ->
(forall τ' ℓ, τ = Array τ' ℓ -> exists loc, v = ValLoc loc) ->
val_taint_eq (identity_bijection loc) (SecType τ ε) v v.
Proof.
intros.
destruct τ.
- specialize_gen.
super_destruct; subst.
eauto.
- repeat specialize_gen.
super_destruct; subst.
eauto.
Qed.
Hint Resolve val_taint_eq_refl.
Lemma val_taint_eq_trans:
forall Φ Ψ τ v1 v2 v3,
val_taint_eq Φ τ v1 v2 ->
val_taint_eq Ψ τ v2 v3 ->
val_taint_eq (bijection.bijection_compose Φ Ψ) τ v1 v3.
Proof.
intros.
destruct τ as [σ [ℓ ι]].
destruct ι.
- inverts H; inverts H0; eauto.
- inverts H; inverts H0; eauto.
Qed.
Ltac invert_val_taint_eq :=
match goal with
[H: val_taint_eq _ _ _ _ |- _] =>
inverts H
end.
Lemma eval_taint_eq_possibilistic:
forall Γ Φ e σ ℓ m1 m2 ι v1,
expr_has_type Γ e (SecType σ (ℓ, ι)) ->
wf_tenv Γ m1 ->
wf_tenv Γ m2 ->
taint_eq_mem Φ Γ m1 m2 ->
eval m1 e = Some v1 ->
exists v2,
eval m2 e = Some v2 /\
val_taint_eq Φ (SecType σ (ℓ, ι)) v1 v2.
Proof.
intros.
revert v1 H3.
dependent induction H; intros.
- unfold eval in *.
rewrite_inj.
exists (ValNum n).
splits*.
- unfold eval in *.
assert (exists v2, memory_lookup m2 x = Some v2).
{
eapply H2; eauto.
}
super_destruct; subst.
exists v2.
splits*.
assert (val_taint_eq Φ (SecType σ (ℓ, ι)) v1 v2).
{
eapply H2; eauto.
}
invert_val_taint_eq; eauto.
- destruct l1 as [ℓ1 ι1].
destruct l2 as [ℓ2 ι2].
rewrite -> about_eval in * |-.
repeat break_match; try congruence.
+ repeat injects; subst.
assert (exists v2,
eval m2 e1 = Some v2 /\ val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n) v2) by eauto 2.
assert (exists v2,
eval m2 e2 = Some v2 /\ val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n0) v2) by eauto 2.
super_destruct; subst.
do 2 invert_val_taint_eq.
* exists (ValNum (n + n0)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n2 + n0)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n + n2)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n3 + n2)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
+ repeat injects; subst.
assert (exists v2,
eval m2 e1 = Some v2 /\ val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n) v2) by eauto 2.
assert (exists v2,
eval m2 e2 = Some v2 /\ val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n0) v2) by eauto 2.
super_destruct; subst.
do 2 invert_val_taint_eq.
* exists (ValNum (n * n0)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n2 * n0)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n * n2)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
* exists (ValNum (n3 * n2)).
splits*.
rewrite -> about_eval.
do 2 decide_exist.
reflexivity.
Qed.
Hint Resolve eval_taint_eq_possibilistic.
Lemma eval_taint_eq:
forall Γ Φ e σ ℓ m1 m2 ι v1 v2,
expr_has_type Γ e (SecType σ (ℓ, ι)) ->
wf_tenv Γ m1 ->
wf_tenv Γ m2 ->
taint_eq_mem Φ Γ m1 m2 ->
eval m1 e = Some v1 ->
eval m2 e = Some v2 ->
val_taint_eq Φ (SecType σ (ℓ, ι)) v1 v2.
Proof.
intros.
revert v1 v2 H3 H4.
dependent induction H; intros.
- eauto.
unfold eval in *.
rewrite_inj.
destruct ι; eauto.
- eapply H2; eauto.
- destruct l1 as [ℓ1 ι1].
destruct l2 as [ℓ2 ι2].
rewrite -> about_eval in *.
repeat break_match; try congruence.
+ repeat injects; subst.
assert (val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n1) (ValNum n)) by eauto 2.
assert (val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n2) (ValNum n0)) by eauto 2.
eauto.
+ repeat injects.
assert (val_taint_eq Φ (SecType Int (ℓ1, ι1)) (ValNum n1) (ValNum n)) by eauto 2.
assert (val_taint_eq Φ (SecType Int (ℓ2, ι2)) (ValNum n2) (ValNum n0)) by eauto 2.
eauto.
Qed.
Hint Resolve eval_taint_eq.
Lemma val_taint_eq_mon:
forall ℓ1 ℓ2 ι1 ι2 v1 v2 Φ σ,
val_taint_eq Φ (SecType σ (ℓ1, ι1)) v1 v2 ->
LH.flowsto ι1 ι2 ->
val_taint_eq Φ (SecType σ (ℓ2, ι2)) v1 v2.
Proof.
intros.
inverts H.
- destruct ι2; eauto.
- destruct ι2; eauto.
- destruct ι2; eauto || discriminate.
- destruct ι2; eauto || discriminate.
Qed.
Hint Resolve val_taint_eq_mon.
Lemma gc_preserves_taint_eq_heap:
forall ℓ_adv c c' pc pc' m m' h h' t t' Σ Σ',
gc_occurred c c' pc pc' m m' h h' t t' Σ Σ' ->
wf_stenv Σ h ->
taint_eq_heap ℓ_adv (identity_bijection loc) Σ Σ' m h m' h'.
Proof.
intros.
unfolds.
intros.
unfold left, identity_bijection in *; subst.
injects.
unfold gc_occurred in *.
super_destruct; subst.
rewrite_inj.
destruct (heap_lookup loc' ([[h1_1_pc ⊎ h1_1_not_pc, H14] ⊎ h1_2, H13]))
eqn:H_loc.
- destruct p as [l μ].
rewrite_inj.
destruct_disjoint_heap_lookup.
+ rewrite_inj.
splits*.
* assert (exists length, length_of loc' ([h1_1_pc ⊎ h1_1_not_pc, H14]) = Some length).
{
eapply length_of_lookup_correspondance; eauto 3.
}
super_destruct'; subst.
rewrite -> H.
eapply disjoint_union_length_of.
eauto.
* intros.
rewrite_inj.
destruct τ as [σ ε].
eapply val_taint_eq_refl.
{ intros; subst; eauto. }
{ intros; subst; eauto. }
+ assert (heap_lookup loc' ([h1_1_pc ⊎ h1_1_not_pc, H14]) = None) by eauto.
congruence.
- discriminate.
Unshelve.
eauto.
Qed.
Hint Resolve gc_preserves_taint_eq_heap.
Ltac destruct_high :=
match goal with
[H: high _ _ _ _ |- _] =>
inverts H
end.
Lemma high_iff:
forall ℓ_adv loc1 loc2 m1 h1 m2 h2 Φ,
taint_eq_heap_domain_eq ℓ_adv Φ m1 m2 h1 h2 ->
taint_eq_reach Φ m1 h1 m2 h2 ->
left Φ loc1 = Some loc2 ->
high ℓ_adv m1 h1 loc1 <->
high ℓ_adv m2 h2 loc2.
Proof.
intros.
splits; intros.
- destruct_high.
+ eapply HighReachable.
firstorder 2.
+ assert ((exists μ, heap_lookup loc2 h2 = Some (ℓ, μ)) /\ high ℓ_adv m2 h2 loc2).
{
eapply H; eauto.
}
super_destruct'; subst.
eauto.
- destruct_high.
+ eapply HighReachable.
firstorder 2.
+ assert ((exists μ, heap_lookup loc1 h1 = Some (ℓ, μ)) /\ high ℓ_adv m1 h1 loc1).
{
eapply H; eauto.
}
super_destruct'; subst.
eauto.
Qed.
Lemma taint_eq_heap_trans:
forall ℓ_adv Σ Σ' Σ'' Φ Ψ m h m' h' m'' h'',
taint_eq_reach Ψ m' h' m'' h'' ->
taint_eq_stenv Φ Σ Σ' ->
dangling_pointer_free m' h' ->
taint_eq_heap ℓ_adv Φ Σ Σ' m h m' h' ->
taint_eq_heap ℓ_adv Ψ Σ' Σ'' m' h' m'' h'' ->
taint_eq_heap_domain_eq ℓ_adv Ψ m' m'' h' h'' ->
taint_eq_heap ℓ_adv (bijection.bijection_compose Φ Ψ) Σ Σ'' m h m'' h''.
Proof.
intros.
unfold taint_eq_heap in *.
intros.
_apply left_compose in *.
super_destruct.
destruct my; try (repeat specialize_gen; congruence).
assert (left Ψ l = Some loc') by eauto 2.
assert (high ℓ_adv m' h' l).
{
eapply high_iff; eauto 2.
}
assert (exists ℓ μ, heap_lookup l h' = Some (ℓ, μ)).
{
destruct_high; eauto.
}
super_destruct; subst.
assert (Σ' l = Some τ) by firstorder 2.
remember_simple (H2 _ _ _ _ _ _ _ H5 H6 H15 H8 H16 H10 H17).
super_destruct; subst.
rewrite_inj.
remember_simple (H3 _ _ _ _ _ _ _ H14 H15 H7 H16 H9 H17 H11).
super_destruct; subst.
splits*.
- intros.
rewrite -> H19.
eauto.
- intros.
rewrite -> H20.
eauto.
- intros.
assert (exists u, lookup μ n = Some u) by firstorder 2.
super_destruct; subst.
assert (reach m' h' l) by (eapply H; eauto 2).
eapply val_taint_eq_trans; eauto.
Qed.
Inductive taint_eq_cmd: cmd -> cmd -> Prop :=
TaintEqSkip: taint_eq_cmd Skip Skip
| TaintEqStop: taint_eq_cmd Stop Stop
| TaintEqAssign: forall x e,
taint_eq_cmd (Assign x e) (Assign x e)
| TaintEqIf: forall c1 c2 c1' c2' e,
taint_eq_cmd c1 c1' ->
taint_eq_cmd c2 c2' ->
taint_eq_cmd (If e c1 c2) (If e c1' c2')
| TaintEqWhile: forall e c c',
taint_eq_cmd c c' ->
taint_eq_cmd (While e c) (While e c')
| TaintEqSeq: forall c1 c2 c1' c2',
taint_eq_cmd c1 c1' ->
taint_eq_cmd c2 c2' ->
taint_eq_cmd (c1 ;; c2) (c1' ;; c2')
| TaintEqAt: forall e l c c',
taint_eq_cmd c c' ->
taint_eq_cmd (At l e c) (At l e c')
| TaintEqBackAt: forall n1 n2 l,
taint_eq_cmd (BackAt l n1) (BackAt l n2)
| TaintEqNewArr: forall x l e1 e2,
taint_eq_cmd (NewArr x l e1 e2) (NewArr x l e1 e2)
| TaintEqSetArr: forall x e1 e2,
taint_eq_cmd (SetArr x e1 e2) (SetArr x e1 e2)
| TaintEqGetArr: forall x y e,
taint_eq_cmd (GetArr x y e) (GetArr x y e)
| TaintEqTime: forall x,
taint_eq_cmd (Time x) (Time x)
| TaintEqTimeOut:
taint_eq_cmd TimeOut TimeOut.
Hint Constructors taint_eq_cmd.
Definition taint_eq ℓ_adv Φ Γ Σ1 Σ2 c1 c2 m1 h1 m2 h2 :=
taint_eq_cmd c1 c2 /\ taint_eq_mem Φ Γ m1 m2 /\ taint_eq_reach Φ m1 h1 m2 h2 /\
taint_eq_heap ℓ_adv Φ Σ1 Σ2 m1 h1 m2 h2 /\ taint_eq_heap_size ℓ_adv h1 h2 /\
taint_eq_heap_domain_eq ℓ_adv Φ m1 m2 h1 h2 /\ taint_eq_stenv Φ Σ1 Σ2.
Inductive taint_eq_events: tenv -> bijection loc loc -> event -> event -> Prop :=
| TaintEqEventEmpty:
forall Γ Φ, taint_eq_events Γ Φ EmptyEvent EmptyEvent
| TaintEqEventAssign:
forall Γ ℓ τ ι x Φ v1 v2,
Γ x = Some (SecType τ ι) ->
val_taint_eq Φ (SecType τ ι) v1 v2 ->
taint_eq_events Γ Φ (AssignEvent ℓ x v1) (AssignEvent ℓ x v2)
| TaintEqEventNew:
forall Γ x ℓ loc loc' Φ,
left Φ loc = Some loc' ->
taint_eq_events Γ Φ (NewEvent ℓ x loc) (NewEvent ℓ x loc')
| TaintEqEventGet:
forall Γ ℓ_x x τ ι y Φ v1 v2,
Γ x = Some (SecType τ ι) ->
val_taint_eq Φ (SecType τ ι) v1 v2 ->
taint_eq_events Γ Φ (GetEvent ℓ_x x y v1) (GetEvent ℓ_x x y v2)
| TaintEqEventSet:
forall Γ ℓ ℓ_p ℓ_x τ ι x n Φ v1 v2,
Γ x = Some (SecType (Array (SecType τ (ℓ, ι)) ℓ_p) (ℓ_x, ∘)) ->
val_taint_eq Φ (SecType τ (ℓ, ι)) v1 v2 ->
taint_eq_events Γ Φ (SetEvent ℓ ℓ_x x n v1) (SetEvent ℓ ℓ_x x n v2)
| TaintEqEventTime:
forall Γ ℓ x n1 n2 Φ,
Γ x = Some (SecType Int (ℓ, •)) ->
taint_eq_events Γ Φ (TimeEvent ℓ x n1) (TimeEvent ℓ x n2)
| TaintEqEventRestore:
forall ℓ n1 n2 Φ Γ,
taint_eq_events Γ Φ (RestoreEvent ℓ n1) (RestoreEvent ℓ n2).
Hint Constructors taint_eq_events.
Definition ni_bridge (n1: nat) (ℓ: level_proj1): Prop :=
forall Γ Σ1 Σ2 Σ3 Σ1' Σ3' φ Φ pc pc1' pc2'' c c' c2 c2' m1 m2 s1 s2'' h1 h2
w1 w2'' t t2 g2'' s1' w1' ev1 ev2 pc_end n2 t',
wf_bijection ℓ φ Γ Σ1 m1 h1 ->
wf_bijection ℓ (inverse φ) Γ Σ2 s1 w1 ->
wf_taint_bijection ℓ Φ s1 w1 ->
wf_taint_bijection ℓ (inverse Φ) s1' w1' ->
wellformed_aux Γ Σ1 ⟨c, pc, m1, h1, t⟩ pc_end ->
wellformed_aux Γ Σ2 ⟨c, pc, s1, w1, t⟩ pc_end ->
wellformed_aux Γ Σ3 ⟨c', pc, s1', w1', t'⟩ pc_end ->
state_low_eq ℓ φ m1 h1 s1 w1 Γ Σ1 Σ2 ->
pc ⊑ ℓ ->
taint_eq ℓ Φ Γ Σ2 Σ3 c c' s1 w1 s1' w1' ->
⟨c, pc, m1, h1, t⟩ ↷ [ℓ, Γ, Σ1, Σ1', ev1, n1] ⟨c2, pc1', m2, h2, t2⟩ ->
⟨c', pc, s1', w1', t'⟩ ↷ [ℓ, Γ, Σ3, Σ3', ev2, n2] ⟨c2', pc2'', s2'', w2'', g2''⟩ ->
c2 <> TimeOut ->
c2' <> TimeOut ->
exists ev1' n1' ψ Ψ s2' w2' Σ2',
⟨c, pc, s1, w1, t⟩ ↷ [ℓ, Γ, Σ2, Σ2', ev1', n1'] ⟨c2, pc1', s2', w2', t2⟩ /\
pc1' ⊑ ℓ /\
pc2'' = pc1' /\
state_low_eq ℓ ψ m2 h2 s2' w2' Γ Σ1' Σ2'/\
event_low_eq ℓ (left ψ) ev1 ev1' /\
taint_eq_events Γ Ψ ev1' ev2 /\
wf_bijection ℓ ψ Γ Σ1' m2 h2 /\
wf_bijection ℓ (inverse ψ) Γ Σ2' s2' w2' /\
wf_taint_bijection ℓ Ψ s2' w2' /\
wf_taint_bijection ℓ (inverse Ψ) s2'' w2'' /\
taint_eq ℓ Ψ Γ Σ2' Σ3' c2 c2' s2' w2' s2'' w2''.
Hint Unfold ni_bridge.
Lemma low_event_step_seq:
forall ℓ c1 c2 c' pc m h t pc' m' h' t' Γ Σ Σ' ev,
low_event_step ℓ ⟨c1;; c2, pc, m, h, t⟩ ⟨c', pc', m', h', t'⟩ Γ Σ Σ' ev ->
(exists c1', c1' <> Stop /\
low_event_step ℓ ⟨c1, pc, m, h, t⟩ ⟨c1', pc', m', h', t'⟩ Γ Σ Σ' ev /\
c' = (c1';; c2))
\/ low_event_step ℓ ⟨c1, pc, m, h, t⟩ ⟨Stop, pc', m', h', t'⟩ Γ Σ Σ' ev /\ c' = c2.
Proof.
intros.
invert_low_event_step.
invert_event_step.
- left.
exists c1'.
splits*.
- eauto.
- invert_low_event.
Qed.
Hint Resolve low_event_step_seq.
Lemma high_event_step_seq:
forall ℓ c1 c2 c' pc m h t pc' m' h' t' Γ Σ Σ' ev,
high_event_step ℓ ⟨c1;; c2, pc, m, h, t⟩ ⟨c', pc', m', h', t'⟩ Γ Σ Σ' ev ->
(exists c1', c1' <> Stop /\ high_event_step ℓ ⟨c1, pc, m, h, t⟩ ⟨c1', pc', m', h', t'⟩ Γ Σ Σ' ev /\ c' = (c1';; c2))
\/ high_event_step ℓ ⟨c1, pc, m, h, t⟩ ⟨Stop, pc', m', h', t'⟩ Γ Σ Σ' ev /\ c' = c2 \/
(gc_occurred (c1;; c2) c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent).
Proof.
intros.
invert_high_event_step.
invert_event_step.
- left.
exists c1'.
eauto.
- right; left.
eauto.
- right; right.
splits*.
unfolds.
splits*.
do 7 eexists.
splits; reflexivity || eauto.
Qed.
Hint Resolve high_event_step_seq.
Ltac high_low_steps_with_expr_is_false t :=
invert_low_event_step; invert_high_event_step;
do 2 invert_event_step;
[ do 2 invert_wf_aux;
repeat specialize_gen;
do 2 invert_wt_cmd;
rewrite_inj;
invert_lifted;
match goal with
[H: high_event _ _ |- _] =>
contradiction H
end;
eapply t; eauto;
invert_low_event;
eauto
| invert_low_event
| invert_low_event; eauto
| invert_low_event ].
Ltac high_low_steps_empty_event_is_false :=
invert_low_event_step;
invert_high_event_step;
do 2 invert_event_step;
contradiction.
Ltac low_and_high_event_is_false t :=
repeat match goal with
| [H1: context[low_event_step], H2: context[high_event_step] |- _] =>
invert_low_event_step;
invert_high_event_step;
do 2 invert_event_step;
unfold high_event in *;
do 2 invert_wf_aux;
do 2 invert_wt_cmd
| [H1: low_event _ _, H2: ~ low_event _ _ |- _] =>
contradiction H2;
inverts H1;
apply t; eauto
end.
Lemma stop_does_no_event_step:
forall c' pc pc' m m' h h' t t' ev Γ Σ Σ',
(⟨ STOP, pc, m, h, t ⟩) ⇒ [ev, Γ, Σ, Σ'] ⟨c', pc', m', h', t'⟩ ->
gc_occurred Stop c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_event_step.
splits*.
Qed.
Hint Resolve stop_does_no_event_step.
Lemma timeout_does_no_event_step:
forall c' pc pc' m m' h h' t t' ev Γ Σ Σ',
(⟨TIMEOUT, pc, m, h, t ⟩) ⇒ [ev, Γ, Σ, Σ'] ⟨c', pc', m', h', t'⟩ ->
gc_occurred TimeOut c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_event_step.
splits*.
Qed.
Hint Resolve timeout_does_no_event_step.
Lemma stop_does_no_low_event_step:
forall ℓ pc m h t cfg ev Γ Σ Σ',
low_event_step ℓ ⟨Stop, pc, m, h, t⟩ cfg Γ Σ Σ' ev -> False.
Proof.
intros.
invert_low_event_step.
destruct cfg.
_apply stop_does_no_event_step in *.
super_destruct.
subst.
invert_low_event.
Qed.
Hint Resolve stop_does_no_low_event_step.
Lemma timeout_does_no_low_event_step:
forall ℓ pc m h t cfg ev Γ Σ Σ',
low_event_step ℓ ⟨TIMEOUT, pc, m, h, t⟩ cfg Γ Σ Σ' ev -> False.
Proof.
intros.
invert_low_event_step.
destruct cfg.
_apply timeout_does_no_event_step in *.
super_destruct.
subst.
invert_low_event.
Qed.
Hint Resolve timeout_does_no_low_event_step.
Lemma stop_does_no_high_event_step:
forall ℓ c' pc pc' m m' h h' t t' ev Γ Σ Σ',
high_event_step ℓ ⟨Stop, pc, m, h, t⟩ ⟨c', pc', m', h', t'⟩ Γ Σ Σ' ev ->
gc_occurred Stop c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_high_event_step.
_apply stop_does_no_event_step in *.
eauto.
Qed.
Hint Resolve stop_does_no_high_event_step.
Lemma timeout_does_no_high_event_step:
forall ℓ c' pc pc' m m' h h' t t' ev Γ Σ Σ',
high_event_step ℓ ⟨TimeOut, pc, m, h, t⟩ ⟨c', pc', m', h', t'⟩ Γ Σ Σ' ev ->
gc_occurred TimeOut c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_high_event_step.
_apply timeout_does_no_event_step in *.
eauto.
Qed.
Hint Resolve timeout_does_no_high_event_step.
Lemma stop_does_no_bridge_step:
forall pc m h t ℓ ev n c' pc' m' h' t' Γ Σ Σ',
⟨Stop, pc, m, h, t ⟩ ↷ [ℓ, Γ, Σ, Σ', ev, n] ⟨c', pc', m', h', t' ⟩ ->
gc_occurred Stop c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_bridge_step; eauto.
- _apply stop_does_no_low_event_step in *.
contradiction.
- destruct cfg2.
_apply stop_does_no_high_event_step in *.
super_destruct.
unfold gc_occurred in * |-.
super_destruct.
subst.
exfalso; eauto.
Qed.
Hint Resolve stop_does_no_bridge_step.
Lemma timeout_does_no_bridge_step:
forall pc m h t ℓ ev n c' pc' m' h' t' Γ Σ Σ',
⟨TimeOut, pc, m, h, t ⟩ ↷ [ℓ, Γ, Σ, Σ', ev, n] ⟨c', pc', m', h', t' ⟩ ->
gc_occurred TimeOut c' pc pc' m m' h h' t t' Σ Σ' /\ ev = EmptyEvent.
Proof.
intros.
invert_bridge_step; eauto.
- _apply timeout_does_no_low_event_step in *.
contradiction.
- destruct cfg2.
_apply timeout_does_no_high_event_step in *.
super_destruct.
unfold gc_occurred in * |-.
super_destruct.
subst.
exfalso; eauto.
Qed.
Hint Resolve timeout_does_no_bridge_step.
Lemma new_low_reach_implies_flowsto_low:
forall Γ x t ℓ ℓ_x ℓ_adv l n v m h loc Σ ℓ_p H1 H2,
Γ x = Some (SecType (Array (SecType t ℓ) ℓ_p) (ℓ_x, ∘)) ->
dangling_pointer_free m h ->
(forall s ℓ, t = Array s ℓ -> exists loc', v = ValLoc loc' /\ reach m h loc') ->
(t = Int -> exists n, v = ValNum n) ->
low_reach ℓ_adv Γ Σ
(m [x → ValLoc loc]) (h [loc → (n × v, l), H1, H2]) loc ->
ℓ_x ⊑ ℓ_adv.
Proof.
intros.
dependent induction H5.
- destruct (decide (x = x0)); subst.
+ rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
eauto.
+ rewrite -> extend_memory_lookup_neq in * by solve[eauto].
assert (exists ℓ μ, heap_lookup loc h = Some (ℓ, μ)) by eauto.
super_destruct; subst.
congruence.
- destruct (decide (loc2 = loc1)); subst.
+ rewrite_inj.
eapply IHlow_reach; eauto.
+ rewrite -> heap_lookup_extend_neq in * by solve[eauto].
assert (reach (m [x → ValLoc loc2])
(h [loc2 → (n × v, l), H1, H2 ]) loc1) by eauto 2.
assert (~ reach m h loc2).
{
intro.
assert (exists ℓ μ, heap_lookup loc2 h = Some (ℓ, μ)) by eauto.
super_destruct; subst.
congruence.
}
assert (reach m h loc1).
{
eapply reach_extend_implies_reach_if.
- instantiate (1 := v).
intros; subst.
destruct t.
+ repeat specialize_gen.
super_destruct; discriminate.
+ specialize (H3 s l1 eq_refl).
super_destruct; subst.
injects.
eauto.
- eauto.
- eauto.
}
exfalso; eauto.
Unshelve.
* eauto.
Qed.
Lemma memory_lookup_is_eval_of_var:
forall m x v,
memory_lookup m x = Some v ->
eval m (Var x) = Some v.
Proof.
intros.
unfolds.
eauto.
Qed.
Hint Resolve memory_lookup_is_eval_of_var.
Ltac apply_taint_eq_reach :=
match goal with
[H: context[taint_eq_reach] |- _] =>
solve[eapply H; eauto]
end.
Lemma taint_bijection_implies_lookup:
forall ℓ τ m1 m2 h1 h2 n Σ1 Σ2 loc1 loc2 loc1' loc2' Φ l1 l2 μ ν,
wf_stenv Σ1 h1 ->
wf_stenv Σ2 h2 ->
taint_eq_heap ℓ Φ Σ1 Σ2 m1 h1 m2 h2 ->
Σ1 loc1 = Some τ ->
Σ2 loc2 = Some τ ->
reach m1 h1 loc1 ->
reach m2 h2 loc2 ->
heap_lookup loc1 h1 = Some (l1, μ) ->
heap_lookup loc2 h2 = Some (l2, ν) ->
left Φ loc1 = Some loc2 ->
lookup μ n = Some (ValLoc loc1') ->
left Φ loc1' = Some loc2' ->
lookup ν n = Some (ValLoc loc2').
Proof.
intros.
assert (high ℓ m1 h1 loc1) by eauto 2.
assert (high ℓ m2 h2 loc2) by eauto 2.
remember_simple (H1 loc1 loc2 _ _ _ _ _ H8 H11 H12 H6 H7 H2 H3).
super_destruct'; subst.
assert (exists u, lookup ν n = Some u).
{
assert (exists v, lookup μ n = Some v) by eauto.
eapply_lookup_func_domain_eq; eauto.
}
super_destruct; subst.
assert (val_taint_eq Φ τ (ValLoc loc1') u) by eauto 2.
invert_val_taint_eq.
- rewrite_inj.
eauto.
- assert_wf_type.
invert_wf_type.
Qed.
Lemma reach_in_extended_memory_and_heap:
forall ℓ Γ Σ1 Σ2 m1 h1 m2 h2 x n1 n2 v1 v2 l1 l2 loc1 loc2 Φ ℓ_τ ℓ_p τ ℓ_x ι_τ H1 H2 H3 H4,
Γ x = Some (SecType (Array (SecType τ (ℓ_τ, ι_τ)) ℓ_p) (ℓ_x, ∘)) ->
wf_taint_bijection ℓ Φ m1 h1 ->
taint_eq_mem Φ Γ m1 m2 ->
taint_eq_reach Φ m1 h1 m2 h2 ->
taint_eq_heap ℓ Φ Σ1 Σ2 m1 h1 m2 h2 ->
taint_eq_stenv Φ Σ1 Σ2 ->
reach (m1 [x → ValLoc l1]) (h1 [l1 → (n1 × v1, ℓ_p), H1, H2]) loc1 ->
dangling_pointer_free m1 h1 ->
dangling_pointer_free m2 h2 ->
wf_tenv Γ m1 ->
wf_tenv Γ m2 ->
wf_stenv Σ1 h1 ->
wf_stenv Σ2 h2 ->
left Φ loc1 = Some loc2 ->
(forall s ℓ', τ = Array s ℓ' -> exists loc', v1 = ValLoc loc' /\
reach m1 h1 loc') ->
(τ = Int -> exists n, v1 = ValNum n) ->
val_taint_eq Φ (SecType τ (ℓ_τ, ι_τ)) v1 v2 ->
reach (m2 [x → ValLoc l2])
(h2 [l2 → (n2 × v2, ℓ_p), H3, H4]) loc2.
Proof.
intros.
revert loc2 H16.
dependent induction H9; intros.
- destruct (decide (x = x0)); subst.
+ rewrite extend_memory_lookup_eq in *.
rewrite_inj.
assert (high ℓ m1 h1 loc).
{
eapply H0; eauto 2.
}
assert (exists ℓ μ, heap_lookup loc h1 = Some (ℓ, μ)) by (destruct_high; eauto).
super_destruct; congruence.
+ rewrite -> extend_memory_lookup_neq in * by solve[eauto].
assert (exists v, memory_lookup m2 x0 = Some v) by firstorder 2.
super_destruct; subst.
assert (exists τ, Γ x0 = Some τ) by eauto 3.
super_destruct'; subst.
destruct τ0 as [σ [ℓ' ι']].
assert (exists ℓ τ, σ = Array τ ℓ).
{
destruct σ; eauto.
assert (exists n, ValLoc loc = ValNum n) by eauto 3.
super_destruct; congruence.
}
super_destruct'; subst.
assert (val_taint_eq Φ (SecType (Array τ0 ℓ0) (ℓ', ι')) (ValLoc loc) v).
{
eapply eval_taint_eq with (e := Var x0) (m1 := m1) (m2 := m2); eauto.
}
invert_val_taint_eq.
* rewrite_inj.
eapply reach_mem.
{ rewrite -> extend_memory_lookup_neq by solve[eauto].