Dynamic_static.thy
author chunhan
Thu, 24 Oct 2013 09:41:33 +0800
changeset 63 051b0ee98852
child 65 6f9a588bcfc4
permissions -rw-r--r--
restructured
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
051b0ee98852 restructured
chunhan
parents:
diff changeset
     1
theory Dynamic_static
051b0ee98852 restructured
chunhan
parents:
diff changeset
     2
imports Main Flask Static Init_prop Valid_prop Tainted_prop Delete_prop Co2sobj_prop S2ss_prop S2ss_prop2
051b0ee98852 restructured
chunhan
parents:
diff changeset
     3
begin
051b0ee98852 restructured
chunhan
parents:
diff changeset
     4
051b0ee98852 restructured
chunhan
parents:
diff changeset
     5
context tainting_s begin
051b0ee98852 restructured
chunhan
parents:
diff changeset
     6
051b0ee98852 restructured
chunhan
parents:
diff changeset
     7
definition init_ss_eq:: "t_static_state \<Rightarrow> t_static_state \<Rightarrow> bool" (infix "\<doteq>" 100)
051b0ee98852 restructured
chunhan
parents:
diff changeset
     8
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
     9
  "ss \<doteq> ss' \<equiv> ss \<subseteq> ss' \<and> {sobj. is_init_sobj sobj \<and> sobj \<in> ss'} \<subseteq> ss"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    10
051b0ee98852 restructured
chunhan
parents:
diff changeset
    11
