-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleSystem.thy
1117 lines (898 loc) · 37.1 KB
/
ExampleSystem.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 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
* See "LICENSE_GPLv2.txt" for details.
*
* @TAG(NICTA_GPL)
*)
theory ExampleSystem
imports Access
begin
definition
nat_to_bl :: "nat \<Rightarrow> nat \<Rightarrow> bool list option"
where
"nat_to_bl bits n \<equiv>
if n \<ge> 2^bits then
None
else
Some $ bin_to_bl bits (of_nat n)"
lemma nat_to_bl_id [simp]: "nat_to_bl (size (x :: (('a::len) word))) (unat x) = Some (to_bl x)"
apply (clarsimp simp: nat_to_bl_def to_bl_def)
apply (auto simp: uint_nat le_def word_size)
done
(*---------------------------------------------------------*)
subsection {* Purpose *}
text {*
This file defines some example systems using the access control
definitions. The aim is a sanity check of the AC definitions, to
ensure they enable to reason about reasonable systems.
In particular, we want to make sure that
. the function state_objs_to_policy does not connect everything to
everything (Example 1)
. we can talk about components sharing cnodes
. we can talk about components sharing frames
. we can have more than 1 untrusted component
. we can have an EP between two untrusted components
*}
(*---------------------------------------------------------*)
subsection {* Generic functions / lemmas *}
text {* Defining the authority between labels.
In addition to the intuitive authority we want, we need to add all the
authority required to have a wellformed graph. So we define
complete_AgentAuthGraph to add these 'extra' authorities (at least all
the ones not depending on the current label). These are:
. self-authority (each label needs all the authorities to itself).
. if Control edge is present between 2 labels then we add all
authorities between them.
. Control authority is transitive: we add an Control edge
between 2 labels if we can connect them via Control
edges. Actually we add all authorities because of the second
clause.
*}
definition
complete_AuthGraph :: "'a auth_graph \<Rightarrow> 'a set \<Rightarrow> 'a auth_graph"
where
"complete_AuthGraph g ls \<equiv>
g \<union> {(l,a,l) | a l. l \<in> ls}"
text {* converting a nat to a bool list of size 10 - for the cnodes *}
definition
the_nat_to_bl :: "nat \<Rightarrow> nat \<Rightarrow> bool list"
where
"the_nat_to_bl sz n \<equiv> the (nat_to_bl sz n)"
definition
the_nat_to_bl_10 :: "nat \<Rightarrow> bool list"
where
"the_nat_to_bl_10 n \<equiv> the_nat_to_bl 10 n"
lemma tcb_cnode_index_nat_to_bl:
"n<10 \<Longrightarrow> the_nat_to_bl_10 n \<noteq> tcb_cnode_index n"
by (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def
tcb_cnode_index_def
nat_to_bl_def to_bl_def bin_to_bl_aux_def)
(*---------------------------------------------------------*)
subsection {* Example 1 *}
text {*
This example aims at checking that we can extract a reasonable policy
from the state, i.e. that the function state_objs_to_policy does not connect
everything to everything.
This example is a system Sys1 made of 2 main components UT1 and T1,
connected through and endpoint EP1. EP1 is made of one single kernel
object: obj1_9, the endpoint. Both UT1 and T1 contains:
. one TCB (obj1_3079 and obj1_3080 resp.)
. one vspace made up of one page directory (obj1_6063 and obj1_3065 resp.)
. each pd contains a single page table (obj1_3072 and obj1_3077 resp.)
. one cspace made up of one cnode (obj1_6 and obj1_7 resp.)
. each cspace contains 4 caps:
one to the tcb
one to the cnode itself
one to the vspace
one to the ep
UT1 can send to the ep while T1 can receive from it.
Attempt to ASCII art:
-------- ---- ---- --------
| | | | | | | |
V | | V S R | V | V
obj1_3079(tcb)-->obj1_6(cnode)--->obj1_9(ep)<---obj1_7(cnode)<--obj1_3080(tcb)
| | | |
V | | V
obj1_3063(pd)<----- -------> obj1_3065(pd)
| |
V V
obj1_3072(pt) obj1_3077(pt)
(the references are derived from the dump of the SAC system)
The aim is to be able to prove
pas_refined Sys1PAS s1
where Sys1PAS is the label graph defining the AC policy for Sys1 and
s1 is the state of Sys1 described above.
This shows that the aag extracted from s1 (by state_objs_to_policy) is
included in the policy graph Sys1PAS.
*}
subsubsection {* Defining the State *}
text {* We need to define the asids of each pd and pt to ensure that
the object is included in the right ASID-label *}
text {* UT1's ASID *}
definition
asid1_3063 :: machine_word
where
"asid1_3063 \<equiv> 1<<asid_low_bits"
text {* T1's ASID *}
definition
asid1_3065 :: machine_word
where
"asid1_3065 \<equiv> 2<<asid_low_bits"
lemma "asid_high_bits_of asid1_3065 \<noteq> asid_high_bits_of asid1_3063"
by (simp add: asid1_3063_def asid_high_bits_of_def asid1_3065_def asid_low_bits_def)
text {* UT1's CSpace *}
definition
caps1_6 :: Structures_A.cnode_contents
where
"caps1_6 \<equiv>
(empty_cnode 10)
( (the_nat_to_bl_10 1)
\<mapsto> Structures_A.ThreadCap 3079,
(the_nat_to_bl_10 2)
\<mapsto> Structures_A.CNodeCap 6 undefined undefined,
(the_nat_to_bl_10 3)
\<mapsto> Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3063
(Some asid1_3063)),
(the_nat_to_bl_10 318)
\<mapsto> Structures_A.EndpointCap 9 0 {AllowSend} )"
definition
obj1_6 :: Structures_A.kernel_object
where
"obj1_6 \<equiv> Structures_A.CNode 10 caps1_6"
text {* T1's Cspace *}
definition
caps1_7 :: Structures_A.cnode_contents
where
"caps1_7 \<equiv>
(empty_cnode 10)
( (the_nat_to_bl_10 1)
\<mapsto> Structures_A.ThreadCap 3080,
(the_nat_to_bl_10 2)
\<mapsto> Structures_A.CNodeCap 7 undefined undefined,
(the_nat_to_bl_10 3)
\<mapsto> Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3065
(Some asid1_3065)),
(the_nat_to_bl_10 318)
\<mapsto> Structures_A.EndpointCap 9 0 {AllowRecv}) "
definition
obj1_7 :: Structures_A.kernel_object
where
"obj1_7 \<equiv> Structures_A.CNode 10 caps1_7"
text {* endpoint between UT1 and T1 *}
definition
obj1_9 :: Structures_A.kernel_object
where
"obj1_9 \<equiv> Structures_A.Endpoint Structures_A.IdleEP"
text {* UT1's VSpace (PageDirectory)*}
definition
pt1_3072 :: "word8 \<Rightarrow> ARM_Structs_A.pte "
where
"pt1_3072 \<equiv> (\<lambda>_. ARM_Structs_A.InvalidPTE)"
definition
obj1_3072 :: Structures_A.kernel_object
where
"obj1_3072 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageTable pt1_3072)"
definition
pd1_3063 :: "12 word \<Rightarrow> ARM_Structs_A.pde "
where
"pd1_3063 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPDE)
(0 := ARM_Structs_A.PageTablePDE
(Platform.addrFromPPtr 3072)
undefined
undefined )"
(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check
if it's right *)
definition
obj1_3063 :: Structures_A.kernel_object
where
"obj1_3063 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageDirectory pd1_3063)"
text {* T1's VSpace (PageDirectory)*}
definition
pt1_3077 :: "word8 \<Rightarrow> ARM_Structs_A.pte "
where
"pt1_3077 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPTE)"
definition
obj1_3077 :: Structures_A.kernel_object
where
"obj1_3077 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageTable pt1_3077)"
definition
pd1_3065 :: "12 word \<Rightarrow> ARM_Structs_A.pde "
where
"pd1_3065 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPDE)
(0 := ARM_Structs_A.PageTablePDE
(Platform.addrFromPPtr 3077)
undefined
undefined )"
(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check
if it's right *)
definition
obj1_3065 :: Structures_A.kernel_object
where
"obj1_3065 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageDirectory pd1_3065)"
text {* UT1's tcb *}
definition
obj1_3079 :: Structures_A.kernel_object
where
"obj1_3079 \<equiv>
Structures_A.TCB \<lparr>
tcb_ctable = Structures_A.CNodeCap 6 undefined undefined ,
tcb_vtable = Structures_A.ArchObjectCap
(ARM_Structs_A.PageDirectoryCap 3063 (Some asid1_3063)),
tcb_reply = Structures_A.ReplyCap 3079 True, (* master reply cap to itself *)
tcb_caller = Structures_A.NullCap,
tcb_ipcframe = Structures_A.NullCap,
tcb_state = Structures_A.Running,
tcb_fault_handler = undefined,
tcb_ipc_buffer = undefined,
tcb_context = undefined,
tcb_fault = undefined \<rparr>"
text {* T1's tcb *}
definition
obj1_3080 :: Structures_A.kernel_object
where
"obj1_3080 \<equiv>
Structures_A.TCB \<lparr>
tcb_ctable = Structures_A.CNodeCap 7 undefined undefined ,
tcb_vtable = Structures_A.ArchObjectCap
(ARM_Structs_A.PageDirectoryCap 3065 (Some asid1_3065)),
tcb_reply = Structures_A.ReplyCap 3080 True, (* master reply cap to itself *)
tcb_caller = Structures_A.NullCap,
tcb_ipcframe = Structures_A.NullCap,
tcb_state = Structures_A.BlockedOnReceive 9 True,
tcb_fault_handler = undefined,
tcb_ipc_buffer = undefined,
tcb_context = undefined,
tcb_fault = undefined \<rparr>"
definition
"obj1_10 \<equiv> Structures_A.CNode 10 (Map.empty([] \<mapsto> cap.NullCap))"
(* the boolean in BlockedOnReceive is True if the object can receive but not send.
but Tom says it only matters if the sender can grant - which is not the case of the UT1 - I think *)
definition
kh1 :: kheap
where
"kh1 \<equiv> [ 6 \<mapsto> obj1_6,
7 \<mapsto> obj1_7,
9 \<mapsto> obj1_9,
10 \<mapsto> obj1_10,
3063 \<mapsto> obj1_3063,
3065 \<mapsto> obj1_3065,
3072 \<mapsto> obj1_3072,
3077 \<mapsto> obj1_3077,
3079 \<mapsto> obj1_3079,
3080 \<mapsto> obj1_3080 ]"
lemmas kh1_obj_def =
obj1_6_def obj1_7_def obj1_9_def obj1_10_def obj1_3063_def obj1_3065_def
obj1_3072_def obj1_3077_def obj1_3079_def obj1_3080_def
definition exst1 :: "det_ext" where
"exst1 \<equiv> \<lparr>work_units_completed_internal = undefined,
scheduler_action_internal = undefined,
ekheap_internal = \<lambda>x. None,
domain_list_internal = undefined,
domain_index_internal = undefined,
cur_domain_internal = undefined,
domain_time_internal = undefined,
ready_queues_internal = undefined,
cdt_list_internal = undefined\<rparr>"
definition
s1 :: "det_ext state"
where
"s1 \<equiv> \<lparr>
kheap = kh1,
cdt = empty,
is_original_cap = undefined,
cur_thread = undefined,
idle_thread = undefined,
machine_state = undefined,
interrupt_irq_node = (\<lambda>_. 10),
interrupt_states = undefined,
arch_state = \<lparr>
arm_globals_frame = undefined,
arm_asid_table = (\<lambda> x. None),
arm_hwasid_table = undefined,
arm_next_asid = undefined,
arm_asid_map = undefined,
arm_global_pd = undefined,
arm_global_pts = undefined,
arm_kernel_vspace = undefined
\<rparr>,
exst = exst1
\<rparr>"
subsubsection {* Defining the policy graph *}
datatype Sys1Labels =
UT1 | T1 | EP1 | IRQ1
definition
Sys1AgentMap :: "Sys1Labels agent_map"
where
"Sys1AgentMap \<equiv>
(\<lambda>_. undefined)
(6 := UT1,
7 := T1,
9 := EP1,
10 := IRQ1,
3063 := UT1,
3065 := T1,
3072 := UT1,
3077 := T1,
3079 := UT1,
3080 := T1 )"
lemma Sys1AgentMap_simps:
"Sys1AgentMap 6 = UT1"
"Sys1AgentMap 7 = T1"
"Sys1AgentMap 9 = EP1"
"Sys1AgentMap 10 = IRQ1"
"Sys1AgentMap 3063 = UT1"
"Sys1AgentMap 3065 = T1"
"Sys1AgentMap 3072 = UT1"
"Sys1AgentMap 3077 = T1"
"Sys1AgentMap 3079 = UT1"
"Sys1AgentMap 3080 = T1"
unfolding Sys1AgentMap_def by simp_all
definition
Sys1AuthGraph_aux :: "Sys1Labels auth_graph"
where
"Sys1AuthGraph_aux \<equiv>
{ (UT1, auth.SyncSend, EP1),
(UT1, auth.Reset, EP1),
(T1, auth.Receive, EP1),
(T1, auth.Reset, EP1) }"
definition
Sys1AuthGraph:: "Sys1Labels auth_graph"
where
"Sys1AuthGraph \<equiv> complete_AuthGraph Sys1AuthGraph_aux {T1, UT1}"
definition
Sys1ASIDMap :: "Sys1Labels agent_asid_map"
where
"Sys1ASIDMap \<equiv>
(\<lambda>x. if (asid_high_bits_of x = asid_high_bits_of asid1_3063)
then UT1
else if (asid_high_bits_of x = asid_high_bits_of asid1_3065)
then T1 else undefined)"
definition Sys1PAS :: "Sys1Labels PAS" where
"Sys1PAS \<equiv> \<lparr> pasObjectAbs = Sys1AgentMap, pasASIDAbs = Sys1ASIDMap, pasIRQAbs = (\<lambda>_. IRQ1),
pasPolicy = Sys1AuthGraph, pasSubject = UT1, pasMayActivate = True, pasMayEditReadyQueues = True, pasMaySendIrqs = True, pasDomainAbs = undefined \<rparr>"
subsubsection {* Proof of pas_refined for Sys1 *}
lemma caps1_7_well_formed: "well_formed_cnode_n 10 caps1_7"
apply (clarsimp simp: caps1_7_def well_formed_cnode_n_def)
apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)
apply (clarsimp simp: empty_cnode_def dom_def)
apply (rule set_eqI, clarsimp)
apply (rule iffI)
apply (elim disjE, insert len_bin_to_bl, simp_all)[1]
apply clarsimp
done
lemma caps1_6_well_formed: "well_formed_cnode_n 10 caps1_6"
apply (clarsimp simp: caps1_6_def well_formed_cnode_n_def)
apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)
apply (clarsimp simp: empty_cnode_def dom_def)
apply (rule set_eqI, clarsimp)
apply (rule iffI)
apply (elim disjE, insert len_bin_to_bl, simp_all)[1]
apply clarsimp
done
(* clagged from KernelInit_R *)
lemma empty_cnode_apply[simp]:
"(empty_cnode n xs = Some cap) = (length xs = n \<and> cap = Structures_A.NullCap)"
by (auto simp add: empty_cnode_def)
lemma s1_caps_of_state :
"caps_of_state s1 p = Some cap \<Longrightarrow>
cap = Structures_A.NullCap \<or>
(p,cap) \<in>
{ ((6::obj_ref,(the_nat_to_bl_10 1)), Structures_A.ThreadCap 3079),
((6::obj_ref,(the_nat_to_bl_10 2)), Structures_A.CNodeCap 6 undefined undefined),
((6::obj_ref,(the_nat_to_bl_10 3)), Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3063 (Some asid1_3063))),
((6::obj_ref,(the_nat_to_bl_10 318)),Structures_A.EndpointCap 9 0 {AllowSend}),
((7::obj_ref,(the_nat_to_bl_10 1)), Structures_A.ThreadCap 3080),
((7::obj_ref,(the_nat_to_bl_10 2)), Structures_A.CNodeCap 7 undefined undefined),
((7::obj_ref,(the_nat_to_bl_10 3)), Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3065 (Some asid1_3065))),
((7::obj_ref,(the_nat_to_bl_10 318)),Structures_A.EndpointCap 9 0 {AllowRecv}) ,
((3079::obj_ref, (tcb_cnode_index 0)), Structures_A.CNodeCap 6 undefined undefined ),
((3079::obj_ref, (tcb_cnode_index 1)), Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3063 (Some asid1_3063))),
((3079::obj_ref, (tcb_cnode_index 2)), Structures_A.ReplyCap 3079 True),
((3079::obj_ref, (tcb_cnode_index 3)), Structures_A.NullCap),
((3079::obj_ref, (tcb_cnode_index 4)), Structures_A.NullCap),
((3080::obj_ref, (tcb_cnode_index 0)), Structures_A.CNodeCap 7 undefined undefined ),
((3080::obj_ref, (tcb_cnode_index 1)), Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3065 (Some asid1_3065))),
((3080::obj_ref, (tcb_cnode_index 2)), Structures_A.ReplyCap 3080 True),
((3080::obj_ref, (tcb_cnode_index 3)), Structures_A.NullCap),
((3080::obj_ref, (tcb_cnode_index 4)), Structures_A.NullCap)} "
apply (insert caps1_7_well_formed)
apply (insert caps1_6_well_formed)
apply (simp add: caps_of_state_cte_wp_at cte_wp_at_cases s1_def kh1_def kh1_obj_def)
apply (case_tac p, clarsimp)
apply (clarsimp split: if_splits)
apply (clarsimp simp: cte_wp_at_cases tcb_cap_cases_def
split: split_if_asm)+
apply (clarsimp simp: caps1_7_def split: if_splits)
apply (clarsimp simp: caps1_6_def cte_wp_at_cases split: if_splits)
done
lemma Sys1_wellformed: "pas_wellformed Sys1PAS"
apply (clarsimp simp: Sys1PAS_def
policy_wellformed_def
Sys1AuthGraph_def
Sys1AuthGraph_aux_def
complete_AuthGraph_def)
apply blast
done
lemma tcb_states_of_state_1:
"tcb_states_of_state s1 = [0xC08 \<mapsto> Structures_A.thread_state.BlockedOnReceive 9 True, 0xC07 \<mapsto> Structures_A.thread_state.Running ]"
unfolding s1_def tcb_states_of_state_def
apply (rule ext)
apply (simp add: get_tcb_def)
apply (simp add: kh1_def kh1_obj_def )
done
declare AllowSend_def[simp] AllowRecv_def[simp]
lemma domains_of_state_s1[simp]:
"domains_of_state s1 = {}"
apply(rule equalityI)
apply(rule subsetI)
apply clarsimp
apply(erule domains_of_state_aux.induct)
apply(simp add: s1_def exst1_def)
apply simp
done
lemma "pas_refined Sys1PAS s1"
apply (clarsimp simp: pas_refined_def)
apply (intro conjI)
apply (simp add: Sys1_wellformed)
apply (simp add: irq_map_wellformed_aux_def s1_def Sys1AgentMap_simps Sys1PAS_def)
apply (clarsimp simp: auth_graph_map_def
Sys1PAS_def
state_objs_to_policy_def
state_bits_to_policy_def tcb_domain_map_wellformed_aux_def
)+
apply (erule state_bits_to_policyp.cases, simp_all, clarsimp)
apply (drule s1_caps_of_state, clarsimp)
apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def)
apply (elim disjE conjE, auto simp: Sys1AgentMap_simps cap_auth_conferred_def cap_rights_to_auth_def)[1]
apply (drule s1_caps_of_state, clarsimp)
apply (elim disjE, simp_all)[1]
apply (clarsimp simp: state_refs_of_def thread_states_def tcb_states_of_state_1
Sys1AuthGraph_def Sys1AgentMap_simps
complete_AuthGraph_def
Sys1AuthGraph_aux_def
split: if_splits)
apply (simp add: s1_def) (* this is OK because cdt is empty..*)
apply (clarsimp simp: state_vrefs_def
vs_refs_no_global_pts_def
s1_def kh1_def Sys1AgentMap_simps
kh1_obj_def comp_def pt1_3072_def pt1_3077_def pte_ref_def pde_ref2_def pd1_3065_def pd1_3063_def
Sys1AuthGraph_def ptr_range_def
complete_AuthGraph_def
Sys1AuthGraph_aux_def
dest!: graph_ofD
split: if_splits)
apply (rule subsetI, clarsimp)
apply (erule state_asids_to_policy_aux.cases)
apply clarsimp
apply (drule s1_caps_of_state, clarsimp)
apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def Sys1PAS_def Sys1ASIDMap_def)
apply (elim disjE conjE, simp_all add: Sys1AgentMap_simps cap_auth_conferred_def cap_rights_to_auth_def asid1_3065_def asid1_3063_def
asid_low_bits_def asid_high_bits_of_def )[1]
apply (clarsimp simp: state_vrefs_def
vs_refs_no_global_pts_def
s1_def kh1_def Sys1AgentMap_simps
kh1_obj_def comp_def pt1_3072_def pt1_3077_def pte_ref_def pde_ref2_def pd1_3065_def pd1_3063_def
Sys1AuthGraph_def ptr_range_def
complete_AuthGraph_def
Sys1AuthGraph_aux_def
dest!: graph_ofD
split: if_splits)
apply (clarsimp simp: s1_def)
apply (rule subsetI, clarsimp)
apply (erule state_irqs_to_policy_aux.cases)
apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def Sys1PAS_def Sys1ASIDMap_def)
apply (drule s1_caps_of_state)
apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def Sys1PAS_def Sys1ASIDMap_def)
apply (elim disjE conjE, simp_all add: Sys1AgentMap_simps cap_auth_conferred_def cap_rights_to_auth_def asid1_3065_def asid1_3063_def
asid_low_bits_def asid_high_bits_of_def )[1]
done
(*---------------------------------------------------------*)
subsection {* Example 2 *}
text {*
This example systems Sys2 aims at checking that we can have 2
components, one untrusted UT2 and one truted T1, sharing a cnode obj2_5.
Both UT2 and T2 contains:
. one TCB (obj2_3079 and obj2_3080 resp.)
. one vspace made up of one page directory (obj2_6063 and obj2_3065 resp.)
. each pd contains a single page table (obj2_3072 and obj2_3077 resp.)
. one cspace made up of one cnode (obj2_6 and obj2_7 resp.)
. each cspace contains 4 caps:
one to the tcb
one to the cnode itself
one to the vspace
one to obj2_5
Attempt to ASCII art:
-------- ---- ---- --------
| | | | | | | |
V | | V S R | V | V
obj2_3079(tcb)-->obj2_6(cnode)--->obj2_5(cnode)<---obj2_7(cnode)<--obj2_3080(tcb)
| | | |
V | | V
obj2_3063(pd)<----- -------> obj2_3065(pd)
| |
V V
obj2_3072(pt) obj2_3077(pt)
(the references are derived from the dump of the SAC system)
The aim is to be able to prove
pas_refined Sys2PAS s2
where Sys2PAS is the label graph defining the AC policy for Sys2 and
s2 is the state of Sys2 described above.
This shows that the aag extracted from s2 (by state_objs_to_policy) is
included in the policy graph Sys2PAS.
*}
subsubsection {* Defining the State *}
text {* We need to define the asids of each pd and pt to ensure that
the object is included in the right ASID-label *}
text {* UT2's ASID *}
definition
asid2_3063 :: machine_word
where
"asid2_3063 \<equiv> 1<<asid_low_bits"
text {* T2's ASID *}
definition
asid2_3065 :: machine_word
where
"asid2_3065 \<equiv> 2<<asid_low_bits"
lemma "asid_high_bits_of asid2_3065 \<noteq> asid_high_bits_of asid2_3063"
by (simp add: asid2_3063_def asid_high_bits_of_def asid2_3065_def asid_low_bits_def)
text {* the intermediaite CSpace *}
definition
caps2_5 :: Structures_A.cnode_contents
where
"caps2_5 \<equiv>
(empty_cnode 10)"
definition
obj2_5 :: Structures_A.kernel_object
where
"obj2_5 \<equiv> Structures_A.CNode 10 caps2_5"
text {* UT2's CSpace *}
definition
caps2_6 :: Structures_A.cnode_contents
where
"caps2_6 \<equiv>
(empty_cnode 10)
( (the_nat_to_bl_10 1)
\<mapsto> Structures_A.ThreadCap 3079,
(the_nat_to_bl_10 2)
\<mapsto> Structures_A.CNodeCap 6 undefined undefined,
(the_nat_to_bl_10 3)
\<mapsto> Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3063
(Some asid2_3063)),
(the_nat_to_bl_10 4)
\<mapsto> Structures_A.CNodeCap 5 undefined undefined )"
definition
obj2_6 :: Structures_A.kernel_object
where
"obj2_6 \<equiv> Structures_A.CNode 10 caps2_6"
text {* T2's Cspace *}
definition
caps2_7 :: Structures_A.cnode_contents
where
"caps2_7 \<equiv>
(empty_cnode 10)
( (the_nat_to_bl_10 1)
\<mapsto> Structures_A.ThreadCap 3080,
(the_nat_to_bl_10 2)
\<mapsto> Structures_A.CNodeCap 7 undefined undefined,
(the_nat_to_bl_10 3)
\<mapsto> Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3065
(Some asid2_3065)),
(the_nat_to_bl_10 4)
\<mapsto> Structures_A.CNodeCap 5 undefined undefined) "
definition
obj2_7 :: Structures_A.kernel_object
where
"obj2_7 \<equiv> Structures_A.CNode 10 caps2_7"
text {* endpoint between UT2 and T2 *}
definition
obj2_9 :: Structures_A.kernel_object
where
"obj2_9 \<equiv> Structures_A.Endpoint Structures_A.IdleEP"
text {* UT2's VSpace (PageDirectory)*}
definition
pt2_3072 :: "word8 \<Rightarrow> ARM_Structs_A.pte "
where
"pt2_3072 \<equiv> (\<lambda>_. ARM_Structs_A.InvalidPTE)"
definition
obj2_3072 :: Structures_A.kernel_object
where
"obj2_3072 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageTable pt2_3072)"
definition
pd2_3063 :: "12 word \<Rightarrow> ARM_Structs_A.pde "
where
"pd2_3063 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPDE)
(0 := ARM_Structs_A.PageTablePDE
(Platform.addrFromPPtr 3072)
undefined
undefined )"
(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check
if it's right *)
definition
obj2_3063 :: Structures_A.kernel_object
where
"obj2_3063 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageDirectory pd2_3063)"
text {* T1's VSpace (PageDirectory)*}
definition
pt2_3077 :: "word8 \<Rightarrow> ARM_Structs_A.pte "
where
"pt2_3077 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPTE)"
definition
obj2_3077 :: Structures_A.kernel_object
where
"obj2_3077 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageTable pt2_3077)"
definition
pd2_3065 :: "12 word \<Rightarrow> ARM_Structs_A.pde "
where
"pd2_3065 \<equiv>
(\<lambda>_. ARM_Structs_A.InvalidPDE)
(0 := ARM_Structs_A.PageTablePDE
(Platform.addrFromPPtr 3077)
undefined
undefined )"
(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check
if it's right *)
definition
obj2_3065 :: Structures_A.kernel_object
where
"obj2_3065 \<equiv> Structures_A.ArchObj (ARM_Structs_A.PageDirectory pd2_3065)"
text {* UT1's tcb *}
definition
obj2_3079 :: Structures_A.kernel_object
where
"obj2_3079 \<equiv>
Structures_A.TCB \<lparr>
tcb_ctable = Structures_A.CNodeCap 6 undefined undefined ,
tcb_vtable = Structures_A.ArchObjectCap
(ARM_Structs_A.PageDirectoryCap 3063 (Some asid2_3063)),
tcb_reply = Structures_A.ReplyCap 3079 True, (* master reply cap to itself *)
tcb_caller = Structures_A.NullCap,
tcb_ipcframe = Structures_A.NullCap,
tcb_state = Structures_A.Running,
tcb_fault_handler = undefined,
tcb_ipc_buffer = undefined,
tcb_context = undefined,
tcb_fault = undefined \<rparr>"
text {* T1's tcb *}
definition
obj2_3080 :: Structures_A.kernel_object
where
"obj2_3080 \<equiv>
Structures_A.TCB \<lparr>
tcb_ctable = Structures_A.CNodeCap 7 undefined undefined ,
tcb_vtable = Structures_A.ArchObjectCap
(ARM_Structs_A.PageDirectoryCap 3065 (Some asid2_3065)),
tcb_reply = Structures_A.ReplyCap 3080 True, (* master reply cap to itself *)
tcb_caller = Structures_A.NullCap,
tcb_ipcframe = Structures_A.NullCap,
tcb_state = Structures_A.BlockedOnReceive 9 True,
tcb_fault_handler = undefined,
tcb_ipc_buffer = undefined,
tcb_context = undefined,
tcb_fault = undefined \<rparr>"
(* the boolean in BlockedOnReceive is True if the object can receive but not send.
but Tom says it only matters if the sender can grant - which is not the case of the UT1 - I think *)
definition
kh2 :: kheap
where
"kh2 \<equiv> [ 6 \<mapsto> obj2_6,
7 \<mapsto> obj2_7,
9 \<mapsto> obj2_9,
3063 \<mapsto> obj2_3063,
3065 \<mapsto> obj2_3065,
3072 \<mapsto> obj2_3072,
3077 \<mapsto> obj2_3077,
3079 \<mapsto> obj2_3079,
3080 \<mapsto> obj2_3080 ]"
lemmas kh2_obj_def =
obj2_6_def obj2_7_def obj2_9_def obj2_3063_def obj2_3065_def
obj2_3072_def obj2_3077_def obj2_3079_def obj2_3080_def
definition
s2 :: "det_ext state"
where
"s2 \<equiv> \<lparr>
kheap = kh2,
cdt = empty,
is_original_cap = undefined,
cur_thread = undefined,
idle_thread = undefined,
machine_state = undefined,
interrupt_irq_node = (\<lambda>_. 9001),
interrupt_states = undefined,
arch_state = \<lparr>
arm_globals_frame = undefined,
arm_asid_table = (\<lambda> x. None),
arm_hwasid_table = undefined,
arm_next_asid = undefined,
arm_asid_map = undefined,
arm_global_pd = undefined,
arm_global_pts = undefined,
arm_kernel_vspace = undefined
\<rparr>,
exst = exst1
\<rparr>"
subsubsection {* Defining the policy graph *}
datatype Sys2Labels =
UT2 | T2 | IRQ2
definition
Sys2AgentMap :: "Sys2Labels agent_map"
where
"Sys2AgentMap \<equiv>
(\<lambda>_. undefined)
(5 := UT2,
6 := UT2,
7 := T2,
9 := T2,
3063 := UT2,
3065 := T2,
3072 := UT2,
3077 := T2,
3079 := UT2,
3080 := T2,
9001 := IRQ2 )"
definition
Sys2AuthGraph_aux :: "Sys2Labels auth_graph"
where
"Sys2AuthGraph_aux \<equiv>
{ (T2, Control, UT2) }"
definition
Sys2AuthGraph:: "Sys2Labels auth_graph"
where
"Sys2AuthGraph \<equiv> complete_AuthGraph Sys2AuthGraph_aux {T2, UT2}"
definition
Sys2ASIDMap :: "Sys2Labels agent_asid_map"
where
"Sys2ASIDMap \<equiv>
(\<lambda>_. undefined)
(asid2_3063 := UT2,
asid2_3065 := T2 )"
definition Sys2PAS :: "Sys2Labels PAS" where
"Sys2PAS \<equiv> \<lparr> pasObjectAbs = Sys2AgentMap, pasASIDAbs = Sys2ASIDMap,
pasIRQAbs = (\<lambda>_. IRQ2),
pasPolicy = Sys2AuthGraph, pasSubject = UT2, pasMayActivate = True, pasMayEditReadyQueues = True, pasMaySendIrqs = True, pasDomainAbs = undefined \<rparr>"
subsubsection {* Proof of pas_refined for Sys2 *}
lemma caps2_7_well_formed: "well_formed_cnode_n 10 caps2_7"
apply (clarsimp simp: caps2_7_def well_formed_cnode_n_def)
apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)
apply (clarsimp simp: empty_cnode_def dom_def)
apply (rule set_eqI, clarsimp)
apply (rule iffI)
apply (elim disjE, insert len_bin_to_bl, simp_all)[1]
apply clarsimp
done
lemma caps2_6_well_formed: "well_formed_cnode_n 10 caps2_6"
apply (clarsimp simp: caps2_6_def well_formed_cnode_n_def)
apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)
apply (clarsimp simp: empty_cnode_def dom_def)
apply (rule set_eqI, clarsimp)
apply (rule iffI)
apply (elim disjE, insert len_bin_to_bl, simp_all)[1]
apply clarsimp
done
lemma s2_caps_of_state :
"caps_of_state s2 p = Some cap \<Longrightarrow>
cap = Structures_A.NullCap \<or>
(p,cap) \<in>
{ ((6::obj_ref,(the_nat_to_bl_10 1)), Structures_A.ThreadCap 3079),
((6::obj_ref,(the_nat_to_bl_10 2)), Structures_A.CNodeCap 6 undefined undefined),
((6::obj_ref,(the_nat_to_bl_10 3)), Structures_A.ArchObjectCap (ARM_Structs_A.PageDirectoryCap 3063 (Some asid2_3063))),
((6::obj_ref,(the_nat_to_bl_10 4)), Structures_A.CNodeCap 5 undefined undefined),
((7::obj_ref,(the_nat_to_bl_10 1)), Structures_A.ThreadCap 3080),