1
+ − 1
theory Dynamic2static
61
+ − 2
imports Main Flask Static Init_prop Valid_prop Tainted_prop Delete_prop Co2sobj_prop S2ss_prop S2ss_prop2
1
+ − 3
begin
+ − 4
+ − 5
context tainting_s begin
+ − 6
61
+ − 7
lemma many_sq_imp_sms:
+ − 8
"\<lbrakk>S_msgq (Create, sec, sms) \<in> ss; ss \<in> static\<rbrakk> \<Longrightarrow> \<forall> sm \<in> (set sms). is_many_smsg sm"
+ − 9
sorry
+ − 10
+ − 11
definition init_ss_eq:: "t_static_state \<Rightarrow> t_static_state \<Rightarrow> bool" (infix "\<doteq>" 100)
+ − 12
where
+ − 13
"ss \<doteq> ss' \<equiv> ss \<subseteq> ss' \<and> {sobj. is_init_sobj sobj \<and> sobj \<in> ss'} \<subseteq> ss"
+ − 14
+ − 15
lemma [simp]: "ss \<doteq> ss"
+ − 16
by (auto simp:init_ss_eq_def)
+ − 17
+ − 18
definition init_ss_in:: "t_static_state \<Rightarrow> t_static_state set \<Rightarrow> bool" (infix "\<propto>" 101)
+ − 19
where
+ − 20
"ss \<propto> sss \<equiv> \<exists> ss' \<in> sss. ss \<doteq> ss'"
+ − 21
+ − 22
lemma s2ss_included_sobj:
+ − 23
"\<lbrakk>alive s obj; co2sobj s obj= Some sobj\<rbrakk> \<Longrightarrow> sobj \<in> (s2ss s)"
+ − 24
by (simp add:s2ss_def, rule_tac x = obj in exI, simp)
+ − 25
+ − 26
lemma init_ss_in_prop:
+ − 27
"\<lbrakk>s2ss s \<propto> static; co2sobj s obj = Some sobj; alive s obj; init_obj_related sobj obj\<rbrakk>
+ − 28
\<Longrightarrow> \<exists> ss \<in> static. sobj \<in> ss"
+ − 29
apply (simp add:init_ss_in_def init_ss_eq_def)
+ − 30
apply (erule bexE, erule conjE)
+ − 31
apply (rule_tac x = ss' in bexI, auto dest!:s2ss_included_sobj)
+ − 32
done
+ − 33
+ − 34
+ − 35
+ − 36
+ − 37
+ − 38
+ − 39
lemma d2s_main_execve:
+ − 40
"valid (Execve p f fds # s) \<Longrightarrow> s2ss (Execve p f fds # s) \<in> static"
+ − 41
apply (frule vd_cons, frule vt_grant_os, clarsimp simp:s2ss_execve)
+ − 42
sorry
+ − 43
1
+ − 44
lemma d2s_main:
61
+ − 45
"valid s \<Longrightarrow> s2ss s \<propto> static"
+ − 46
apply (induct s, simp add:s2ss_nil_prop init_ss_in_def)
+ − 47
apply (rule_tac x = "init_static_state" in bexI, simp, simp add:s_init)
+ − 48
apply (frule vd_cons, frule vt_grant_os, simp)
+ − 49
apply (case_tac a)
+ − 50
apply (clarsimp simp add:s2ss_execve)
+ − 51
apply (rule conjI, rule impI)
+ − 52
31
+ − 53
+ − 54
1
+ − 55
sorry
+ − 56
+ − 57
+ − 58
lemma t2ts:
+ − 59
"obj \<in> tainted s \<Longrightarrow> co2sobj s obj = Some sobj \<Longrightarrow> tainted_s (s2ss s) sobj"
19
+ − 60
apply (frule tainted_in_current, frule tainted_is_valid)
62
+ − 61
apply (frule s2ss_included_sobj, simp)
1
+ − 62
apply (case_tac sobj, simp_all)
61
+ − 63
apply (case_tac [!] obj, simp_all add:co2sobj.simps split:option.splits if_splits)
19
+ − 64
apply (drule dir_not_tainted, simp)
+ − 65
apply (drule msgq_not_tainted, simp)
+ − 66
apply (drule shm_not_tainted, simp)
43
+ − 67
done
1
+ − 68
+ − 69
lemma delq_imp_delqm:
+ − 70
"deleted (O_msgq q) s \<Longrightarrow> deleted (O_msg q m) s"
+ − 71
apply (induct s, simp)
+ − 72
by (case_tac a, auto)
+ − 73
61
+ − 74
lemma tainted_s_subset_prop:
+ − 75
"\<lbrakk>tainted_s ss sobj; ss \<subseteq> ss'\<rbrakk> \<Longrightarrow> tainted_s ss' sobj"
+ − 76
apply (case_tac sobj)
+ − 77
apply auto
+ − 78
done
+ − 79
1
+ − 80
theorem static_complete:
+ − 81
assumes undel: "undeletable obj" and tbl: "taintable obj"
+ − 82
shows "taintable_s obj"
+ − 83
proof-
+ − 84
from tbl obtain s where tainted: "obj \<in> tainted s"
+ − 85
by (auto simp:taintable_def)
19
+ − 86
hence vs: "valid s" by (simp add:tainted_is_valid)
61
+ − 87
hence static: "s2ss s \<propto> static" using d2s_main by auto
62
+ − 88
from tainted tbl vs obtain sobj where sobj: "co2sobj s obj = Some sobj"
+ − 89
apply (clarsimp simp add:taintable_def)
+ − 90
apply (frule tainted_in_current)
+ − 91
apply (case_tac obj, simp_all add:co2sobj.simps)
+ − 92
apply (frule current_proc_has_sp, simp, auto)
+ − 93
done
1
+ − 94
from undel vs have "\<not> deleted obj s" and init_alive: "init_alive obj"
+ − 95
by (auto simp:undeletable_def)
+ − 96
with vs sobj have "init_obj_related sobj obj"
+ − 97
apply (case_tac obj, case_tac [!] sobj)
61
+ − 98
apply (auto split:option.splits if_splits simp:co2sobj.simps cp2sproc_def ch2sshm_def cq2smsgq_def cm2smsg_def delq_imp_delqm)
43
+ − 99
apply (frule not_deleted_init_file, simp+)
+ − 100
apply (drule is_file_has_sfile', simp, erule exE)
1
+ − 101
apply (rule_tac x = sf in bexI)
+ − 102
apply (case_tac list, auto split:option.splits simp:is_init_file_props)[1]
43
+ − 103
apply (drule root_is_init_dir', simp)
+ − 104
apply (frule not_deleted_init_file, simp, simp)
+ − 105
apply (simp add:cf2sfile_def split:option.splits if_splits)
+ − 106
apply (simp add:cf2sfiles_def)
+ − 107
apply (rule_tac x = list in bexI, simp, simp add:same_inode_files_def not_deleted_init_file)
+ − 108
+ − 109
apply (frule not_deleted_init_dir, simp+)
+ − 110
apply (simp add:cf2sfile_def split:option.splits if_splits)
+ − 111
apply (case_tac list, simp add:sroot_def, simp)
+ − 112
apply (drule file_dir_conflict, simp+)
+ − 113
done
1
+ − 114
with tainted t2ts init_alive sobj static
61
+ − 115
show ?thesis unfolding taintable_s_def
+ − 116
apply (simp add:init_ss_in_def)
+ − 117
apply (erule bexE)
+ − 118
apply (simp add:init_ss_eq_def)
+ − 119
apply (rule_tac x = "ss'" in bexI)
+ − 120
apply (rule_tac x = "sobj" in exI)
+ − 121
by (auto intro:tainted_s_subset_prop)
1
+ − 122
qed
+ − 123
19
+ − 124
lemma cp2sproc_pi:
+ − 125
"\<lbrakk>cp2sproc s p = Some (Init p', sec, fds, shms); valid s\<rbrakk> \<Longrightarrow> p = p' \<and> \<not> deleted (O_proc p) s \<and> p \<in> init_procs"
+ − 126
by (simp add:cp2sproc_def split:option.splits if_splits)
+ − 127
+ − 128
lemma cq2smsgq_qi:
+ − 129
"\<lbrakk>cq2smsgq s q = Some (Init q', sec, sms); valid s\<rbrakk> \<Longrightarrow> q = q' \<and> \<not> deleted (O_msgq q) s \<and> q \<in> init_msgqs"
+ − 130
by (simp add:cq2smsgq_def split:option.splits if_splits)
+ − 131
+ − 132
lemma cm2smsg_mi:
+ − 133
"\<lbrakk>cm2smsg s q m = Some (Init m', sec, ttag); q \<in> init_msgqs; valid s\<rbrakk>
+ − 134
\<Longrightarrow> m = m' \<and> \<not> deleted (O_msg q m) s \<and> m \<in> set (init_msgs_of_queue q) \<and> q \<in> init_msgqs"
+ − 135
by (clarsimp simp add:cm2smsg_def split:if_splits option.splits)
+ − 136
+ − 137
lemma ch2sshm_hi:
+ − 138
"\<lbrakk>ch2sshm s h = Some (Init h', sec); valid s\<rbrakk> \<Longrightarrow> h = h' \<and> \<not> deleted (O_shm h) s \<and> h \<in> init_shms"
+ − 139
by (clarsimp simp:ch2sshm_def split:if_splits option.splits)
+ − 140
+ − 141
lemma root_not_deleted:
+ − 142
"\<lbrakk>deleted (O_dir []) s; valid s\<rbrakk> \<Longrightarrow> False"
+ − 143
apply (induct s, simp)
+ − 144
apply (frule vd_cons, frule vt_grant_os, case_tac a, auto)
+ − 145
done
+ − 146
+ − 147
lemma cf2sfile_fi:
+ − 148
"\<lbrakk>cf2sfile s f = Some (Init f', sec, psecopt, asecs); valid s\<rbrakk> \<Longrightarrow> f = f' \<and>
+ − 149
(if (is_file s f) then \<not> deleted (O_file f) s \<and> is_init_file f
+ − 150
else \<not> deleted (O_dir f) s \<and> is_init_dir f)"
+ − 151
apply (case_tac f)
+ − 152
by (auto simp:sroot_def cf2sfile_def root_is_init_dir dest!:root_is_dir' root_not_deleted
+ − 153
split:if_splits option.splits)
+ − 154
1
+ − 155
lemma init_deled_imp_deled_s:
+ − 156
"\<lbrakk>deleted obj s; init_alive obj; sobj \<in> (s2ss s); valid s\<rbrakk> \<Longrightarrow> \<not> init_obj_related sobj obj"
19
+ − 157
apply (rule notI)
+ − 158
apply (clarsimp simp:s2ss_def)
+ − 159
apply (case_tac obj, case_tac [!] obja, case_tac sobj)
61
+ − 160
apply (auto split:option.splits if_splits dest!:cp2sproc_pi cq2smsgq_qi ch2sshm_hi cm2smsg_mi cf2sfile_fi simp:co2sobj.simps)
+ − 161
apply (auto simp:cf2sfiles_def same_inode_files_def has_same_inode_prop1' is_file_def is_dir_def co2sobj.simps
20
+ − 162
split:option.splits t_inode_tag.splits dest!:cf2sfile_fi)
19
+ − 163
done
1
+ − 164
+ − 165
lemma deleted_imp_deletable_s:
+ − 166
"\<lbrakk>deleted obj s; init_alive obj; valid s\<rbrakk> \<Longrightarrow> deletable_s obj"
+ − 167
apply (simp add:deletable_s_def)
61
+ − 168
apply (frule d2s_main)
+ − 169
apply (simp add:init_ss_in_def)
+ − 170
apply (erule bexE)
+ − 171
apply (rule_tac x = ss' in bexI)
+ − 172
apply (auto simp add: init_ss_eq_def dest!:init_deled_imp_deled_s)
+ − 173
apply (case_tac obj, case_tac [!] sobj)
+ − 174
apply auto
+ − 175
apply (erule set_mp)
+ − 176
apply (simp)
+ − 177
apply auto
+ − 178
apply (rule_tac x = "(Init list, (aa, ab, b), ac, ba)" in bexI)
+ − 179
apply auto
1
+ − 180
done
+ − 181
62
+ − 182
lemma init_related_imp_init_sobj:
+ − 183
"init_obj_related sobj obj \<Longrightarrow> is_init_sobj sobj"
+ − 184
apply (case_tac sobj, case_tac [!] obj, auto)
+ − 185
apply (rule_tac x = "(Init list, (aa, ab, b), ac, ba)" in bexI, auto)
+ − 186
done
+ − 187
1
+ − 188
theorem undeletable_s_complete:
+ − 189
assumes undel_s: "undeletable_s obj"
+ − 190
shows "undeletable obj"
+ − 191
proof-
+ − 192
from undel_s have init_alive: "init_alive obj"
+ − 193
and alive_s: "\<forall> ss \<in> static. \<exists> sobj \<in> ss. init_obj_related sobj obj"
+ − 194
using undeletable_s_def by auto
+ − 195
have "\<not> (\<exists> s. valid s \<and> deleted obj s)"
+ − 196
proof
+ − 197
assume "\<exists> s. valid s \<and> deleted obj s"
+ − 198
then obtain s where vs: "valid s" and del: "deleted obj s" by auto
61
+ − 199
from vs have vss: "s2ss s \<propto> static" by (rule d2s_main)
1
+ − 200
with alive_s obtain sobj where in_ss: "sobj \<in> (s2ss s)"
62
+ − 201
and related: "init_obj_related sobj obj"
+ − 202
apply (simp add:init_ss_in_def init_ss_eq_def)
+ − 203
apply (erule bexE, erule_tac x= ss' in ballE)
+ − 204
apply (auto dest:init_related_imp_init_sobj)
+ − 205
done
1
+ − 206
from init_alive del vs have "deletable_s obj"
+ − 207
by (auto elim:deleted_imp_deletable_s)
+ − 208
with alive_s
+ − 209
show False by (auto simp:deletable_s_def)
+ − 210
qed
+ − 211
with init_alive show ?thesis
+ − 212
by (simp add:undeletable_def)
+ − 213
qed
+ − 214
+ − 215
theorem final_offer:
+ − 216
"\<lbrakk>undeletable_s obj; \<not> taintable_s obj; init_alive obj\<rbrakk> \<Longrightarrow> \<not> taintable obj"
+ − 217
apply (erule swap)
+ − 218
by (simp add:static_complete undeletable_s_complete)
+ − 219
+ − 220
(************** static \<rightarrow> dynamic ***************)
+ − 221
+ − 222
lemma s2d_main:
+ − 223
"ss \<in> static \<Longrightarrow> \<exists> s. valid s \<and> s2ss s = ss"
+ − 224
apply (erule static.induct)
+ − 225
apply (rule_tac x = "[]" in exI, simp add:s2ss_nil_prop valid.intros)
+ − 226
+ − 227
apply (erule exE|erule conjE)+
+ − 228
20
+ − 229
sorry
+ − 230
+ − 231
lemma set_eq_D:
+ − 232
"\<lbrakk>x \<in> S; {x. P x} = S\<rbrakk> \<Longrightarrow> P x"
+ − 233
by auto
+ − 234
+ − 235
lemma cqm2sms_prop1:
+ − 236
"\<lbrakk>cqm2sms s q queue = Some sms; sm \<in> set sms\<rbrakk> \<Longrightarrow> \<exists> m. cm2smsg s q m = Some sm"
+ − 237
apply (induct queue arbitrary:sms)
43
+ − 238
apply (auto simp:cqm2sms.simps split:option.splits)
20
+ − 239
done
1
+ − 240
20
+ − 241
lemma sq_sm_prop:
+ − 242
"\<lbrakk>sm \<in> set sms; cq2smsgq s q = Some (qi, qsec, sms); valid s\<rbrakk>
+ − 243
\<Longrightarrow> \<exists> m. cm2smsg s q m = Some sm"
+ − 244
by (auto simp:cq2smsgq_def split: option.splits intro:cqm2sms_prop1)
+ − 245
62
+ − 246
declare co2sobj.simps [simp add]
+ − 247
20
+ − 248
lemma tainted_s_imp_tainted:
+ − 249
"\<lbrakk>tainted_s ss sobj; ss \<in> static\<rbrakk> \<Longrightarrow> \<exists> s obj. valid s \<and> co2sobj s obj = Some sobj \<and> obj \<in> tainted s"
+ − 250
apply (drule s2d_main)
+ − 251
apply (erule exE, erule conjE, simp add:s2ss_def)
+ − 252
apply (rule_tac x = s in exI, simp)
+ − 253
apply (case_tac sobj, simp_all)
+ − 254
apply (erule conjE, drule_tac S = ss in set_eq_D, simp, (erule exE|erule conjE)+)
+ − 255
apply (rule_tac x = obj in exI, simp)
+ − 256
apply (case_tac obj, (simp split:option.splits if_splits)+)
+ − 257
+ − 258
apply (erule conjE, drule_tac S = ss in set_eq_D, simp, (erule exE|erule conjE)+)
+ − 259
apply (rule_tac x = obj in exI, simp)
+ − 260
apply (case_tac obj, (simp split:option.splits if_splits)+)
21
+ − 261
done
1
+ − 262
62
+ − 263
lemma has_same_inode_prop3:
+ − 264
"has_same_inode s f f' \<Longrightarrow> has_same_inode s f' f"
+ − 265
by (auto simp:has_same_inode_def)
1
+ − 266
+ − 267
theorem static_sound:
+ − 268
assumes tbl_s: "taintable_s obj"
+ − 269
shows "taintable obj"
+ − 270
proof-
+ − 271
from tbl_s obtain ss sobj where static: "ss \<in> static"
+ − 272
and sobj: "tainted_s ss sobj" and related: "init_obj_related sobj obj"
+ − 273
and init_alive: "init_alive obj" by (auto simp:taintable_s_def)
+ − 274
from static sobj tainted_s_imp_tainted
20
+ − 275
obtain s obj' where co2sobj: "co2sobj s obj' = Some sobj"
+ − 276
and tainted': "obj' \<in> tainted s" and vs: "valid s" by blast
1
+ − 277
20
+ − 278
from co2sobj related vs
+ − 279
have eq:"obj = obj' \<or> (\<exists> f f'. obj = O_file f \<and> obj' = O_file f' \<and> has_same_inode s f f')"
+ − 280
apply (case_tac obj', case_tac [!] obj)
+ − 281
apply (auto split:option.splits if_splits dest!:cp2sproc_pi cq2smsgq_qi ch2sshm_hi cm2smsg_mi cf2sfile_fi)
+ − 282
apply (auto simp:cf2sfiles_def same_inode_files_def has_same_inode_def is_file_def is_dir_def
+ − 283
split:option.splits t_inode_tag.splits dest!:cf2sfile_fi)
+ − 284
done
62
+ − 285
with tainted' vs have tainted: "obj \<in> tainted s"
+ − 286
by (auto dest:has_same_inode_prop3 intro:has_same_inode_tainted)
+ − 287
from sobj related init_alive have "appropriate obj"
+ − 288
by (case_tac obj, case_tac [!] sobj, auto)
+ − 289
with vs init_alive tainted
1
+ − 290
show ?thesis by (auto simp:taintable_def)
+ − 291
qed
+ − 292
62
+ − 293
end
1
+ − 294
+ − 295
end