-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoFlow.thy
1759 lines (1471 loc) · 79.4 KB
/
InfoFlow.thy
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
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: GPL-2.0-only
*)
text \<open>
This file provide the main confidentiality unwinding condition:
the reads_respects family.
In order to do that it provides subjectReads, the set of labels a label can observe from
and subjectAffects, the set of labels a label can affect.
Then we can build read_equiv and affects_equiv which are parts of the unwinding relation.
reads_respects then states that reads_equiv and affects_equiv are preserved
through a specific function
\<close>
theory InfoFlow
imports
"Access.Syscall_AC"
"Lib.EquivValid"
begin
context begin interpretation Arch . (*FIXME: arch_split*)
section \<open>Scheduler domain constraint\<close>
text \<open>
For the information flow theorem, we assume that every domain
contains threads of exactly one label, so that labels cannot leak
information through the scheduler.
Morally, domains that have no labels ought to be allowed as well,
but this definition is easier to reason about. In practice, we can
just put all empty domains into some dummy label to satisfy the
exactly-one requirement. See e.g. the mapping in Example_Valid_State.
\<close>
definition pas_domains_distinct :: "('a, 'b) PAS_scheme \<Rightarrow> bool"
where
"pas_domains_distinct aag \<equiv> \<forall>d. \<exists>l. pasDomainAbs aag d = {l}"
lemma pas_domains_distinct_inj:
"\<lbrakk> pas_domains_distinct aag;
l1 \<in> pasDomainAbs aag d;
l2 \<in> pasDomainAbs aag d \<rbrakk> \<Longrightarrow>
l1 = l2"
apply (clarsimp simp: pas_domains_distinct_def)
apply (drule_tac x=d in spec)
apply auto
done
lemma domain_has_unique_label:
"pas_domains_distinct aag \<Longrightarrow> \<exists>l. pasDomainAbs aag d = {l}"
by (simp add: pas_domains_distinct_def)
lemma domain_has_the_label:
"pas_domains_distinct aag \<Longrightarrow> l \<in> pasDomainAbs aag d \<Longrightarrow> the_elem (pasDomainAbs aag d) = l"
apply (simp add: pas_domains_distinct_def)
apply (metis singletonD the_elem_eq)
done
section \<open>Reading: subjectReads and associated equivalence properties\<close>
subsection \<open>subjectReads\<close>
text\<open>We take the authority graph from the access proofs. We identify each
label in that graph with an information flow domain. Our goal is to
construct an equivalence relation (R l) on states, for each label l of
the authority graph, that tells us when those two states are equal for
all state readable by label l -- i.e. all state that falls within l's
information flow domain. The set of all such state, we denote
subjectReads g l, where g is the authority graph.\<close>
(* TODO: consider putting the current subject as a parameter and restricting
the inductive rules to require that 'a' is the current subject *)
inductive_set subjectReads :: "'a auth_graph \<Rightarrow> 'a \<Rightarrow> 'a set"
for g :: "'a auth_graph" and l :: "'a"
where
(* clearly, l can read from anything it has Read authority to *)
reads_read: "(l,Read,l') \<in> g \<Longrightarrow> l' \<in> subjectReads g l" |
(* l can read from itself *)
reads_lrefl[simp,intro!]: "l \<in> subjectReads g l" |
(* if l has SyncSend or Receive authority to an endpoint, l can read it *)
reads_ep:
"\<lbrakk>(l,auth,ep) \<in> g; auth \<in> {SyncSend,Receive}\<rbrakk> \<Longrightarrow>
ep \<in> subjectReads g l" |
reads_read_queued_thread_read_ep:
(* if someone can send on or reset an endpoint, and l can read from a thread t
that can receive or send synchronously on that endpoint, then l needs to
be able to read from the endpoint too. This is because the thread t might
be blocked waiting to send or receive an that endpoint. When the other
party completes the rendezvous,
the affects caused to t depend of course on the state of the endpoint.
Since t is in l's domain, the ep better be too. *)
"\<lbrakk>(a, auth', ep) \<in> g; auth' \<in> {Notify,SyncSend,Reset};
(t, auth, ep) \<in> g; auth \<in> {SyncSend, Receive};
t \<in> subjectReads g l\<rbrakk>
\<Longrightarrow> ep \<in> subjectReads g l" |
(* if someone, t, can write to a page, and the page is in l's domain, that the
writer better be too. This is needed for when the page is t's ipc buffer,
and t is blocked on an IPC and the other party completes the operation.
The affects caused to the page in question naturally depend on t's state,
so if the page is part of l's domain, t better be too. *)
reads_read_page_read_thread:
"\<lbrakk>b \<in> subjectReads g l; (t,Write,b) \<in> g\<rbrakk> \<Longrightarrow>
t \<in> subjectReads g l" |
(* This is the symmetric case for the rule reads_read_page_read_thread.
Here now suppose t is a sender of an IPC and p is its IPC buffer, to which
it necessarily has Read authority. Suppose t is blocked waiting to complete
the send, and the receiver completes the rendezvous.
IF t is in l's domain, then the IPC buffer had better be too, since it
will clearly be read during the operation to send the IPC *)
reads_read_thread_read_pages:
"\<lbrakk>t \<in> subjectReads g l; (t,Read,p) \<in> g\<rbrakk> \<Longrightarrow>
p \<in> subjectReads g l" |
(* This rule allows domain l to read from all senders to synchronous endpoints
for all such endpoints in its domain. This is needed for when someone
does a receive (for which a sender is already blocked) or reset on the ep.
The affects on the ep here will depend on the state of any blocked
senders. So if the ep is in l's domain, the senders better be too. *)
read_sync_ep_read_senders_strong:
"\<lbrakk>ep \<in> subjectReads g l; (b,SyncSend,ep) \<in> g\<rbrakk> \<Longrightarrow>
b \<in> subjectReads g l" |
read_sync_ep_call_senders_strong:
"\<lbrakk>ep \<in> subjectReads g l; (b,Call,ep) \<in> g\<rbrakk> \<Longrightarrow>
b \<in> subjectReads g l" |
(* This rule allows anyone who can read a synchronous endpoint, to also be
able to read from its receivers. The intuition is that the state of the
receivers can affect how the endpoint is affected. *)
(* I'm not convinced that this rule is strictly necessary. I think that
the specific state of the receiver doesn't affect the ep too much and
that we could probably do away with this rule at the cost of some way more
complex confidentiality proofs for send_ipc. We would have to prove that
the affect on the ep is the same regardless of /who/ the reciever is
(and which page their IPC buffer is etc.). This would involve some quite
tedious equiv_valid_2 proofs for send_ipc and the functions it calls,
which don't really seem worth it at the moment. *)
(* If we removed this rule, all it would gain us I think would be the absence
of direct edges from receiver \<rightarrow> sender in the infoflow policy, but we
would still have edges from receiver \<rightarrow> ep \<rightarrow> sender in either case. I
cannot imagine a useful intransitive noninterference policy that permits
the latter case but not the former, so the extra cost of doing away with
this rule does not seem worth it IMO. *)
read_sync_ep_read_receivers_strong:
"\<lbrakk>ep \<in> subjectReads g l; (b,Receive,ep) \<in> g\<rbrakk> \<Longrightarrow>
b \<in> subjectReads g l" |
(* if t can reply to t', then t can send directly information to t' *)
read_reply_thread_read_thread:
"\<lbrakk>t' \<in> subjectReads g l; (t,Reply,t') \<in> g\<rbrakk> \<Longrightarrow>
t \<in> subjectReads g l" |
(* This rule is only there for convinience if Reply authorities corresponds to Call authorities*)
read_reply_thread_read_thread_rev:
"\<lbrakk>t' \<in> subjectReads g l; (t',Reply,t) \<in> g\<rbrakk> \<Longrightarrow>
t \<in> subjectReads g l" |
(* if t can reply to t', then t can send directly information to t' *)
read_delder_thread_read_thread:
"\<lbrakk>t' \<in> subjectReads g l; (t,DeleteDerived,t') \<in> g\<rbrakk> \<Longrightarrow>
t \<in> subjectReads g l" |
(* This rule is only there for convinience if Reply authorities corresponds to Call authorities*)
read_delder_thread_read_thread_rev:
"\<lbrakk>t' \<in> subjectReads g l; (t',DeleteDerived,t) \<in> g\<rbrakk> \<Longrightarrow>
t \<in> subjectReads g l"
lemma read_sync_ep_read_senders:
"\<lbrakk>(a,auth,ep) \<in> g; auth \<in> {Reset,Receive};
ep \<in> subjectReads g l; (b,SyncSend,ep) \<in> g\<rbrakk> \<Longrightarrow>
b \<in> subjectReads g l"
by (rule read_sync_ep_read_senders_strong)
lemma read_sync_ep_read_receivers:
"\<lbrakk>(a,auth,ep) \<in> g; auth \<in> {SyncSend};
ep \<in> subjectReads g l; (b,Receive,ep) \<in> g\<rbrakk> \<Longrightarrow>
b \<in> subjectReads g l"
by (rule read_sync_ep_read_receivers_strong)
abbreviation aag_can_read :: "'a PAS \<Rightarrow> word32 \<Rightarrow> bool"
where
"aag_can_read aag x \<equiv> (pasObjectAbs aag x) \<in> subjectReads (pasPolicy aag) (pasSubject aag)"
abbreviation aag_can_read_irq :: "'a PAS \<Rightarrow> 10 word \<Rightarrow> bool"
where
"aag_can_read_irq aag x \<equiv> (pasIRQAbs aag x) \<in> subjectReads (pasPolicy aag) (pasSubject aag)"
abbreviation aag_can_read_asid :: "'a PAS \<Rightarrow> asid \<Rightarrow> bool"
where
"aag_can_read_asid aag x \<equiv> (pasASIDAbs aag x) \<in> subjectReads (pasPolicy aag) (pasSubject aag)"
(* FIXME: having an op\<noteq> in the definition causes clarsimp to spuriously
apply classical rules. Using @{term disjnt} may avoid this issue *)
abbreviation aag_can_read_domain :: "'a PAS \<Rightarrow> domain \<Rightarrow> bool"
where
"aag_can_read_domain aag x \<equiv>
pasDomainAbs aag x \<inter> subjectReads (pasPolicy aag) (pasSubject aag) \<noteq> {}"
lemma aag_can_read_self:
"is_subject aag x \<Longrightarrow> aag_can_read aag x"
by simp
lemma aag_can_read_read:
"aag_has_auth_to aag Read x \<Longrightarrow> aag_can_read aag x"
by (rule reads_read)
lemma aag_can_read_irq_self:
"is_subject_irq aag x \<Longrightarrow> aag_can_read_irq aag x"
by simp
subsection \<open>Generic equivalence\<close>
definition equiv_for
where
"equiv_for P f c c' \<equiv> \<forall> x. P x \<longrightarrow> f c x = f c' x"
lemma equiv_forE:
assumes e: "equiv_for P f c c'"
obtains "\<And> x. P x \<Longrightarrow> f c x = f c' x"
apply (erule meta_mp)
apply(erule e[simplified equiv_for_def, rule_format])
done
lemma equiv_forI:
"(\<And> x. P x \<Longrightarrow> f c x = f c' x) \<Longrightarrow> equiv_for P f c c'"
by(simp add: equiv_for_def)
lemma equiv_forD:
"equiv_for P f c c' \<Longrightarrow> P x \<Longrightarrow> f c x = f c' x"
apply(blast elim: equiv_forE)
done
lemma equiv_for_comp:
"equiv_for P (f \<circ> g) s s' = equiv_for P f (g s) (g s')"
apply(simp add: equiv_for_def)
done
lemma equiv_for_or:
"equiv_for (A or B) f c c' = (equiv_for A f c c' \<and> equiv_for B f c c')"
by (fastforce simp: equiv_for_def)
lemma equiv_for_id_update:
"equiv_for P id c c' \<Longrightarrow>
equiv_for P id (c(x := v)) (c'(x := v))"
by (simp add: equiv_for_def)
subsection \<open>Machine state equivalence\<close>
abbreviation equiv_machine_state
:: "(word32 \<Rightarrow> bool) \<Rightarrow> 'a machine_state_scheme \<Rightarrow> 'a machine_state_scheme \<Rightarrow> bool"
where
"equiv_machine_state P s s' \<equiv> equiv_for (\<lambda>x. P x) underlying_memory s s' \<and>
equiv_for (\<lambda>x. P x) device_state s s'"
subsection \<open>ASID equivalence\<close>
definition equiv_asid :: "asid \<Rightarrow> det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"equiv_asid asid s s' \<equiv>
((arm_asid_table (arch_state s) (asid_high_bits_of asid)) =
(arm_asid_table (arch_state s') (asid_high_bits_of asid))) \<and>
(\<forall> pool_ptr.
arm_asid_table (arch_state s) (asid_high_bits_of asid) = Some pool_ptr \<longrightarrow>
asid_pool_at pool_ptr s = asid_pool_at pool_ptr s' \<and>
(\<forall> asid_pool asid_pool'.
kheap s pool_ptr = Some (ArchObj (ASIDPool asid_pool)) \<and>
kheap s' pool_ptr = Some (ArchObj (ASIDPool asid_pool')) \<longrightarrow>
asid_pool (ucast asid) = asid_pool' (ucast asid)))"
definition equiv_asid'
where
"equiv_asid' asid pool_ptr_opt pool_ptr_opt' kh kh' \<equiv>
(case pool_ptr_opt of None \<Rightarrow> pool_ptr_opt' = None
| Some pool_ptr \<Rightarrow>
(case pool_ptr_opt' of None \<Rightarrow> False
| Some pool_ptr' \<Rightarrow>
(pool_ptr' = pool_ptr \<and>
((\<exists> asid_pool. kh pool_ptr = Some (ArchObj (ASIDPool asid_pool))) =
(\<exists> asid_pool'. kh' pool_ptr' = Some (ArchObj (ASIDPool asid_pool')))) \<and>
(\<forall> asid_pool asid_pool'.
kh pool_ptr = Some (ArchObj (ASIDPool asid_pool)) \<and>
kh' pool_ptr' = Some (ArchObj (ASIDPool asid_pool')) \<longrightarrow>
asid_pool (ucast asid) = asid_pool' (ucast asid)))
)
)"
lemma asid_pool_at_kheap:
"asid_pool_at ptr s = (\<exists> asid_pool. kheap s ptr = Some (ArchObj (ASIDPool asid_pool)))"
apply(clarsimp simp: obj_at_def)
apply(rule iffI)
apply(erule exE, rename_tac ko, clarsimp)
apply (clarsimp simp: a_type_simps)
done
lemma equiv_asid:
"equiv_asid asid s s' = equiv_asid' asid (arm_asid_table (arch_state s) (asid_high_bits_of asid))
(arm_asid_table (arch_state s') (asid_high_bits_of asid))
(kheap s) (kheap s')"
apply(auto simp: equiv_asid_def equiv_asid'_def split: option.splits simp: asid_pool_at_kheap)
done
definition equiv_asids :: "(asid \<Rightarrow> bool) \<Rightarrow> det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"equiv_asids R s s' \<equiv> \<forall> asid. asid \<noteq> 0 \<and> R asid \<longrightarrow> equiv_asid asid s s'"
lemma equiv_asids_refl:
"equiv_asids R s s"
apply(auto simp: equiv_asids_def equiv_asid_def)
done
lemma equiv_asids_sym:
"equiv_asids R s t \<Longrightarrow> equiv_asids R t s"
apply(auto simp: equiv_asids_def equiv_asid_def)
done
lemma equiv_asids_trans:
"\<lbrakk>equiv_asids R s t; equiv_asids R t u\<rbrakk> \<Longrightarrow> equiv_asids R s u"
apply(fastforce simp: equiv_asids_def equiv_asid_def asid_pool_at_kheap)
done
definition non_asid_pool_kheap_update
where
"non_asid_pool_kheap_update s kh \<equiv>
\<forall>x. (\<exists> asid_pool. kheap s x = Some (ArchObj (ASIDPool asid_pool)) \<or>
kh x = Some (ArchObj (ASIDPool asid_pool))) \<longrightarrow> kheap s x = kh x"
definition identical_updates
where
"identical_updates k k' kh kh' \<equiv> \<forall>x. (kh x \<noteq> kh' x \<longrightarrow> (k x = kh x \<and> k' x = kh' x))"
abbreviation identical_kheap_updates
where
"identical_kheap_updates s s' kh kh' \<equiv> identical_updates (kheap s) (kheap s') kh kh'"
abbreviation identical_ekheap_updates
where
"identical_ekheap_updates s s' kh kh' \<equiv> identical_updates (ekheap s) (ekheap s') kh kh'"
lemmas identical_kheap_updates_def = identical_updates_def
lemmas identical_ekheap_updates_def = identical_updates_def
lemma equiv_asids_non_asid_pool_kheap_update:
"\<lbrakk>equiv_asids R s s';
non_asid_pool_kheap_update s kh; non_asid_pool_kheap_update s' kh'\<rbrakk> \<Longrightarrow>
equiv_asids R (s\<lparr>kheap := kh\<rparr>) (s'\<lparr>kheap := kh'\<rparr>)"
apply(clarsimp simp: equiv_asids_def equiv_asid non_asid_pool_kheap_update_def)
apply(fastforce simp: equiv_asid'_def split: option.splits)
done
lemma equiv_asids_identical_kheap_updates:
"\<lbrakk>equiv_asids R s s';
identical_kheap_updates s s' kh kh'\<rbrakk> \<Longrightarrow>
equiv_asids R (s\<lparr>kheap := kh\<rparr>) (s'\<lparr>kheap := kh'\<rparr>)"
apply(clarsimp simp: equiv_asids_def identical_kheap_updates_def)
apply(clarsimp simp: equiv_asid_def asid_pool_at_kheap)
apply(case_tac "kh pool_ptr = kh' pool_ptr")
apply fastforce
apply fastforce
done
lemma equiv_asids_triv:
"\<lbrakk>equiv_asids R s s';
kheap t = kheap s; arm_asid_table (arch_state t) = arm_asid_table (arch_state s);
kheap t' = kheap s'; arm_asid_table (arch_state t') = arm_asid_table (arch_state s')\<rbrakk> \<Longrightarrow>
equiv_asids R t t'"
apply(fastforce simp: equiv_asids_def equiv_asid equiv_asid'_def)
done
subsection \<open>Generic state equivalence\<close>
text\<open>Define state equivalence for a given set of object references, irqs, asids and domains
The first four parameters are just predicate for those four sets:
- P : object reference predicate
- Q : irq predicate
- R : asid predicate
- S : domain predicate
\<close>
(*FIXME: We're not ancient Romans and don't need to condense the meaning of
the universe into S P Q R *)
definition states_equiv_for
:: "(word32 \<Rightarrow> bool) \<Rightarrow> (10 word \<Rightarrow> bool) \<Rightarrow> (asid \<Rightarrow> bool) \<Rightarrow> (domain \<Rightarrow> bool) \<Rightarrow>
det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"states_equiv_for P Q R S s s' \<equiv>
equiv_for P kheap s s' \<and>
equiv_machine_state P (machine_state s) (machine_state s') \<and>
equiv_for (P \<circ> fst) cdt s s' \<and>
equiv_for P ekheap s s' \<and>
equiv_for (P \<circ> fst) cdt_list s s' \<and>
equiv_for (P \<circ> fst) is_original_cap s s' \<and>
equiv_for Q interrupt_states s s' \<and>
equiv_for Q interrupt_irq_node s s' \<and>
equiv_for S ready_queues s s' \<and>
equiv_asids R s s'"
(* This the main use of states_equiv_for : P is use to restrict the labels we want to consider *)
abbreviation states_equiv_for_labels :: "'a PAS \<Rightarrow> ('a \<Rightarrow> bool)\<Rightarrow> det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"states_equiv_for_labels aag P \<equiv>
states_equiv_for (\<lambda> x. P (pasObjectAbs aag x)) (\<lambda> x. P (pasIRQAbs aag x))
(\<lambda> x. P (pasASIDAbs aag x)) (\<lambda> x. \<exists>l\<in>pasDomainAbs aag x. P l)"
(* We need this to correctly complement the domain mapping, i.e. it's not true that
states_equiv_but_for_labels aag P = states_equiv_for_labels aag (not P) *)
abbreviation states_equiv_but_for_labels :: "'a PAS \<Rightarrow> ('a \<Rightarrow> bool)\<Rightarrow> det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"states_equiv_but_for_labels aag P \<equiv>
states_equiv_for (\<lambda> x. \<not> P (pasObjectAbs aag x)) (\<lambda> x. \<not> P (pasIRQAbs aag x))
(\<lambda> x. \<not> P (pasASIDAbs aag x)) (\<lambda> x. \<forall>l\<in>pasDomainAbs aag x. \<not> P l)"
lemma states_equiv_forI:
"\<lbrakk>equiv_for P kheap s s';
equiv_machine_state P (machine_state s) (machine_state s');
equiv_for (P \<circ> fst) cdt s s';
equiv_for P ekheap s s';
equiv_for (P \<circ> fst) cdt_list s s';
equiv_for (P \<circ> fst) is_original_cap s s';
equiv_for Q interrupt_states s s';
equiv_for Q interrupt_irq_node s s';
equiv_asids R s s';
equiv_for S ready_queues s s'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S s s'"
by(auto simp: states_equiv_for_def)
lemma states_equiv_for_machine_state_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_machine_state P kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> machine_state := kh \<rparr>) (s'\<lparr> machine_state := kh' \<rparr>)"
apply(fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
done
lemma states_equiv_for_non_asid_pool_kheap_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for P id kh kh';
non_asid_pool_kheap_update s kh; non_asid_pool_kheap_update s' kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
apply(fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_non_asid_pool_kheap_update)
done
lemma states_equiv_for_identical_kheap_updates:
"\<lbrakk>states_equiv_for P Q R S s s';
identical_kheap_updates s s' kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
apply(clarsimp simp: states_equiv_for_def)
apply(auto elim!: equiv_forE intro!: equiv_forI elim!: equiv_asids_identical_kheap_updates
simp: identical_kheap_updates_def)
done
lemma states_equiv_for_cdt_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for (P \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> cdt := kh \<rparr>) (s'\<lparr> cdt := kh' \<rparr>)"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_cdt_list_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for (P \<circ> fst) id (kh (cdt_list s)) (kh' (cdt_list s'))\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (cdt_list_update kh s) (cdt_list_update kh' s')"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_identical_ekheap_updates:
"\<lbrakk>states_equiv_for P Q R S s s';
identical_ekheap_updates s s' (kh (ekheap s)) (kh' (ekheap s'))\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (ekheap_update kh s) (ekheap_update kh' s')"
by (fastforce simp: identical_ekheap_updates_def equiv_for_def states_equiv_for_def
equiv_asids_def equiv_asid_def)
lemma states_equiv_for_ekheap_update:
"\<lbrakk>states_equiv_for P Q R S s s';
equiv_for P id (kh (ekheap s)) (kh' (ekheap s'))\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (ekheap_update kh s) (ekheap_update kh' s')"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_is_original_cap_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for (P \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> is_original_cap := kh \<rparr>) (s'\<lparr> is_original_cap := kh' \<rparr>)"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_interrupt_states_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for Q id kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> interrupt_states := kh \<rparr>) (s'\<lparr> interrupt_states := kh' \<rparr>)"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_interrupt_irq_node_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for Q id kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> interrupt_irq_node := kh \<rparr>) (s'\<lparr> interrupt_irq_node := kh' \<rparr>)"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_for_ready_queues_update:
"\<lbrakk>states_equiv_for P Q R S s s'; equiv_for S id kh kh'\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S (s\<lparr> ready_queues := kh \<rparr>) (s'\<lparr> ready_queues := kh' \<rparr>)"
by (fastforce simp: states_equiv_for_def elim: equiv_forE intro: equiv_forI
elim!: equiv_asids_triv)
lemma states_equiv_forE:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "equiv_machine_state P (machine_state s) (machine_state s')"
"equiv_for P kheap s s'"
"equiv_for (P \<circ> fst) cdt s s'"
"equiv_for (P \<circ> fst) cdt_list s s'"
"equiv_for P ekheap s s'"
"equiv_for (P \<circ> fst) is_original_cap s s'"
"equiv_for Q interrupt_states s s'"
"equiv_for Q interrupt_irq_node s s'"
"equiv_asids R s s'"
"equiv_for S ready_queues s s'"
using sef[simplified states_equiv_for_def] by auto
lemma equiv_for_apply: "equiv_for P g (f s) (f s') = equiv_for P (g o f) s s'"
by (simp add: equiv_for_def)
lemma states_equiv_forE_kheap:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P x \<Longrightarrow> kheap s x = kheap s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_mem:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P x \<Longrightarrow>
(underlying_memory (machine_state s)) x = (underlying_memory (machine_state s')) x \<and>
(device_state (machine_state s)) x = (device_state (machine_state s')) x"
using sef
apply (clarsimp simp: states_equiv_for_def elim: equiv_forE)
apply (elim equiv_forE)
apply fastforce
done
lemma states_equiv_forE_cdt:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P (fst x) \<Longrightarrow> cdt s x = cdt s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_cdt_list:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P (fst x) \<Longrightarrow> cdt_list s x = cdt_list s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_ekheap:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P x \<Longrightarrow> ekheap s x = ekheap s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_is_original_cap:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. P (fst x) \<Longrightarrow> is_original_cap s x = is_original_cap s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_interrupt_states:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. Q x \<Longrightarrow> interrupt_states s x = interrupt_states s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_interrupt_irq_node:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. Q x \<Longrightarrow> interrupt_irq_node s x = interrupt_irq_node s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma states_equiv_forE_ready_queues:
assumes sef: "states_equiv_for P Q R S s s'"
obtains "\<And> x. S x \<Longrightarrow> ready_queues s x = ready_queues s' x"
using sef by(auto simp: states_equiv_for_def elim: equiv_forE)
lemma equiv_for_refl:
"equiv_for P f s s"
by(auto simp: equiv_for_def)
lemma equiv_for_sym:
"equiv_for P f s t \<Longrightarrow> equiv_for P f t s"
by(auto simp: equiv_for_def)
lemma equiv_for_trans:
"\<lbrakk>equiv_for P f s t; equiv_for P f t u\<rbrakk> \<Longrightarrow>
equiv_for P f s u"
by(auto simp: equiv_for_def)
lemma states_equiv_for_refl:
"states_equiv_for P Q R S s s"
by(auto simp: states_equiv_for_def intro: equiv_for_refl equiv_asids_refl)
lemma states_equiv_for_sym:
"states_equiv_for P Q R S s t \<Longrightarrow> states_equiv_for P Q R S t s"
by (auto simp: states_equiv_for_def intro: equiv_for_sym equiv_asids_sym simp: equiv_for_def)
lemma states_equiv_for_trans:
"\<lbrakk>states_equiv_for P Q R S s t; states_equiv_for P Q R S t u\<rbrakk> \<Longrightarrow>
states_equiv_for P Q R S s u"
by (auto simp: states_equiv_for_def
intro: equiv_for_trans equiv_asids_trans equiv_forI
elim: equiv_forE)
(* FIXME MOVE *)
lemma or_comp_dist:
"(A or B) \<circ> f = (A \<circ> f or B \<circ> f)"
by (simp add: pred_disj_def comp_def)
subsection \<open>Idle thread equivalence\<close>
definition idle_equiv :: "('z :: state_ext) state \<Rightarrow> ('z :: state_ext) state \<Rightarrow> bool"
where
"idle_equiv s s' \<equiv> idle_thread s = idle_thread s' \<and>
(\<forall>tcb tcb'. kheap s (idle_thread s) = Some (TCB tcb) \<longrightarrow>
kheap s' (idle_thread s) = Some (TCB tcb') \<longrightarrow>
arch_tcb_context_get (tcb_arch tcb) = arch_tcb_context_get (tcb_arch tcb')) \<and>
(tcb_at (idle_thread s) s \<longleftrightarrow> tcb_at (idle_thread s) s')"
lemma idle_equiv_refl: "idle_equiv s s"
by (simp add: idle_equiv_def)
lemma idle_equiv_sym: "idle_equiv s s' \<Longrightarrow> idle_equiv s' s"
by (clarsimp simp add: idle_equiv_def)
lemma idle_equiv_trans: "idle_equiv s s' \<Longrightarrow> idle_equiv s' s'' \<Longrightarrow> idle_equiv s s''"
by (clarsimp simp add: idle_equiv_def tcb_at_def get_tcb_def split: option.splits
kernel_object.splits)
subsection \<open>Exclusive machine state equivalence\<close>
abbreviation exclusive_state_equiv
where
"exclusive_state_equiv s s' \<equiv>
exclusive_state (machine_state s) = exclusive_state (machine_state s')"
subsection \<open>Global (Kernel) VSpace equivalence\<close>
(* globals_equiv should be maintained by everything except the scheduler, since
nothing else touches the globals frame *)
(* cur_thread is included here also to enforce this being an equivalence relation *)
definition globals_equiv :: "('z :: state_ext) state \<Rightarrow> ('z :: state_ext) state \<Rightarrow> bool" where
"globals_equiv s s' \<equiv>
arm_global_pd (arch_state s) = arm_global_pd (arch_state s') \<and>
kheap s (arm_global_pd (arch_state s)) = kheap s' (arm_global_pd (arch_state s)) \<and>
idle_equiv s s' \<and>
dom (device_state (machine_state s)) = dom (device_state (machine_state s')) \<and>
cur_thread s = cur_thread s' \<and>
(cur_thread s \<noteq> idle_thread s \<longrightarrow> exclusive_state_equiv s s')"
subsection \<open>read_equiv\<close>
(* Basically defines the domain of the current thread, excluding globals.
This also includes the things that are in the scheduler's domain, which
the current domain is always allowed to read. *)
definition reads_equiv :: "'a PAS \<Rightarrow> det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"reads_equiv aag s s' \<equiv>
((\<forall> d\<in>subjectReads (pasPolicy aag) (pasSubject aag).
states_equiv_for_labels aag ((=) d) s s') \<and>
cur_thread s = cur_thread s' \<and>
cur_domain s = cur_domain s' \<and>
scheduler_action s = scheduler_action s' \<and>
work_units_completed s = work_units_completed s' \<and>
irq_state (machine_state s) = irq_state (machine_state s'))"
(* this is the main equivalence we want to be maintained, since it defines
everything the current thread can read from; however, we'll deal with
reads_equiv in the reads_respects proofs, since globals_equiv is always preserved *)
definition reads_equiv_g :: "'a PAS \<Rightarrow> det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"reads_equiv_g aag s s' \<equiv> reads_equiv aag s s' \<and> globals_equiv s s'"
lemma reads_equiv_def2:
"reads_equiv aag s s' =
(states_equiv_for (aag_can_read aag) (aag_can_read_irq aag) (aag_can_read_asid aag)
(aag_can_read_domain aag) s s' \<and>
cur_thread s = cur_thread s' \<and> cur_domain s = cur_domain s' \<and>
scheduler_action s = scheduler_action s' \<and> work_units_completed s = work_units_completed s' \<and>
irq_state (machine_state s) = irq_state (machine_state s'))"
apply(rule iffI)
apply(auto simp: reads_equiv_def equiv_for_def states_equiv_for_def equiv_asids_def)
done
lemma reads_equivE:
assumes sef: "reads_equiv aag s s'"
obtains "equiv_for (aag_can_read aag) kheap s s'"
"equiv_machine_state (aag_can_read aag) (machine_state s) (machine_state s')"
"equiv_for ((aag_can_read aag) \<circ> fst) cdt s s'"
"equiv_for ((aag_can_read aag) \<circ> fst) cdt_list s s'"
"equiv_for (aag_can_read aag) ekheap s s'"
"equiv_for ((aag_can_read aag) \<circ> fst) is_original_cap s s'"
"equiv_for (aag_can_read_irq aag) interrupt_states s s'"
"equiv_for (aag_can_read_irq aag) interrupt_irq_node s s'"
"equiv_asids (aag_can_read_asid aag) s s'"
"equiv_for (aag_can_read_domain aag) ready_queues s s'"
"cur_thread s = cur_thread s'"
"cur_domain s = cur_domain s'"
"scheduler_action s = scheduler_action s'"
"work_units_completed s = work_units_completed s'"
"irq_state (machine_state s) = irq_state (machine_state s')"
using sef by(auto simp: reads_equiv_def2 elim: states_equiv_forE)
lemma reads_equiv_machine_state_update:
"\<lbrakk>reads_equiv aag s s'; equiv_machine_state (aag_can_read aag) kh kh'; irq_state kh = irq_state kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> machine_state := kh \<rparr>) (s'\<lparr> machine_state := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_machine_state_update)
lemma reads_equiv_non_asid_pool_kheap_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for (aag_can_read aag) id kh kh';
non_asid_pool_kheap_update s kh; non_asid_pool_kheap_update s' kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_non_asid_pool_kheap_update)
lemma reads_equiv_identical_kheap_updates:
"\<lbrakk>reads_equiv aag s s';
identical_kheap_updates s s' kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_identical_kheap_updates)
lemma reads_equiv_cdt_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for ((aag_can_read aag) \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> cdt := kh \<rparr>) (s'\<lparr> cdt := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_cdt_update)
lemma reads_equiv_cdt_list_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for ((aag_can_read aag) \<circ> fst) id (kh (cdt_list s)) (kh' (cdt_list s'))\<rbrakk> \<Longrightarrow>
reads_equiv aag (cdt_list_update kh s) (cdt_list_update kh' s')"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_cdt_list_update)
lemma reads_equiv_identical_ekheap_updates:
"\<lbrakk>reads_equiv aag s s'; identical_ekheap_updates s s' (kh (ekheap s)) (kh' (ekheap s'))\<rbrakk> \<Longrightarrow>
reads_equiv aag (ekheap_update kh s) (ekheap_update kh' s')"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_identical_ekheap_updates)
lemma reads_equiv_ekheap_updates:
"\<lbrakk>reads_equiv aag s s'; equiv_for (aag_can_read aag) id (kh (ekheap s)) (kh' (ekheap s')) \<rbrakk> \<Longrightarrow>
reads_equiv aag (ekheap_update kh s) (ekheap_update kh' s')"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_ekheap_update)
lemma reads_equiv_is_original_cap_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for ((aag_can_read aag) \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> is_original_cap := kh \<rparr>) (s'\<lparr> is_original_cap := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_is_original_cap_update)
lemma reads_equiv_interrupt_states_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for (aag_can_read_irq aag) id kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> interrupt_states := kh \<rparr>) (s'\<lparr> interrupt_states := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_interrupt_states_update)
lemma reads_equiv_interrupt_irq_node_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for (aag_can_read_irq aag) id kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> interrupt_irq_node := kh \<rparr>) (s'\<lparr> interrupt_irq_node := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_interrupt_irq_node_update)
lemma reads_equiv_ready_queues_update:
"\<lbrakk>reads_equiv aag s s'; equiv_for (aag_can_read_domain aag) id kh kh'\<rbrakk> \<Longrightarrow>
reads_equiv aag (s\<lparr> ready_queues := kh \<rparr>) (s'\<lparr> ready_queues := kh' \<rparr>)"
by (fastforce simp: reads_equiv_def2 intro: states_equiv_for_ready_queues_update)
lemma reads_equiv_scheduler_action_update:
"reads_equiv aag s s' \<Longrightarrow>
reads_equiv aag (s\<lparr> scheduler_action := kh \<rparr>) (s'\<lparr> scheduler_action := kh \<rparr>)"
by (fastforce simp: reads_equiv_def2 states_equiv_for_def equiv_for_def elim!: equiv_asids_triv)
lemma reads_equiv_work_units_completed_update:
"reads_equiv aag s s' \<Longrightarrow>
reads_equiv aag (s\<lparr> work_units_completed := kh \<rparr>) (s'\<lparr> work_units_completed := kh \<rparr>)"
by (fastforce simp: reads_equiv_def2 states_equiv_for_def equiv_for_def elim!: equiv_asids_triv)
lemma reads_equiv_work_units_completed_update':
"reads_equiv aag s s' \<Longrightarrow>
reads_equiv aag (s\<lparr> work_units_completed := (f (work_units_completed s)) \<rparr>)
(s'\<lparr> work_units_completed := (f (work_units_completed s')) \<rparr>)"
by (fastforce simp: reads_equiv_def2 states_equiv_for_def equiv_for_def elim!: equiv_asids_triv)
section \<open>Writing: subjectsAffects and affects_equiv\<close>
text \<open>
This defines the other labels of the authority graph that subject l can
affect, i.e. if there is some part of the state that carries a label l', and
through the actions of l, this state can be modified, then we say that the
label l' can be affected by l. This is, of course, just a more coarse
statement of the integrity property from the access proofs.
The case in which @{thm tro_asidpool_clear} is covered when the graph is wellformed
since, in this case, the subject has Control rights to the asid.
\<close>
inductive_set subjectAffects :: "'a auth_graph \<Rightarrow> 'a \<Rightarrow> 'a set"
for g :: "'a auth_graph" and l :: "'a"
where
affects_lrefl:
"l \<in> subjectAffects g l" |
affects_write:
"\<lbrakk>(l,auth,l') \<in> g; auth \<in> {Control, Write}\<rbrakk> \<Longrightarrow>
l' \<in> subjectAffects g l" |
affects_ep:
"\<lbrakk>(l,auth,l') \<in> g; auth \<in> {Receive, Notify, SyncSend, Call, Reset}\<rbrakk> \<Longrightarrow>
l' \<in> subjectAffects g l" |
(* ipc buffer is not necessarily owned by thread *)
affects_send:
"\<lbrakk>(l,auth,ep) \<in> g; auth \<in> {SyncSend, Notify, Call}; (l',Receive,ep) \<in> g;
(l',Write,l'') \<in> g\<rbrakk> \<Longrightarrow>
l'' \<in> subjectAffects g l" |
(* synchronous sends provide a back-channel from receiver to sender *)
affects_recv:
"\<lbrakk>(l,Receive,ep) \<in> g; (l',SyncSend,ep) \<in> g\<rbrakk> \<Longrightarrow>
l' \<in> subjectAffects g l" |
(* a reply right can only exist if l has a call right to l',
* so including this case saves us from having to re-derive it *)
affects_reply_back:
"\<lbrakk>(l',Reply,l) \<in> g\<rbrakk> \<Longrightarrow>
l' \<in> subjectAffects g l" |
(* reply direct ipc buffer writing *)
affects_reply:
"\<lbrakk>(l,Reply,l') \<in> g; (l',Write,l'') \<in> g\<rbrakk> \<Longrightarrow>
l'' \<in> subjectAffects g l" |
(* deletion direct channel *)
affects_delete_derived:
"\<lbrakk>(l,DeleteDerived,l') \<in> g\<rbrakk> \<Longrightarrow>
l' \<in> subjectAffects g l" |
(* If two agents can delete the same caps, they can affect each other *)
affects_delete_derived2:
"\<lbrakk>(l,DeleteDerived,l') \<in> g; (l'',DeleteDerived,l') \<in> g\<rbrakk> \<Longrightarrow>
l'' \<in> subjectAffects g l" |
(* integrity definitions allow resets to modify ipc buffer *)
affects_reset:
"\<lbrakk>(l,Reset,ep) \<in> g; (l',auth,ep) \<in> g; auth \<in> {SyncSend, Receive};
(l',Write,l'') \<in> g\<rbrakk> \<Longrightarrow>
l'' \<in> subjectAffects g l" |
(* if you alter an asid mapping, you affect the domain who owns that asid *)
affects_asidpool_map:
"(l,ASIDPoolMapsASID,l') \<in> g \<Longrightarrow> l' \<in> subjectAffects g l" |
(* if you are sending to an ntfn, which is bound to a tcb that is
receive blocked on an ep, then you can affect that ep *)
affects_ep_bound_trans:
"\<lbrakk>\<exists>tcb ntfn. (tcb, Receive, ntfn) \<in> g \<and> (tcb, Receive, ep) \<in> g \<and>
(l, Notify, ntfn) \<in> g\<rbrakk> \<Longrightarrow>
ep \<in> subjectAffects g l"
(* We define when the current subject can affect another domain whose label is
l. This occurs when the current subject can affect some label d that is
considered to be part of what domain l can read. *)
definition aag_can_affect_label
where
"aag_can_affect_label aag l \<equiv> \<exists> d. d \<in> subjectAffects (pasPolicy aag) (pasSubject aag) \<and>
d \<in> subjectReads (pasPolicy aag) l"
lemma aag_can_affect_labelI[intro!]:
"\<lbrakk>d \<in> subjectAffects (pasPolicy aag) (pasSubject aag); d \<in> subjectReads (pasPolicy aag) l\<rbrakk>
\<Longrightarrow> aag_can_affect_label aag l"
by (auto simp: aag_can_affect_label_def)
(* Defines when two states are equivalent for some domain l that can be affected
by the current subject. When the current subject cannot affect domain l,
we relate all states. *)
definition affects_equiv :: "'a PAS \<Rightarrow> 'a \<Rightarrow> det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"affects_equiv aag l s s' \<equiv>
(if (aag_can_affect_label aag l) then
(states_equiv_for_labels aag (\<lambda>l'. l' \<in> subjectReads (pasPolicy aag) l) s s')
else True)"
lemma equiv_for_trivial:
"(\<And> x. P x \<Longrightarrow> False) \<Longrightarrow> equiv_for P f c c'"
by (auto simp: equiv_for_def)
lemma equiv_asids_trivial:
"(\<And> x. P x \<Longrightarrow> False) \<Longrightarrow> equiv_asids P x y"
by (auto simp: equiv_asids_def)
abbreviation aag_can_affect
where
"aag_can_affect aag l \<equiv> \<lambda>x. aag_can_affect_label aag l \<and>
pasObjectAbs aag x \<in> subjectReads (pasPolicy aag) l"
abbreviation aag_can_affect_irq
where
"aag_can_affect_irq aag l \<equiv> \<lambda>x. aag_can_affect_label aag l \<and>
pasIRQAbs aag x \<in> subjectReads (pasPolicy aag) l"
abbreviation aag_can_affect_asid
where
"aag_can_affect_asid aag l \<equiv> \<lambda>x. aag_can_affect_label aag l \<and>
pasASIDAbs aag x \<in> subjectReads (pasPolicy aag) l"
abbreviation aag_can_affect_domain
where
"aag_can_affect_domain aag l \<equiv> \<lambda>x. aag_can_affect_label aag l \<and>
pasDomainAbs aag x \<inter> subjectReads (pasPolicy aag) l \<noteq> {}"
lemma affects_equiv_def2:
"affects_equiv aag l s s' = states_equiv_for (aag_can_affect aag l) (aag_can_affect_irq aag l) (aag_can_affect_asid aag l) (aag_can_affect_domain aag l) s s'"
apply(clarsimp simp: affects_equiv_def)
apply(auto intro!: states_equiv_forI equiv_forI equiv_asids_trivial
dest: equiv_forD
elim!: states_equiv_forE)
done
lemma affects_equivE:
assumes sef: "affects_equiv aag l s s'"
obtains "equiv_for (aag_can_affect aag l) kheap s s'"
"equiv_machine_state (aag_can_affect aag l) (machine_state s) (machine_state s')"
"equiv_for ((aag_can_affect aag l) \<circ> fst) cdt s s'"
"equiv_for ((aag_can_affect aag l) \<circ> fst) cdt_list s s'"
"equiv_for (aag_can_affect aag l) ekheap s s'"
"equiv_for ((aag_can_affect aag l) \<circ> fst) is_original_cap s s'"
"equiv_for (aag_can_affect_irq aag l) interrupt_states s s'"
"equiv_for (aag_can_affect_irq aag l) interrupt_irq_node s s'"
"equiv_asids (aag_can_affect_asid aag l) s s'"
"equiv_for (aag_can_affect_domain aag l) ready_queues s s'"
using sef by(auto simp: affects_equiv_def2 elim: states_equiv_forE)
lemma affects_equiv_machine_state_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_machine_state (aag_can_affect aag l) kh kh'\<rbrakk> \<Longrightarrow>
affects_equiv aag l (s\<lparr> machine_state := kh \<rparr>) (s'\<lparr> machine_state := kh' \<rparr>)"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_machine_state_update)
done
lemma affects_equiv_non_asid_pool_kheap_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_for (aag_can_affect aag l) id kh kh';
non_asid_pool_kheap_update s kh; non_asid_pool_kheap_update s' kh'\<rbrakk> \<Longrightarrow>
affects_equiv aag l (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_non_asid_pool_kheap_update)
done
lemma affects_equiv_identical_kheap_updates:
"\<lbrakk>affects_equiv aag l s s';
identical_kheap_updates s s' kh kh'\<rbrakk> \<Longrightarrow>
affects_equiv aag l (s\<lparr> kheap := kh \<rparr>) (s'\<lparr> kheap := kh' \<rparr>)"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_identical_kheap_updates)
done
lemma affects_equiv_cdt_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_for ((aag_can_affect aag l) \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
affects_equiv aag l (s\<lparr> cdt := kh \<rparr>) (s'\<lparr> cdt := kh' \<rparr>)"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_cdt_update)
done
lemma affects_equiv_cdt_list_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_for ((aag_can_affect aag l) \<circ> fst) id (kh (cdt_list s)) (kh' (cdt_list s'))\<rbrakk> \<Longrightarrow>
affects_equiv aag l (cdt_list_update kh s) (cdt_list_update kh' s')"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_cdt_list_update)
done
lemma affects_equiv_identical_ekheap_updates:
"\<lbrakk>affects_equiv aag l s s'; identical_ekheap_updates s s' (kh (ekheap s)) (kh' (ekheap s'))\<rbrakk> \<Longrightarrow>
affects_equiv aag l (ekheap_update kh s) (ekheap_update kh' s')"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_identical_ekheap_updates)
done
lemma affects_equiv_ekheap_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_for (aag_can_affect aag l) id (kh (ekheap s)) (kh' (ekheap s')) \<rbrakk> \<Longrightarrow>
affects_equiv aag l (ekheap_update kh s) (ekheap_update kh' s')"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_ekheap_update)
done
lemma affects_equiv_is_original_cap_update:
"\<lbrakk>affects_equiv aag l s s'; equiv_for ((aag_can_affect aag l) \<circ> fst) id kh kh'\<rbrakk> \<Longrightarrow>
affects_equiv aag l (s\<lparr> is_original_cap := kh \<rparr>) (s'\<lparr> is_original_cap := kh' \<rparr>)"
apply(fastforce simp: affects_equiv_def2 intro: states_equiv_for_is_original_cap_update)
done