lemma [simp]: "ss \<doteq> ss"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    12
by (auto simp:init_ss_eq_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    13
051b0ee98852 restructured
chunhan
parents:
diff changeset
    14
definition init_ss_in:: "t_static_state \<Rightarrow> t_static_state set \<Rightarrow> bool" (infix "\<propto>" 101)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    15
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    16
  "ss \<propto> sss \<equiv> \<exists> ss' \<in> sss. ss \<doteq> ss'"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    17
051b0ee98852 restructured
chunhan
parents:
diff changeset
    18
lemma s2ss_included_sobj:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    19
  "\<lbrakk>alive s obj; co2sobj s obj= Some sobj\<rbrakk> \<Longrightarrow> sobj \<in> (s2ss s)"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    20
by (simp add:s2ss_def, rule_tac x = obj in exI, simp)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    21
051b0ee98852 restructured
chunhan
parents:
diff changeset
    22
lemma init_ss_in_prop:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    23
  "\<lbrakk>s2ss s \<propto> static; co2sobj s obj = Some sobj; alive s obj; init_obj_related sobj obj\<rbrakk>
051b0ee98852 restructured
chunhan
parents:
diff changeset
    24
   \<Longrightarrow> \<exists> ss \<in> static. sobj \<in> ss"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    25
apply (simp add:init_ss_in_def init_ss_eq_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    26
apply (erule bexE, erule conjE)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    27
apply (rule_tac x = ss' in bexI, auto dest!:s2ss_included_sobj)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    28
done
051b0ee98852 restructured
chunhan
parents:
diff changeset
    29
051b0ee98852 restructured
chunhan
parents:
diff changeset
    30
051b0ee98852 restructured
chunhan
parents:
diff changeset
    31
051b0ee98852 restructured
chunhan
parents:
diff changeset
    32
051b0ee98852 restructured
chunhan
parents:
diff changeset
    33
051b0ee98852 restructured
chunhan
parents:
diff changeset
    34
definition enrich:: "t_state \<Rightarrow> t_object set \<Rightarrow> t_state \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    35
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    36
  "enrich s objs s' \<equiv> \<forall> obj \<in> objs. \<exists> obj'. obj' \<notin> objs \<and> alive s' obj \<and> co2sobj s' obj' = co2sobj s' obj"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    37
051b0ee98852 restructured
chunhan
parents:
diff changeset
    38
definition reserve:: "t_state \<Rightarrow> t_object set \<Rightarrow> t_state \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    39
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    40
  "reserve s objs s' \<equiv> \<forall> obj. alive s obj \<longrightarrow> alive s' obj \<and> co2sobj s' obj = co2sobj s obj"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    41
051b0ee98852 restructured
chunhan
parents:
diff changeset
    42
definition enrichable :: "t_state \<Rightarrow> t_object set \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    43
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    44
  "enrichable s objs \<equiv> \<exists> s'. valid s' \<and> s2ss s' = s2ss s \<and> enrich s objs s' \<and> reserve s objs s'"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    45
051b0ee98852 restructured
chunhan
parents:
diff changeset
    46
definition is_created :: "t_state \<Rightarrow> t_object \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    47
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    48
  "is_created s obj \<equiv> init_alive obj \<longrightarrow> deleted obj s"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    49
051b0ee98852 restructured
chunhan
parents:
diff changeset
    50
definition is_inited :: "t_state \<Rightarrow> t_object \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    51
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    52
  "is_inited s obj \<equiv> init_alive obj \<and> \<not> deleted obj s"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    53
051b0ee98852 restructured
chunhan
parents:
diff changeset
    54
lemma is_inited_eq_not_created:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    55
  "is_inited s obj = (\<not> is_created s obj)"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    56
by (auto simp:is_created_def is_inited_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    57
051b0ee98852 restructured
chunhan
parents:
diff changeset
    58
(* recorded in our static world *)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    59
fun recorded :: "t_object \<Rightarrow> bool"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    60
where
051b0ee98852 restructured
chunhan
parents:
diff changeset
    61
  "recorded (O_proc p)     = True"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    62
| "recorded (O_file f)     = True"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    63
| "recorded (O_dir  f)     = True"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    64
| "recorded (O_node n)     = False" (* cause socket is temperary not considered *)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    65
| "recorded (O_shm  h)     = True"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    66
| "recorded (O_msgq q)     = True"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    67
| "recorded _              = False"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    68
051b0ee98852 restructured
chunhan
parents:
diff changeset
    69
051b0ee98852 restructured
chunhan
parents:
diff changeset
    70
051b0ee98852 restructured
chunhan
parents:
diff changeset
    71
051b0ee98852 restructured
chunhan
parents:
diff changeset
    72
051b0ee98852 restructured
chunhan
parents:
diff changeset
    73
051b0ee98852 restructured
chunhan
parents:
diff changeset
    74
lemma d2s_main_execve:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    75
  "valid (Execve p f fds # s) \<Longrightarrow> s2ss (Execve p f fds # s) \<in> static"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    76
apply (frule vd_cons, frule vt_grant_os, clarsimp simp:s2ss_execve)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    77
sorry
051b0ee98852 restructured
chunhan
parents:
diff changeset
    78
051b0ee98852 restructured
chunhan
parents:
diff changeset
    79
lemma d2s_main:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    80
  "valid s \<Longrightarrow> s2ss s \<propto> static"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    81
apply (induct s, simp add:s2ss_nil_prop init_ss_in_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    82
apply (rule_tac x = "init_static_state" in bexI, simp, simp add:s_init)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    83
apply (frule vd_cons, frule vt_grant_os, simp)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    84
apply (case_tac a) 
051b0ee98852 restructured
chunhan
parents:
diff changeset
    85
apply (clarsimp simp add:s2ss_execve)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    86
apply (rule conjI, rule impI)
051b0ee98852 restructured
chunhan
parents:
diff changeset
    87
051b0ee98852 restructured
chunhan
parents:
diff changeset
    88
051b0ee98852 restructured
chunhan
parents:
diff changeset
    89
051b0ee98852 restructured
chunhan
parents:
diff changeset
    90
sorry
051b0ee98852 restructured
chunhan
parents:
diff changeset
    91
051b0ee98852 restructured
chunhan
parents:
diff changeset
    92
051b0ee98852 restructured
chunhan
parents:
diff changeset
    93
lemma many_sq_imp_sms:
051b0ee98852 restructured
chunhan
parents:
diff changeset
    94
  "\<lbrakk>S_msgq (Create, sec, sms) \<in> ss; ss \<in> static\<rbrakk> \<Longrightarrow> \<forall> sm \<in> (set sms). is_many_smsg sm"
051b0ee98852 restructured
chunhan
parents:
diff changeset
    95
sorry
051b0ee98852 restructured
chunhan
parents:
diff changeset
    96
051b0ee98852 restructured
chunhan
parents:
diff changeset
    97
051b0ee98852 restructured
chunhan
parents:
diff changeset
    98
051b0ee98852 restructured
chunhan
parents:
diff changeset
    99
lemma enrichability: 
051b0ee98852 restructured
chunhan
parents:
diff changeset
   100
  "\<lbrakk>valid s; \<forall> obj \<in> objs. alive s obj \<and> is_created s obj \<and> recorded obj\<rbrakk>
051b0ee98852 restructured
chunhan
parents:
diff changeset
   101
   \<Longrightarrow> enrichable s objs"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   102
proof (induct s arbitrary:objs)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   103
  case Nil
051b0ee98852 restructured
chunhan
parents:
diff changeset
   104
  hence "objs = {}" 
051b0ee98852 restructured
chunhan
parents:
diff changeset
   105
    apply (auto simp:is_created_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   106
    apply (erule_tac x = x in ballE)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   107
    apply (auto simp:init_alive_prop)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   108
    done
051b0ee98852 restructured
chunhan
parents:
diff changeset
   109
  thus ?case using Nil unfolding enrichable_def enrich_def reserve_def
051b0ee98852 restructured
chunhan
parents:
diff changeset
   110
    by (rule_tac x = "[]" in exI, auto)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   111
next
051b0ee98852 restructured
chunhan
parents:
diff changeset
   112
  case (Cons e s)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   113
  hence p1: "\<And> objs. \<forall> obj \<in> objs. alive s obj \<and> is_created s obj \<and> recorded obj \<Longrightarrow> enrichable s objs"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   114
    and p2: "valid (e # s)" and p3: "\<forall>obj\<in>objs. alive (e # s) obj \<and> is_created (e # s) obj \<and> recorded obj"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   115
    and os: "os_grant s e" and se: "grant s e" and vd: "valid s"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   116
    by (auto dest:vt_grant_os vd_cons vt_grant)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   117
  show ?case sorry (*
051b0ee98852 restructured
chunhan
parents:
diff changeset
   118
  proof (cases e)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   119
    case (Execve p f fds)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   120
    hence p4: "e = Execve p f fds" by simp
051b0ee98852 restructured
chunhan
parents:
diff changeset
   121
    from p3 have p5: "is_inited s (O_proc p) \<Longrightarrow> (O_proc p) \<notin> objs"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   122
      by (auto simp:is_created_def is_inited_def p4 elim!:ballE[where x = "O_proc p"])
051b0ee98852 restructured
chunhan
parents:
diff changeset
   123
    show "enrichable (e # s) objs"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   124
    proof (case "is_inited s (O_proc p)")
051b0ee98852 restructured
chunhan
parents:
diff changeset
   125
      apply (simp add:enrichable_def p4)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   126
051b0ee98852 restructured
chunhan
parents:
diff changeset
   127
      
051b0ee98852 restructured
chunhan
parents:
diff changeset
   128
  
051b0ee98852 restructured
chunhan
parents:
diff changeset
   129
    apply auto
051b0ee98852 restructured
chunhan
parents:
diff changeset
   130
    apply (auto simp:enrichable_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   131
apply (induct s)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   132
051b0ee98852 restructured
chunhan
parents:
diff changeset
   133
051b0ee98852 restructured
chunhan
parents:
diff changeset
   134
051b0ee98852 restructured
chunhan
parents:
diff changeset
   135
done
051b0ee98852 restructured
chunhan
parents:
diff changeset
   136
*)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   137
qed
051b0ee98852 restructured
chunhan
parents:
diff changeset
   138
051b0ee98852 restructured
chunhan
parents:
diff changeset
   139
lemma s2d_main:
051b0ee98852 restructured
chunhan
parents:
diff changeset
   140
  "ss \<in> static \<Longrightarrow> \<exists> s. valid s \<and> s2ss s = ss"
051b0ee98852 restructured
chunhan
parents:
diff changeset
   141
apply (erule static.induct)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   142
apply (rule_tac x = "[]" in exI, simp add:s2ss_nil_prop valid.intros)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   143
051b0ee98852 restructured
chunhan
parents:
diff changeset
   144
apply (erule exE|erule conjE)+
051b0ee98852 restructured
chunhan
parents:
diff changeset
   145
051b0ee98852 restructured
chunhan
parents:
diff changeset
   146
apply (simp add:update_ss_def)
051b0ee98852 restructured
chunhan
parents:
diff changeset
   147
051b0ee98852 restructured
chunhan
parents:
diff changeset
   148
sorry
051b0ee98852 restructured
chunhan
parents:
diff changeset
   149
051b0ee98852 restructured
chunhan
parents:
diff changeset
   150
051b0ee98852 restructured
chunhan
parents:
diff changeset
   151
end
051b0ee98852 restructured
chunhan
parents:
diff changeset
   152
051b0ee98852 restructured
chunhan
parents:
diff changeset
   153
end