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 |
|
43
|
58 |
lemma tainted_has_sobj:
|
|
59 |
"\<lbrakk>obj \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> \<exists> sobj. co2sobj s obj = Some sobj"
|
61
|
60 |
apply (frule tainted_in_current, case_tac obj)
|
|
61 |
apply (auto dest:valid_tainted_obj simp:co2sobj.simps split:option.splits)
|
|
62 |
oops
|
1
|
63 |
|
|
64 |
lemma t2ts:
|
|
65 |
"obj \<in> tainted s \<Longrightarrow> co2sobj s obj = Some sobj \<Longrightarrow> tainted_s (s2ss s) sobj"
|
19
|
66 |
apply (frule tainted_in_current, frule tainted_is_valid)
|
61
|
67 |
apply (frule d2s_main', simp)
|
1
|
68 |
apply (case_tac sobj, simp_all)
|
61
|
69 |
apply (case_tac [!] obj, simp_all add:co2sobj.simps split:option.splits if_splits)
|
19
|
70 |
apply (drule dir_not_tainted, simp)
|
|
71 |
apply (drule msgq_not_tainted, simp)
|
|
72 |
apply (drule shm_not_tainted, simp)
|
43
|
73 |
done
|
1
|
74 |
|
|
75 |
lemma delq_imp_delqm:
|
|
76 |
"deleted (O_msgq q) s \<Longrightarrow> deleted (O_msg q m) s"
|
|
77 |
apply (induct s, simp)
|
|
78 |
by (case_tac a, auto)
|
|
79 |
|
61
|
80 |
lemma tainted_s_subset_prop:
|
|
81 |
"\<lbrakk>tainted_s ss sobj; ss \<subseteq> ss'\<rbrakk> \<Longrightarrow> tainted_s ss' sobj"
|
|
82 |
apply (case_tac sobj)
|
|
83 |
apply auto
|
|
84 |
done
|
|
85 |
|
1
|
86 |
theorem static_complete:
|
|
87 |
assumes undel: "undeletable obj" and tbl: "taintable obj"
|
|
88 |
shows "taintable_s obj"
|
|
89 |
proof-
|
|
90 |
from tbl obtain s where tainted: "obj \<in> tainted s"
|
|
91 |
by (auto simp:taintable_def)
|
19
|
92 |
hence vs: "valid s" by (simp add:tainted_is_valid)
|
61
|
93 |
hence static: "s2ss s \<propto> static" using d2s_main by auto
|
|
94 |
from tainted obtain sobj where sobj: "co2sobj s obj = Some sobj" sorry
|
|
95 |
(* should constrain undeletable with file/dir/process only, while msg and fd are excluded
|
|
96 |
using vs tainted_has_sobj by blast *)
|
1
|
97 |
from undel vs have "\<not> deleted obj s" and init_alive: "init_alive obj"
|
|
98 |
by (auto simp:undeletable_def)
|
|
99 |
with vs sobj have "init_obj_related sobj obj"
|
|
100 |
apply (case_tac obj, case_tac [!] sobj)
|
61
|
101 |
apply (auto split:option.splits if_splits simp:co2sobj.simps cp2sproc_def ch2sshm_def cq2smsgq_def cm2smsg_def delq_imp_delqm)
|
43
|
102 |
apply (frule not_deleted_init_file, simp+)
|
|
103 |
apply (drule is_file_has_sfile', simp, erule exE)
|
1
|
104 |
apply (rule_tac x = sf in bexI)
|
|
105 |
apply (case_tac list, auto split:option.splits simp:is_init_file_props)[1]
|
43
|
106 |
apply (drule root_is_init_dir', simp)
|
|
107 |
apply (frule not_deleted_init_file, simp, simp)
|
|
108 |
apply (simp add:cf2sfile_def split:option.splits if_splits)
|
|
109 |
apply (simp add:cf2sfiles_def)
|
|
110 |
apply (rule_tac x = list in bexI, simp, simp add:same_inode_files_def not_deleted_init_file)
|
|
111 |
|
|
112 |
apply (frule not_deleted_init_dir, simp+)
|
|
113 |
apply (simp add:cf2sfile_def split:option.splits if_splits)
|
|
114 |
apply (case_tac list, simp add:sroot_def, simp)
|
|
115 |
apply (drule file_dir_conflict, simp+)
|
|
116 |
done
|
1
|
117 |
with tainted t2ts init_alive sobj static
|
61
|
118 |
show ?thesis unfolding taintable_s_def
|
|
119 |
apply (simp add:init_ss_in_def)
|
|
120 |
apply (erule bexE)
|
|
121 |
apply (simp add:init_ss_eq_def)
|
|
122 |
apply (rule_tac x = "ss'" in bexI)
|
|
123 |
apply (rule_tac x = "sobj" in exI)
|
|
124 |
by (auto intro:tainted_s_subset_prop)
|
1
|
125 |
qed
|
|
126 |
|
19
|
127 |
lemma cp2sproc_pi:
|
|
128 |
"\<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"
|
|
129 |
by (simp add:cp2sproc_def split:option.splits if_splits)
|
|
130 |
|
|
131 |
lemma cq2smsgq_qi:
|
|
132 |
"\<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"
|
|
133 |
by (simp add:cq2smsgq_def split:option.splits if_splits)
|
|
134 |
|
|
135 |
lemma cm2smsg_mi:
|
|
136 |
"\<lbrakk>cm2smsg s q m = Some (Init m', sec, ttag); q \<in> init_msgqs; valid s\<rbrakk>
|
|
137 |
\<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"
|
|
138 |
by (clarsimp simp add:cm2smsg_def split:if_splits option.splits)
|
|
139 |
|
|
140 |
lemma ch2sshm_hi:
|
|
141 |
"\<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"
|
|
142 |
by (clarsimp simp:ch2sshm_def split:if_splits option.splits)
|
|
143 |
|
|
144 |
lemma root_not_deleted:
|
|
145 |
"\<lbrakk>deleted (O_dir []) s; valid s\<rbrakk> \<Longrightarrow> False"
|
|
146 |
apply (induct s, simp)
|
|
147 |
apply (frule vd_cons, frule vt_grant_os, case_tac a, auto)
|
|
148 |
done
|
|
149 |
|
|
150 |
lemma cf2sfile_fi:
|
|
151 |
"\<lbrakk>cf2sfile s f = Some (Init f', sec, psecopt, asecs); valid s\<rbrakk> \<Longrightarrow> f = f' \<and>
|
|
152 |
(if (is_file s f) then \<not> deleted (O_file f) s \<and> is_init_file f
|
|
153 |
else \<not> deleted (O_dir f) s \<and> is_init_dir f)"
|
|
154 |
apply (case_tac f)
|
|
155 |
by (auto simp:sroot_def cf2sfile_def root_is_init_dir dest!:root_is_dir' root_not_deleted
|
|
156 |
split:if_splits option.splits)
|
|
157 |
|
1
|
158 |
lemma init_deled_imp_deled_s:
|
|
159 |
"\<lbrakk>deleted obj s; init_alive obj; sobj \<in> (s2ss s); valid s\<rbrakk> \<Longrightarrow> \<not> init_obj_related sobj obj"
|
19
|
160 |
apply (rule notI)
|
|
161 |
apply (clarsimp simp:s2ss_def)
|
|
162 |
apply (case_tac obj, case_tac [!] obja, case_tac sobj)
|
61
|
163 |
apply (auto split:option.splits if_splits dest!:cp2sproc_pi cq2smsgq_qi ch2sshm_hi cm2smsg_mi cf2sfile_fi simp:co2sobj.simps)
|
|
164 |
apply (auto simp:cf2sfiles_def same_inode_files_def has_same_inode_prop1' is_file_def is_dir_def co2sobj.simps
|
20
|
165 |
split:option.splits t_inode_tag.splits dest!:cf2sfile_fi)
|
19
|
166 |
done
|
1
|
167 |
|
|
168 |
lemma deleted_imp_deletable_s:
|
|
169 |
"\<lbrakk>deleted obj s; init_alive obj; valid s\<rbrakk> \<Longrightarrow> deletable_s obj"
|
|
170 |
apply (simp add:deletable_s_def)
|
61
|
171 |
apply (frule d2s_main)
|
|
172 |
apply (simp add:init_ss_in_def)
|
|
173 |
apply (erule bexE)
|
|
174 |
apply (rule_tac x = ss' in bexI)
|
|
175 |
apply (auto simp add: init_ss_eq_def dest!:init_deled_imp_deled_s)
|
|
176 |
apply (case_tac obj, case_tac [!] sobj)
|
|
177 |
apply auto
|
|
178 |
apply (erule set_mp)
|
|
179 |
apply (simp)
|
|
180 |
apply auto
|
|
181 |
apply (rule_tac x = "(Init list, (aa, ab, b), ac, ba)" in bexI)
|
|
182 |
apply auto
|
1
|
183 |
done
|
|
184 |
|
|
185 |
theorem undeletable_s_complete:
|
|
186 |
assumes undel_s: "undeletable_s obj"
|
|
187 |
shows "undeletable obj"
|
|
188 |
proof-
|
|
189 |
from undel_s have init_alive: "init_alive obj"
|
|
190 |
and alive_s: "\<forall> ss \<in> static. \<exists> sobj \<in> ss. init_obj_related sobj obj"
|
|
191 |
using undeletable_s_def by auto
|
|
192 |
have "\<not> (\<exists> s. valid s \<and> deleted obj s)"
|
|
193 |
proof
|
|
194 |
assume "\<exists> s. valid s \<and> deleted obj s"
|
|
195 |
then obtain s where vs: "valid s" and del: "deleted obj s" by auto
|
61
|
196 |
from vs have vss: "s2ss s \<propto> static" by (rule d2s_main)
|
1
|
197 |
with alive_s obtain sobj where in_ss: "sobj \<in> (s2ss s)"
|
61
|
198 |
and related: "init_obj_related sobj obj" apply auto
|
1
|
199 |
from init_alive del vs have "deletable_s obj"
|
|
200 |
by (auto elim:deleted_imp_deletable_s)
|
|
201 |
with alive_s
|
|
202 |
show False by (auto simp:deletable_s_def)
|
|
203 |
qed
|
|
204 |
with init_alive show ?thesis
|
|
205 |
by (simp add:undeletable_def)
|
|
206 |
qed
|
|
207 |
|
|
208 |
theorem final_offer:
|
|
209 |
"\<lbrakk>undeletable_s obj; \<not> taintable_s obj; init_alive obj\<rbrakk> \<Longrightarrow> \<not> taintable obj"
|
|
210 |
apply (erule swap)
|
|
211 |
by (simp add:static_complete undeletable_s_complete)
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
(************** static \<rightarrow> dynamic ***************)
|
|
216 |
|
|
217 |
lemma created_can_have_many:
|
|
218 |
"\<lbrakk>valid s; alive s obj; \<not> init_alive obj\<rbrakk> \<Longrightarrow> \<exists> s'. valid s' \<and> alive s' obj \<and> alive s' obj' \<and> s2ss s = s2ss s'"
|
|
219 |
sorry
|
|
220 |
|
|
221 |
lemma s2d_main:
|
|
222 |
"ss \<in> static \<Longrightarrow> \<exists> s. valid s \<and> s2ss s = ss"
|
|
223 |
apply (erule static.induct)
|
|
224 |
apply (rule_tac x = "[]" in exI, simp add:s2ss_nil_prop valid.intros)
|
|
225 |
|
|
226 |
apply (erule exE|erule conjE)+
|
|
227 |
|
20
|
228 |
sorry
|
|
229 |
|
|
230 |
lemma tainted_s_in_ss:
|
|
231 |
"tainted_s ss sobj \<Longrightarrow> sobj \<in> ss"
|
|
232 |
apply (case_tac sobj, simp_all)
|
|
233 |
apply (case_tac bool, simp+)
|
|
234 |
apply (case_tac bool, simp+)
|
|
235 |
apply (case_tac prod1, case_tac prod2, simp)
|
|
236 |
thm tainted_s.simps
|
|
237 |
oops
|
|
238 |
|
|
239 |
lemma set_eq_D:
|
|
240 |
"\<lbrakk>x \<in> S; {x. P x} = S\<rbrakk> \<Longrightarrow> P x"
|
|
241 |
by auto
|
|
242 |
|
|
243 |
lemma cqm2sms_prop1:
|
|
244 |
"\<lbrakk>cqm2sms s q queue = Some sms; sm \<in> set sms\<rbrakk> \<Longrightarrow> \<exists> m. cm2smsg s q m = Some sm"
|
|
245 |
apply (induct queue arbitrary:sms)
|
43
|
246 |
apply (auto simp:cqm2sms.simps split:option.splits)
|
20
|
247 |
done
|
1
|
248 |
|
20
|
249 |
lemma sq_sm_prop:
|
|
250 |
"\<lbrakk>sm \<in> set sms; cq2smsgq s q = Some (qi, qsec, sms); valid s\<rbrakk>
|
|
251 |
\<Longrightarrow> \<exists> m. cm2smsg s q m = Some sm"
|
|
252 |
by (auto simp:cq2smsgq_def split: option.splits intro:cqm2sms_prop1)
|
|
253 |
|
|
254 |
lemma tainted_s_imp_tainted:
|
|
255 |
"\<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"
|
|
256 |
apply (drule s2d_main)
|
|
257 |
apply (erule exE, erule conjE, simp add:s2ss_def)
|
|
258 |
apply (rule_tac x = s in exI, simp)
|
|
259 |
apply (case_tac sobj, simp_all)
|
|
260 |
apply (erule conjE, drule_tac S = ss in set_eq_D, simp, (erule exE|erule conjE)+)
|
|
261 |
apply (rule_tac x = obj in exI, simp)
|
|
262 |
apply (case_tac obj, (simp split:option.splits if_splits)+)
|
|
263 |
|
|
264 |
apply (erule conjE, drule_tac S = ss in set_eq_D, simp, (erule exE|erule conjE)+)
|
|
265 |
apply (rule_tac x = obj in exI, simp)
|
|
266 |
apply (case_tac obj, (simp split:option.splits if_splits)+)
|
|
267 |
|
|
268 |
apply (case_tac prod1, case_tac prod2, simp)
|
|
269 |
apply ((erule conjE)+, drule_tac S = ss in set_eq_D, simp, (erule exE|erule conjE)+)
|
|
270 |
apply (case_tac obj, simp_all split:option.splits if_splits)
|
|
271 |
apply (drule_tac sm = "(aa, ba, True)" in sq_sm_prop, simp+, erule exE)
|
|
272 |
apply (rule_tac x = "O_msg nat m" in exI)
|
43
|
273 |
apply (rule conjI)
|
|
274 |
apply simp
|
|
275 |
apply (simp add
|
|
276 |
apply (simp add:co2sobj.simps)
|
|
277 |
apply (simp add:cm2smsg_def split:option.splits if_splits)
|
21
|
278 |
done
|
1
|
279 |
|
20
|
280 |
lemma has_inode_tainted_aux:
|
|
281 |
"O_file f \<in> tainted s \<Longrightarrow> \<forall> f'. has_same_inode s f f' \<longrightarrow> O_file f' \<in> tainted s"
|
|
282 |
apply (erule tainted.induct)
|
|
283 |
apply (auto intro:tainted.intros simp:has_same_inode_def)
|
|
284 |
(*?? need simpset for tainted *)
|
1
|
285 |
sorry
|
|
286 |
|
20
|
287 |
lemma has_same_inode_tainted:
|
|
288 |
"\<lbrakk>has_same_inode s f f'; O_file f' \<in> tainted s\<rbrakk> \<Longrightarrow> O_file f \<in> tainted s"
|
|
289 |
by (drule has_inode_tainted_aux, auto simp:has_same_inode_def)
|
1
|
290 |
|
|
291 |
theorem static_sound:
|
|
292 |
assumes tbl_s: "taintable_s obj"
|
|
293 |
shows "taintable obj"
|
|
294 |
proof-
|
|
295 |
from tbl_s obtain ss sobj where static: "ss \<in> static"
|
|
296 |
and sobj: "tainted_s ss sobj" and related: "init_obj_related sobj obj"
|
|
297 |
and init_alive: "init_alive obj" by (auto simp:taintable_s_def)
|
|
298 |
from static sobj tainted_s_imp_tainted
|
20
|
299 |
obtain s obj' where co2sobj: "co2sobj s obj' = Some sobj"
|
|
300 |
and tainted': "obj' \<in> tainted s" and vs: "valid s" by blast
|
1
|
301 |
|
20
|
302 |
from co2sobj related vs
|
|
303 |
have eq:"obj = obj' \<or> (\<exists> f f'. obj = O_file f \<and> obj' = O_file f' \<and> has_same_inode s f f')"
|
|
304 |
apply (case_tac obj', case_tac [!] obj)
|
|
305 |
apply (auto split:option.splits if_splits dest!:cp2sproc_pi cq2smsgq_qi ch2sshm_hi cm2smsg_mi cf2sfile_fi)
|
|
306 |
apply (auto simp:cf2sfiles_def same_inode_files_def has_same_inode_def is_file_def is_dir_def
|
|
307 |
split:option.splits t_inode_tag.splits dest!:cf2sfile_fi)
|
|
308 |
done
|
|
309 |
with tainted' have tainted: "obj \<in> tainted s"
|
|
310 |
by (auto intro:has_same_inode_tainted)
|
|
311 |
with vs init_alive
|
1
|
312 |
show ?thesis by (auto simp:taintable_def)
|
|
313 |
qed
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
lemma ts2t:
|
|
318 |
"obj \<in> tainted_s ss \<Longrightarrow> \<exists> s. obj \<in> tainted s"
|
|
319 |
"obj \<in> tainted_s ss \<Longrightarrow> \<exists> so. so True \<in> ss \<Longrightarrow> so True \<in> ss \<Longrightarrow> \<exists> s. valid s \<and> s2ss s = ss \<Longrightarrow> so True \<in> s2ss s \<Longrightarrow> tainted s obj. "
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
end |