|
1 theory Static |
|
2 imports Static_type OS_type_def Flask_type Flask |
|
3 begin |
|
4 |
|
5 locale tainting_s = tainting |
|
6 |
|
7 begin |
|
8 |
|
9 (* |
|
10 definition init_sectxt_of_file:: "t_file \<Rightarrow> security_context_t option" |
|
11 where |
|
12 "init_sectxt_of_file f \<equiv> |
|
13 if (is_init_file f) then init_sectxt_of_obj (O_file f) |
|
14 else if (is_init_dir f) then init_sectxt_of_obj (O_dir f) |
|
15 else None" |
|
16 *) |
|
17 |
|
18 definition sroot :: "t_sfile" |
|
19 where |
|
20 "sroot \<equiv> (Init [], sec_of_root, None, {})" |
|
21 |
|
22 definition init_cf2sfile :: "t_file \<Rightarrow> t_sfile option" |
|
23 where |
|
24 "init_cf2sfile f \<equiv> |
|
25 case (parent f) of |
|
26 None \<Rightarrow> Some sroot |
|
27 | Some pf \<Rightarrow> if (is_init_file f) then |
|
28 (case (init_sectxt_of_obj (O_file f), init_sectxt_of_obj (O_dir pf), get_parentfs_ctxts [] pf) of |
|
29 (Some sec, Some psec, Some aseclist) \<Rightarrow> Some (Init f, sec, Some psec, set aseclist) |
|
30 | _ \<Rightarrow> None) else |
|
31 (case (init_sectxt_of_obj (O_dir f), init_sectxt_of_obj (O_dir pf), get_parentfs_ctxts [] pf) of |
|
32 (Some sec, Some psec, Some aseclist) \<Rightarrow> Some (Init f, sec, Some psec, set aseclist) |
|
33 | _ \<Rightarrow> None)" |
|
34 |
|
35 definition init_cf2sfiles :: "t_file \<Rightarrow> t_sfile set" |
|
36 where |
|
37 "init_cf2sfiles f \<equiv> {sf. \<exists>f' \<in> init_same_inode_files f. init_cf2sfile f' = Some sf}" |
|
38 |
|
39 definition init_cfd2sfd :: "t_process \<Rightarrow> t_fd \<Rightarrow> (security_context_t \<times> t_open_flags \<times> t_sfile) option" |
|
40 where |
|
41 "init_cfd2sfd p fd = |
|
42 (case (init_file_of_proc_fd p fd, init_oflags_of_proc_fd p fd, init_sectxt_of_obj (O_fd p fd)) of |
|
43 (Some f, Some flags, Some sec) \<Rightarrow> (case (init_cf2sfile f) of |
|
44 Some sf \<Rightarrow> Some (sec, flags, sf) |
|
45 | _ \<Rightarrow> None) |
|
46 | _ \<Rightarrow> None)" |
|
47 |
|
48 definition init_cfds2sfds :: "t_process \<Rightarrow> (security_context_t \<times> t_open_flags \<times> t_sfile) set" |
|
49 where |
|
50 "init_cfds2sfds p \<equiv> { sfd. \<exists> fd \<in> init_proc_file_fds p. init_cfd2sfd p fd = Some sfd}" |
|
51 |
|
52 (* |
|
53 definition init_ch2sshm :: "t_shm \<Rightarrow> t_sshm option" |
|
54 where |
|
55 "init_ch2sshm h \<equiv> (case (init_sectxt_of_obj (O_shm h)) of |
|
56 Some sec \<Rightarrow> Some (Init h, sec) |
|
57 | _ \<Rightarrow> None)" |
|
58 |
|
59 definition init_cph2spshs |
|
60 :: "t_process \<Rightarrow> (t_sshm \<times> t_shm_attach_flag) set" |
|
61 where |
|
62 "init_cph2spshs p \<equiv> {(sh, flag)| sh flag h. (p, flag) \<in> init_procs_of_shm h \<and> |
|
63 init_ch2sshm h = Some sh}" |
|
64 *) |
|
65 |
|
66 definition init_cp2sproc :: "t_process \<Rightarrow> t_sproc option" |
|
67 where |
|
68 "init_cp2sproc p \<equiv> (case (init_sectxt_of_obj (O_proc p)) of |
|
69 Some sec \<Rightarrow> Some (Init p, sec, (init_cfds2sfds p)) |
|
70 | None \<Rightarrow> None)" |
|
71 |
|
72 (* acient files of init-file |
|
73 definition init_o2s_afs :: "t_file \<Rightarrow> security_context_t set" |
|
74 where |
|
75 "init_o2s_afs f \<equiv> {sec. \<exists> f'. f' \<preceq> f \<and> init_sectxt_of_obj (O_dir f') = Some sec}" *) |
|
76 |
|
77 definition init_cm2smsg :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsg option" |
|
78 where |
|
79 "init_cm2smsg q m \<equiv> (case (init_sectxt_of_obj (O_msg q m)) of |
|
80 Some sec \<Rightarrow> Some (Init m, sec, (O_msg q m) \<in> seeds) |
|
81 | _ \<Rightarrow> None)" |
|
82 |
|
83 fun init_cqm2sms :: "t_msgq \<Rightarrow> t_msg list \<Rightarrow> (t_smsg list) option" |
|
84 where |
|
85 "init_cqm2sms q [] = Some []" |
|
86 | "init_cqm2sms q (m#ms) = |
|
87 (case (init_cqm2sms q ms, init_cm2smsg q m) of |
|
88 (Some sms, Some sm) \<Rightarrow> Some (sm # sms) |
|
89 | _ \<Rightarrow> None)" |
|
90 |
|
91 definition init_cq2smsgq :: "t_msgq \<Rightarrow> t_smsgq option" |
|
92 where |
|
93 "init_cq2smsgq q \<equiv> (case (init_sectxt_of_obj (O_msgq q), init_cqm2sms q (init_msgs_of_queue q)) of |
|
94 (Some sec, Some sms) \<Rightarrow> Some (Init q, sec, sms) |
|
95 | _ \<Rightarrow> None)" |
|
96 |
|
97 fun init_obj2sobj :: "t_object \<Rightarrow> t_sobject option" |
|
98 where |
|
99 "init_obj2sobj (O_proc p) = |
|
100 (case (init_cp2sproc p) of |
|
101 Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> seeds)) |
|
102 | _ \<Rightarrow> None)" |
|
103 | "init_obj2sobj (O_file f) = |
|
104 (case (init_cf2sfile f) of |
|
105 Some sf \<Rightarrow> Some (S_file sf (O_file f \<in> seeds)) |
|
106 | _ \<Rightarrow> None)" |
|
107 | "init_obj2sobj (O_dir f) = |
|
108 (case (init_cf2sfile f) of |
|
109 Some sf \<Rightarrow> Some (S_dir sf) |
|
110 | _ \<Rightarrow> None)" |
|
111 | "init_obj2sobj (O_msgq q) = |
|
112 (case (init_cq2smsgq q) of |
|
113 Some sq \<Rightarrow> Some (S_msgq sq) |
|
114 | _ \<Rightarrow> None)" |
|
115 (* |
|
116 | "init_obj2sobj (O_shm h) = |
|
117 (case (init_ch2sshm h) of |
|
118 Some sh \<Rightarrow> Some (S_shm sh) |
|
119 | _ \<Rightarrow> None)" |
|
120 | "init_obj2sobj (O_msg q m) = |
|
121 (case (init_cq2smsgq q, init_cm2smsg q m) of |
|
122 (Some sq, Some sm) \<Rightarrow> Some (S_msg sq sm) |
|
123 | _ \<Rightarrow> None)" *) |
|
124 | "init_obj2sobj _ = None" |
|
125 |
|
126 definition |
|
127 "init_static_state \<equiv> {sobj. \<exists> obj. init_alive obj \<and> init_obj2sobj obj = Some sobj}" |
|
128 |
|
129 (**************** translation from dynamic to static *******************) |
|
130 |
|
131 definition cf2sfile :: "t_state \<Rightarrow> t_file \<Rightarrow> t_sfile option" |
|
132 where |
|
133 "cf2sfile s f \<equiv> |
|
134 case (parent f) of |
|
135 None \<Rightarrow> Some sroot |
|
136 | Some pf \<Rightarrow> if (is_file s f) |
|
137 then (case (sectxt_of_obj s (O_file f), sectxt_of_obj s (O_dir pf), get_parentfs_ctxts s pf) of |
|
138 (Some sec, Some psec, Some asecs) \<Rightarrow> |
|
139 Some (if (\<not> deleted (O_file f) s \<and> is_init_file f) then Init f else Created, sec, Some psec, set asecs) |
|
140 | _ \<Rightarrow> None) |
|
141 else (case (sectxt_of_obj s (O_dir f), sectxt_of_obj s (O_dir pf), get_parentfs_ctxts s pf) of |
|
142 (Some sec, Some psec, Some asecs) \<Rightarrow> |
|
143 Some (if (\<not> deleted (O_dir f) s \<and> is_init_dir f) then Init f else Created, sec, Some psec, set asecs) |
|
144 | _ \<Rightarrow> None)" |
|
145 |
|
146 (* |
|
147 definition cf2sfiles :: "t_state \<Rightarrow> t_file \<Rightarrow> t_sfile set" |
|
148 where |
|
149 "cf2sfiles s f \<equiv> {sf. \<exists> f' \<in> (same_inode_files s f). cf2sfile s f' = Some sf}" |
|
150 *) |
|
151 |
|
152 (* here cf2sfile is passed with True, because, process' fds are only for files not dirs *) |
|
153 definition cfd2sfd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_sfd option" |
|
154 where |
|
155 "cfd2sfd s p fd \<equiv> |
|
156 (case (file_of_proc_fd s p fd, flags_of_proc_fd s p fd, sectxt_of_obj s (O_fd p fd)) of |
|
157 (Some f, Some flags, Some sec) \<Rightarrow> (case (cf2sfile s f) of |
|
158 Some sf \<Rightarrow> Some (sec, flags, sf) |
|
159 | _ \<Rightarrow> None) |
|
160 | _ \<Rightarrow> None)" |
|
161 |
|
162 |
|
163 definition cpfd2sfds :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sfd set" |
|
164 where |
|
165 "cpfd2sfds s p \<equiv> {sfd. \<exists> fd \<in> proc_file_fds s p. cfd2sfd s p fd = Some sfd}" |
|
166 |
|
167 (* |
|
168 definition ch2sshm :: "t_state \<Rightarrow> t_shm \<Rightarrow> t_sshm option" |
|
169 where |
|
170 "ch2sshm s h \<equiv> (case (sectxt_of_obj s (O_shm h)) of |
|
171 Some sec \<Rightarrow> |
|
172 Some (if (\<not> deleted (O_shm h) s \<and> h \<in> init_shms) then Init h else Created, sec) |
|
173 | _ \<Rightarrow> None)" |
|
174 |
|
175 definition cph2spshs :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sproc_sshm set" |
|
176 where |
|
177 "cph2spshs s p \<equiv> {(sh, flag)| sh flag h. (p, flag) \<in> procs_of_shm s h \<and> ch2sshm s h = Some sh}" |
|
178 *) |
|
179 |
|
180 definition cp2sproc :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sproc option" |
|
181 where |
|
182 "cp2sproc s p \<equiv> (case (sectxt_of_obj s (O_proc p)) of |
|
183 Some sec \<Rightarrow> |
|
184 Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) then Init p else Created, sec, |
|
185 cpfd2sfds s p) |
|
186 | _ \<Rightarrow> None)" |
|
187 |
|
188 definition cm2smsg :: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsg option" |
|
189 where |
|
190 "cm2smsg s q m \<equiv> (case (sectxt_of_obj s (O_msg q m)) of |
|
191 Some sec \<Rightarrow> |
|
192 Some (if (\<not> deleted (O_msg q m) s \<and> m \<in> set (init_msgs_of_queue q)) then Init m else Created, |
|
193 sec, O_msg q m \<in> tainted s) |
|
194 | _ \<Rightarrow> None)" |
|
195 |
|
196 fun cqm2sms:: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_msg list \<Rightarrow> (t_smsg list) option" |
|
197 where |
|
198 "cqm2sms s q [] = Some []" |
|
199 | "cqm2sms s q (m#ms) = |
|
200 (case (cqm2sms s q ms, cm2smsg s q m) of |
|
201 (Some sms, Some sm) \<Rightarrow> Some (sm#sms) |
|
202 | _ \<Rightarrow> None)" |
|
203 |
|
204 definition cq2smsgq :: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_smsgq option" |
|
205 where |
|
206 "cq2smsgq s q \<equiv> (case (sectxt_of_obj s (O_msgq q), cqm2sms s q (msgs_of_queue s q)) of |
|
207 (Some sec, Some sms) \<Rightarrow> |
|
208 Some (if (\<not> deleted (O_msgq q) s \<and> q \<in> init_msgqs) then Init q else Created, |
|
209 sec, sms) |
|
210 | _ \<Rightarrow> None)" |
|
211 |
|
212 fun co2sobj :: "t_state \<Rightarrow> t_object \<Rightarrow> t_sobject option" |
|
213 where |
|
214 "co2sobj s (O_proc p) = |
|
215 (case (cp2sproc s p) of |
|
216 Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> tainted s)) |
|
217 | _ \<Rightarrow> None)" |
|
218 | "co2sobj s (O_file f) = |
|
219 (case (cf2sfile s f) of |
|
220 Some sf \<Rightarrow> Some (S_file sf (O_file f \<in> tainted s)) |
|
221 | _ \<Rightarrow> None)" |
|
222 | "co2sobj s (O_dir f) = |
|
223 (case (cf2sfile s f) of |
|
224 Some sf \<Rightarrow> Some (S_dir sf) |
|
225 | _ \<Rightarrow> None)" |
|
226 | "co2sobj s (O_msgq q) = |
|
227 (case (cq2smsgq s q) of |
|
228 Some sq \<Rightarrow> Some (S_msgq sq) |
|
229 | _ \<Rightarrow> None)" |
|
230 (* |
|
231 | "co2sobj s (O_shm h) = |
|
232 (case (ch2sshm s h) of |
|
233 Some sh \<Rightarrow> Some (S_shm sh) |
|
234 | _ \<Rightarrow> None)" |
|
235 | "co2sobj s (O_msg q m) = |
|
236 (case (cq2smsgq s q, cm2smsg s q m) of |
|
237 (Some sq, Some sm) \<Rightarrow> Some (S_msg sq sm) |
|
238 | _ \<Rightarrow> None)" |
|
239 *) |
|
240 | "co2sobj s _ = None" |
|
241 |
|
242 |
|
243 definition s2ss :: "t_state \<Rightarrow> t_static_state" |
|
244 where |
|
245 "s2ss s \<equiv> {sobj. \<exists> obj. alive s obj \<and> co2sobj s obj = Some sobj}" |
|
246 |
|
247 |
|
248 (* ******************************************************** *) |
|
249 |
|
250 |
|
251 fun is_init_sfile :: "t_sfile \<Rightarrow> bool" |
|
252 where |
|
253 "is_init_sfile (Init _, sec, psec,asec) = True" |
|
254 | "is_init_sfile _ = False" |
|
255 |
|
256 fun is_many_sfile :: "t_sfile \<Rightarrow> bool" |
|
257 where |
|
258 "is_many_sfile (Created, sec, psec, asec) = True" |
|
259 | "is_many_sfile _ = False" |
|
260 |
|
261 fun is_init_sproc :: "t_sproc \<Rightarrow> bool" |
|
262 where |
|
263 "is_init_sproc (Init p, sec, fds) = True" |
|
264 | "is_init_sproc _ = False" |
|
265 |
|
266 fun is_many_sproc :: "t_sproc \<Rightarrow> bool" |
|
267 where |
|
268 "is_many_sproc (Created, sec,fds) = True" |
|
269 | "is_many_sproc _ = False" |
|
270 |
|
271 fun is_many_smsg :: "t_smsg \<Rightarrow> bool" |
|
272 where |
|
273 "is_many_smsg (Created,sec,tag) = True" |
|
274 | "is_many_smsg _ = False" |
|
275 |
|
276 (* wrong def |
|
277 fun is_many_smsgq :: "t_smsgq \<Rightarrow> bool" |
|
278 where |
|
279 "is_many_smsgq (Created,sec,sms) = (True \<and> (\<forall> sm \<in> (set sms). is_many_smsg sm))" |
|
280 | "is_many_smsgq _ = False" |
|
281 *) |
|
282 |
|
283 fun is_many_smsgq :: "t_smsgq \<Rightarrow> bool" |
|
284 where |
|
285 "is_many_smsgq (Created,sec,sms) = True" |
|
286 | "is_many_smsgq _ = False" |
|
287 |
|
288 fun is_many :: "t_sobject \<Rightarrow> bool" |
|
289 where |
|
290 "is_many (S_proc sp tag) = is_many_sproc sp" |
|
291 | "is_many (S_file sf tag) = is_many_sfile sf" |
|
292 | "is_many (S_dir sf ) = is_many_sfile sf" |
|
293 | "is_many (S_msgq sq ) = is_many_smsgq sq" |
|
294 |
|
295 fun is_init_smsgq :: "t_smsgq \<Rightarrow> bool" |
|
296 where |
|
297 "is_init_smsgq (Init q,sec,sms) = True" |
|
298 | "is_init_smsgq _ = False" |
|
299 |
|
300 fun is_init_sobj :: "t_sobject \<Rightarrow> bool" |
|
301 where |
|
302 "is_init_sobj (S_proc sp tag ) = is_init_sproc sp" |
|
303 | "is_init_sobj (S_file sf tag ) = is_init_sfile sf" |
|
304 | "is_init_sobj (S_dir sf ) = is_init_sfile sf" |
|
305 | "is_init_sobj (S_msgq sq ) = is_init_smsgq sq" |
|
306 |
|
307 (* |
|
308 fun update_ss_sp:: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state" |
|
309 where |
|
310 "update_ss_sp ss (S_proc sp tag) (S_proc sp' tag') = |
|
311 (if (is_many_sproc sp) then ss \<union> {S_proc sp' tag'} |
|
312 else (ss - {S_proc sp tag}) \<union> {S_proc sp' tag'})" |
|
313 |
|
314 fun update_ss_sd:: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state" |
|
315 where |
|
316 "update_ss_sd ss (S_dir sf tag) (S_dir sf' tag') = |
|
317 (if (is_many_sfile sf) then ss \<union> {S_dir sf' tag'} |
|
318 else (ss - {S_dir sf tag}) \<union> {S_dir sf' tag'})" |
|
319 *) |
|
320 |
|
321 (* |
|
322 fun sparent :: "t_sfile \<Rightarrow> t_sfile option" |
|
323 where |
|
324 "sparent (Sroot si sec) = None" |
|
325 | "sparent (Sfile si sec spf) = Some spf" |
|
326 |
|
327 inductive is_ancesf :: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool" |
|
328 where |
|
329 "is_ancesf sf sf" |
|
330 | "sparent sf = Some spf \<Longrightarrow> is_ancesf spf sf" |
|
331 | "\<lbrakk>sparent sf = Some spf; is_ancesf saf spf\<rbrakk> \<Longrightarrow> is_ancesf saf sf" |
|
332 |
|
333 definition sfile_reparent :: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile" |
|
334 where |
|
335 "sfile_reparent (Sroot)" |
|
336 *) |
|
337 |
|
338 (* |
|
339 (* sfds rename aux definitions *) |
|
340 definition sfds_rename_notrelated |
|
341 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
342 where |
|
343 "sfds_rename_notrelated sfds from to sfds' \<equiv> |
|
344 (\<forall> sec flag sf. (sec,flag,sf) \<in> sfds \<and> (\<not> from \<preceq> sf) \<longrightarrow> (sec,flag,sf) \<in> sfds')" |
|
345 |
|
346 definition sfds_rename_renamed |
|
347 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
348 where |
|
349 "sfds_rename_renamed sfds sf from to sfds' \<equiv> |
|
350 (\<forall> sec flag sf'. (sec,flag,sf) \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow> |
|
351 (sec, flag, file_after_rename sf' from to) \<in> sfds' \<and> (sec,flag,sf) \<notin> sfds')" |
|
352 |
|
353 definition sfds_rename_remain |
|
354 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
355 where |
|
356 "sfds_rename_remain sfds sf from to sfds' \<equiv> |
|
357 (\<forall> sec flag sf'. (sec,flag,sf') \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow> |
|
358 (sec, flag, sf') \<in> sfds' \<and> (sec,flag, file_after_rename sf' from to) \<notin> sfds')" |
|
359 |
|
360 (* for not many, choose on renamed or not *) |
|
361 definition sfds_rename_choices |
|
362 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
363 where |
|
364 "sfds_rename_choices sfds sf from to sfds' \<equiv> |
|
365 sfds_rename_remain sfds sf from to sfds' \<or> sfds_rename_renamed sfds sf from to sfds'" |
|
366 |
|
367 (* for many, merge renamed with not renamed *) |
|
368 definition sfds_rename_both |
|
369 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
370 where |
|
371 "sfds_rename_both sfds sf from to sfds' \<equiv> |
|
372 (\<forall> sec flag sf'. (sec,flag,sf') \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow> |
|
373 (sec, flag, sf') \<in> sfds' \<or> (sec,flag, file_after_rename sf' from to) \<in> sfds')" |
|
374 |
|
375 (* added to the new sfds, are those only under the new sfile *) |
|
376 definition sfds_rename_added |
|
377 :: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
378 where |
|
379 "sfds_rename_added sfds from to sfds' \<equiv> |
|
380 (\<forall> sec' flag' sf' sec flag. (sec',flag',sf') \<in> sfds' \<and> (sec,flag,sf') \<notin> sfds \<longrightarrow> |
|
381 (\<exists> sf. (sec,flag,sf) \<in> sfds \<and> sf' = file_after_rename from to sf))" |
|
382 |
|
383 definition sproc_sfds_renamed |
|
384 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
385 where |
|
386 "sproc_sfds_renamed ss sf from to ss' \<equiv> |
|
387 (\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> |
|
388 (\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_renamed sfds sf from to sfds'))" |
|
389 |
|
390 definition sproc_sfds_remain |
|
391 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
392 where |
|
393 "sproc_sfds_remain ss sf from to ss' \<equiv> |
|
394 (\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> |
|
395 (\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_remain sfds sf from to sfds'))" |
|
396 |
|
397 (* for not many, choose on renamed or not *) |
|
398 definition sproc_sfds_choices |
|
399 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
400 where |
|
401 "sproc_sfds_choices ss sf from to ss' \<equiv> |
|
402 (\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> |
|
403 (\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_choices sfds sf from to sfds'))" |
|
404 |
|
405 (* for many, merge renamed with not renamed *) |
|
406 definition sproc_sfds_both |
|
407 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
408 where |
|
409 "sproc_sfds_both ss sf from to ss' \<equiv> |
|
410 (\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> |
|
411 (\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_both sfds sf from to sfds'))" |
|
412 |
|
413 (* remove (\<forall> sp tag. S_proc sp tag \<in> ss \<longrightarrow> S_proc sp tag \<in> ss'), |
|
414 * cause sfds contains sfs informations *) |
|
415 definition ss_rename_notrelated |
|
416 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
417 where |
|
418 "ss_rename_notrelated ss sf sf' ss' \<equiv> |
|
419 (\<forall> sq. S_msgq sq \<in> ss \<longrightarrow> S_msgq sq \<in> ss') \<and> |
|
420 (\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> (\<exists> sfds'. |
|
421 S_proc (pi,sec,sfds',sshms) tagp \<in> ss'\<and> sfds_rename_notrelated sfds sf sf' sfds')) \<and> |
|
422 (\<forall> sfs sf'' tag. S_file sfs tag \<in> ss \<and> sf'' \<in> sfs \<and> (\<not> sf \<preceq> sf'') \<longrightarrow> (\<exists> sfs'. |
|
423 S_file sfs tag \<in> ss' \<and> sf'' \<in> sfs')) \<and> |
|
424 (\<forall> sf'' tag. S_dir sf'' tag \<in> ss \<and> (\<not> sf \<preceq> sf'') \<longrightarrow> S_dir sf'' tag \<in> ss')" |
|
425 |
|
426 (* rename from to, from should definited renamed if not many *) |
|
427 definition all_descendant_sf_renamed |
|
428 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
429 where |
|
430 "all_descendant_sf_renamed ss sf from to ss' \<equiv> |
|
431 (\<forall> sfs sf' tagf. sf \<preceq> sf' \<and> S_file sfs tagf \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'. |
|
432 S_file sfs' tagf \<in> ss' \<and> file_after_rename from to sf' \<in> sfs' \<and> sf' \<notin> sfs')) \<and> |
|
433 (\<forall> sf' tagf. sf \<preceq> sf' \<and> S_dir sf' tagf \<in> ss \<longrightarrow> S_dir (file_after_rename from to sf') tagf \<in> ss' \<and> S_dir sf' tagf \<notin> ss') \<and> |
|
434 sproc_sfds_renamed ss sf from to ss'" |
|
435 |
|
436 (* not renamed *) |
|
437 definition all_descendant_sf_remain |
|
438 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
439 where |
|
440 "all_descendant_sf_remain ss sf from to ss' \<equiv> |
|
441 (\<forall> sfs sf' tag'. sf \<preceq> sf' \<and> S_file sfs tag' \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'. |
|
442 S_file sfs' tag' \<in> ss \<and> file_after_rename from to sf' \<notin> sfs' \<and> sf' \<in> sfs')) \<and> |
|
443 (\<forall> sf' tag'. sf \<preceq> sf' \<and> S_dir sf' tag' \<in> ss \<longrightarrow> S_dir (file_after_rename from to sf') tag' \<notin> ss' \<and> S_dir sf' tag' \<in> ss') \<and> |
|
444 sproc_sfds_remain ss sf from to ss'" |
|
445 |
|
446 definition all_descendant_sf_choices |
|
447 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
448 where |
|
449 "all_descendant_sf_choices ss sf from to ss' \<equiv> |
|
450 all_descendant_sf_renamed ss sf from to ss' \<or> all_descendant_sf_remain ss sf from to ss'" |
|
451 |
|
452 definition all_descendant_sf_both |
|
453 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
454 where |
|
455 "all_descendant_sf_both ss sf from to ss' \<equiv> |
|
456 (\<forall> sfs sf' tag'. sf \<preceq> sf' \<and> S_file sfs tag' \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'. |
|
457 S_file sfs' tag' \<in> ss \<and> file_after_rename from to sf' \<in> sfs' \<or> sf' \<in> sfs')) \<and> |
|
458 (\<forall> sf' tag'. sf \<preceq> sf' \<and> S_dir sf' tag' \<in> ss \<longrightarrow> |
|
459 S_dir (file_after_rename from to sf') tag' \<in> ss' \<or> S_dir sf' tag' \<in> ss') \<and> |
|
460 sproc_sfds_both ss sf from to ss'" |
|
461 |
|
462 definition ss_renamed_file |
|
463 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
464 where |
|
465 "ss_renamed_file ss sf sf' ss' \<equiv> |
|
466 (if (is_many_sfile sf) |
|
467 then all_descendant_sf_choices ss sf sf sf' ss' |
|
468 else all_descendant_sf_renamed ss sf sf sf' ss')" |
|
469 |
|
470 (* added to the new sfs, are those only under the new sfile *) |
|
471 definition sfs_rename_added |
|
472 :: "t_sfile set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile set \<Rightarrow> bool" |
|
473 where |
|
474 "sfs_rename_added sfs from to sfs' \<equiv> |
|
475 (\<forall> sf'. sf' \<in> sfs' \<and> sf' \<notin> sfs \<longrightarrow> (\<exists> sf. sf \<in> sfs \<and> sf' = file_after_rename from to sf))" |
|
476 |
|
477 (* added to the new sfile, are those only under the new sfile *) |
|
478 definition ss_rename_added |
|
479 :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
480 where |
|
481 "ss_rename_added ss from to ss' \<equiv> |
|
482 (\<forall> pi sec fds fds' shms tagp. S_proc (pi, sec, fds,shms) tagp \<in> ss \<and> |
|
483 S_proc (pi,sec,fds',shms) tagp \<in> ss' \<longrightarrow> sfds_rename_added fds from to fds') \<and> |
|
484 (\<forall> sq. S_msgq sq \<in> ss' \<longrightarrow> S_msgq sq \<in> ss) \<and> |
|
485 (\<forall> sfs sfs' tagf. S_file sfs' tagf \<in> ss' \<and> S_file sfs tagf \<in> ss \<longrightarrow> |
|
486 sfs_rename_added sfs from to sfs') \<and> |
|
487 (\<forall> sf' tagf. S_dir sf' tagf \<in> ss' \<and> S_dir sf' tagf \<notin> ss \<longrightarrow> |
|
488 (\<exists> sf. S_dir sf tagf \<in> ss \<and> sf' = file_after_rename from to sf))" |
|
489 |
|
490 definition sfile_alive :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> bool" |
|
491 where |
|
492 "sfile_alive ss sf \<equiv> (\<exists> sfs tagf. sf \<in> sfs \<and> S_file sfs tagf \<in> ss)" |
|
493 |
|
494 definition sf_alive :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> bool" |
|
495 where |
|
496 "sf_alive ss sf \<equiv> (\<exists> tagd. S_dir sf tagd \<in> ss) \<or> sfile_alive ss sf" |
|
497 |
|
498 (* constrains that the new static state should satisfy *) |
|
499 definition ss_rename:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool" |
|
500 where |
|
501 "ss_rename ss sf sf' ss' \<equiv> |
|
502 ss_rename_notrelated ss sf sf' ss' \<and> |
|
503 ss_renamed_file ss sf sf' ss' \<and> ss_rename_added ss sf sf' ss' \<and> |
|
504 (\<forall> sf''. sf_alive ss sf'' \<and> sf \<prec> sf'' \<longrightarrow> |
|
505 (if (is_many_sfile sf'') |
|
506 then all_descendant_sf_choices ss sf'' sf sf' ss' |
|
507 else all_descendant_sf_both ss sf'' sf sf' ss'))" |
|
508 |
|
509 (* two sfile, the last fname should not be equal *) |
|
510 fun sfile_same_fname:: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool" |
|
511 where |
|
512 "sfile_same_fname ((Init n, sec)#spf) ((Init n', sec')#spf') = (n = n')" |
|
513 | "sfile_same_fname _ _ = False" |
|
514 |
|
515 (* no same init sfile/only sfile in the target-to spf, should be in static_state addmissble check *) |
|
516 definition ss_rename_no_same_fname:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool" |
|
517 where |
|
518 "ss_rename_no_same_fname ss from spf \<equiv> |
|
519 \<not> (\<exists> to. sfile_same_fname from to \<and> parent to = Some spf \<and> sf_alive ss to)" |
|
520 |
|
521 (* is not a function, is a relation (one 2 many) |
|
522 definition update_ss_rename :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state" |
|
523 where |
|
524 "update_ss_rename ss sf sf' \<equiv> if (is_many_sfile sf) |
|
525 then (ss \<union> {S_file (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss} |
|
526 \<union> {S_dir (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss}) |
|
527 else (ss - {S_file sf'' tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss} |
|
528 - {S_dir sf'' tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss}) |
|
529 \<union> {S_file (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss} |
|
530 \<union> {S_dir (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss}" |
|
531 *) |
|
532 *) |
|
533 |
|
534 fun sectxt_of_sproc :: "t_sproc \<Rightarrow> security_context_t" |
|
535 where |
|
536 "sectxt_of_sproc (pi,sec,fds) = sec" |
|
537 |
|
538 fun sectxt_of_sfile :: "t_sfile \<Rightarrow> security_context_t" |
|
539 where |
|
540 "sectxt_of_sfile (fi,sec,psec,asecs) = sec" |
|
541 |
|
542 fun asecs_of_sfile :: "t_sfile \<Rightarrow> security_context_t set" |
|
543 where |
|
544 "asecs_of_sfile (fi,sec,psec,asecs) = asecs" |
|
545 |
|
546 definition search_check_s :: "security_context_t \<Rightarrow> t_sfile \<Rightarrow> bool \<Rightarrow> bool" |
|
547 where |
|
548 "search_check_s pctxt sf if_file = |
|
549 (if if_file |
|
550 then search_check_ctxt pctxt (sectxt_of_sfile sf) (asecs_of_sfile sf) True |
|
551 else search_check_ctxt pctxt (sectxt_of_sfile sf) (asecs_of_sfile sf) False)" |
|
552 |
|
553 definition sectxts_of_sfds :: "t_sfd set \<Rightarrow> security_context_t set" |
|
554 where |
|
555 "sectxts_of_sfds sfds \<equiv> {ctxt. \<exists> flag sf. (ctxt, flag, sf) \<in> sfds}" |
|
556 |
|
557 definition inherit_fds_check_s :: "security_context_t \<Rightarrow> t_sfd set \<Rightarrow> bool" |
|
558 where |
|
559 "inherit_fds_check_s pctxt sfds \<equiv> inherit_fds_check_ctxt pctxt (sectxts_of_sfds sfds)" |
|
560 |
|
561 (* |
|
562 fun smsg_related :: "t_msg \<Rightarrow> t_smsg list \<Rightarrow> bool" |
|
563 where |
|
564 "smsg_related m [] = False" |
|
565 | "smsg_related m ((mi, sec, tag)#sms) = |
|
566 (if (mi = Init m) then True else smsg_related m sms)" |
|
567 |
|
568 fun smsgq_smsg_related :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsgq \<Rightarrow> bool" |
|
569 where |
|
570 "smsgq_smsg_related q m (qi, sec, smsgslist) = ((qi = Init q) \<and> (smsg_related m smsgslist))" |
|
571 |
|
572 fun smsg_relatainted :: "t_msg \<Rightarrow> t_smsg list \<Rightarrow> bool" |
|
573 where |
|
574 "smsg_relatainted m [] = False" |
|
575 | "smsg_relatainted m ((mi, sec, tag)#sms) = |
|
576 (if (mi = Init m \<and> tag = True) then True else smsg_relatainted m sms)" |
|
577 |
|
578 fun smsgq_smsg_relatainted :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsgq \<Rightarrow> bool" |
|
579 where |
|
580 "smsgq_smsg_relatainted q m (qi, sec, smsgslist) = |
|
581 ((qi = Init q) \<and> (smsg_relatainted m smsgslist))" |
|
582 *) |
|
583 |
|
584 fun sfile_related :: "t_sfile \<Rightarrow> t_file \<Rightarrow> bool" |
|
585 where |
|
586 "sfile_related (fi,sec,psec,asecs) f = (fi = Init f)" |
|
587 (* |
|
588 fun sproc_related :: "t_process \<Rightarrow> t_sproc \<Rightarrow> bool" |
|
589 where |
|
590 "sproc_related p (pi, sec, fds, shms) = (pi = Init p)" |
|
591 *) |
|
592 fun init_obj_related :: "t_sobject \<Rightarrow> t_object \<Rightarrow> bool" |
|
593 where |
|
594 "init_obj_related (S_proc (pi, sec, fds) tag) (O_proc p') = (pi = Init p')" |
|
595 | "init_obj_related (S_file sf tag) (O_file f) = (sfile_related sf f)" |
|
596 | "init_obj_related (S_dir sf) (O_dir f) = (sfile_related sf f)" |
|
597 | "init_obj_related (S_msgq (qi, sec, sms)) (O_msgq q') = (qi = Init q')" |
|
598 (* |
|
599 | "init_obj_related (S_msg (qi, sec, sms) (mi, secm, tagm)) (O_msg q' m') = (qi = Init q' \<and> mi = Init m')" |
|
600 *) |
|
601 | "init_obj_related _ _ = False" |
|
602 |
|
603 |
|
604 |
|
605 (***************** for backward proof when Instancing static objects ******************) |
|
606 |
|
607 definition next_nat :: "nat set \<Rightarrow> nat" |
|
608 where |
|
609 "next_nat nset = (Max nset) + 1" |
|
610 |
|
611 definition new_proc :: "t_state \<Rightarrow> t_process" |
|
612 where |
|
613 "new_proc \<tau> = next_nat (current_procs \<tau>)" |
|
614 |
|
615 definition new_inode_num :: "t_state \<Rightarrow> nat" |
|
616 where |
|
617 "new_inode_num \<tau> = next_nat (current_inode_nums \<tau>)" |
|
618 |
|
619 definition new_msgq :: "t_state \<Rightarrow> t_msgq" |
|
620 where |
|
621 "new_msgq s = next_nat (current_msgqs s)" |
|
622 |
|
623 definition new_msg :: "t_state \<Rightarrow> t_msgq \<Rightarrow> nat" |
|
624 where |
|
625 "new_msg s q = next_nat (set (msgs_of_queue s q))" |
|
626 |
|
627 definition new_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd" |
|
628 where |
|
629 "new_proc_fd \<tau> p = next_nat (current_proc_fds \<tau> p)" |
|
630 |
|
631 definition all_fname_under_dir:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname set" |
|
632 where |
|
633 "all_fname_under_dir d \<tau> = {fn. \<exists> f. fn # d = f \<and> f \<in> current_files \<tau>}" |
|
634 |
|
635 fun fname_all_a:: "nat \<Rightarrow> t_fname" |
|
636 where |
|
637 "fname_all_a 0 = []" | |
|
638 "fname_all_a (Suc n) = ''a''@(fname_all_a n)" |
|
639 |
|
640 definition fname_length_set :: "t_fname set \<Rightarrow> nat set" |
|
641 where |
|
642 "fname_length_set fns = length`fns" |
|
643 |
|
644 definition next_fname:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname" |
|
645 where |
|
646 "next_fname pf \<tau> = fname_all_a ((Max (fname_length_set (all_fname_under_dir pf \<tau>))) + 1)" |
|
647 |
|
648 definition new_childf:: "t_file \<Rightarrow> t_state \<Rightarrow> t_file" |
|
649 where |
|
650 "new_childf pf \<tau> = next_fname pf \<tau> # pf" |
|
651 |
|
652 end |
|
653 |
|
654 end |