1
|
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 |
fun init_role_of_obj :: "t_object \<Rightarrow> role_t option"
|
|
10 |
where
|
|
11 |
"init_role_of_obj (O_proc p) = init_role_of_proc p"
|
|
12 |
| "init_role_of_obj _ = Some R_object"
|
|
13 |
|
|
14 |
definition init_sectxt_of_obj :: "t_object \<Rightarrow> security_context_t option"
|
|
15 |
where
|
|
16 |
"init_sectxt_of_obj obj \<equiv>
|
|
17 |
(case (init_user_of_obj obj, init_role_of_obj obj, init_type_of_obj obj) of
|
|
18 |
(Some u, Some r, Some t) \<Rightarrow> Some (u,r,t)
|
|
19 |
| _ \<Rightarrow> None)"
|
|
20 |
|
|
21 |
(*
|
|
22 |
definition init_sectxt_of_file:: "t_file \<Rightarrow> security_context_t option"
|
|
23 |
where
|
|
24 |
"init_sectxt_of_file f \<equiv>
|
|
25 |
if (is_init_file f) then init_sectxt_of_obj (O_file f)
|
|
26 |
else if (is_init_dir f) then init_sectxt_of_obj (O_dir f)
|
|
27 |
else None"
|
|
28 |
*)
|
|
29 |
|
|
30 |
definition sec_of_root :: "security_context_t"
|
|
31 |
where
|
|
32 |
"sec_of_root \<equiv> (case (init_user_of_obj (O_dir []), init_type_of_obj (O_dir [])) of
|
|
33 |
(Some u, Some t) \<Rightarrow> (u, R_object, t))"
|
|
34 |
|
|
35 |
definition sroot :: "t_sfile"
|
|
36 |
where
|
|
37 |
"sroot \<equiv> (Init [], sec_of_root, None, {})"
|
|
38 |
|
|
39 |
definition init_cf2sfile :: "t_file \<Rightarrow> t_sfile option"
|
|
40 |
where
|
|
41 |
"init_cf2sfile f \<equiv>
|
|
42 |
case (parent f) of
|
|
43 |
None \<Rightarrow> Some sroot
|
|
44 |
| Some pf \<Rightarrow> if (is_init_file f) then
|
|
45 |
(case (init_sectxt_of_obj (O_file f), init_sectxt_of_obj (O_dir pf), get_parentfs_ctxts [] pf) of
|
|
46 |
(Some sec, Some psec, Some aseclist) \<Rightarrow> Some (Init f, sec, Some psec, set aseclist)
|
|
47 |
| _ \<Rightarrow> None) else
|
|
48 |
(case (init_sectxt_of_obj (O_dir f), init_sectxt_of_obj (O_dir pf), get_parentfs_ctxts [] pf) of
|
|
49 |
(Some sec, Some psec, Some aseclist) \<Rightarrow> Some (Init f, sec, Some psec, set aseclist)
|
|
50 |
| _ \<Rightarrow> None)"
|
|
51 |
|
|
52 |
definition init_cfs2sfiles :: "t_file set \<Rightarrow> t_sfile set"
|
|
53 |
where
|
2
|
54 |
"init_cfs2sfiles fs \<equiv> {sf. \<exists>f \<in> fs. init_cf2sfile f = Some sf \<and> is_init_file f}"
|
1
|
55 |
|
|
56 |
definition init_cfd2sfd :: "t_process \<Rightarrow> t_fd \<Rightarrow> (security_context_t \<times> t_open_flags \<times> t_sfile) option"
|
|
57 |
where
|
|
58 |
"init_cfd2sfd p fd =
|
|
59 |
(case (init_file_of_proc_fd p fd, init_oflags_of_proc_fd p fd, init_sectxt_of_obj (O_fd p fd)) of
|
|
60 |
(Some f, Some flags, Some sec) \<Rightarrow> (case (init_cf2sfile f) of
|
|
61 |
Some sf \<Rightarrow> Some (sec, flags, sf)
|
|
62 |
| _ \<Rightarrow> None)
|
|
63 |
| _ \<Rightarrow> None)"
|
|
64 |
|
|
65 |
definition init_cfds2sfds :: "t_process \<Rightarrow> (security_context_t \<times> t_open_flags \<times> t_sfile) set"
|
|
66 |
where
|
|
67 |
"init_cfds2sfds p \<equiv> { sfd. \<exists> fd sfd f. init_file_of_proc_fd p fd = Some f \<and> init_cfd2sfd p fd = Some sfd}"
|
|
68 |
|
|
69 |
definition init_ch2sshm :: "t_shm \<Rightarrow> t_sshm option"
|
|
70 |
where
|
|
71 |
"init_ch2sshm h \<equiv> (case (init_sectxt_of_obj (O_shm h)) of
|
|
72 |
Some sec \<Rightarrow> Some (Init h, sec)
|
|
73 |
| _ \<Rightarrow> None)"
|
|
74 |
|
|
75 |
definition init_cph2spshs
|
|
76 |
:: "t_process \<Rightarrow> (t_sshm \<times> t_shm_attach_flag) set"
|
|
77 |
where
|
|
78 |
"init_cph2spshs p \<equiv> {(sh, flag)| sh flag h. (p, flag) \<in> init_procs_of_shm h \<and>
|
|
79 |
init_ch2sshm h = Some sh}"
|
|
80 |
|
|
81 |
definition init_cp2sproc :: "t_process \<Rightarrow> t_sproc option"
|
|
82 |
where
|
|
83 |
"init_cp2sproc p \<equiv> (case (init_sectxt_of_obj (O_proc p)) of
|
|
84 |
Some sec \<Rightarrow> Some (Init p, sec, (init_cfds2sfds p), (init_cph2spshs p))
|
|
85 |
| None \<Rightarrow> None)"
|
|
86 |
|
|
87 |
(* acient files of init-file
|
|
88 |
definition init_o2s_afs :: "t_file \<Rightarrow> security_context_t set"
|
|
89 |
where
|
|
90 |
"init_o2s_afs f \<equiv> {sec. \<exists> f'. f' \<preceq> f \<and> init_sectxt_of_obj (O_dir f') = Some sec}" *)
|
|
91 |
|
|
92 |
definition init_cm2smsg :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsg option"
|
|
93 |
where
|
|
94 |
"init_cm2smsg q m \<equiv> (case (init_sectxt_of_obj (O_msg q m)) of
|
|
95 |
Some sec \<Rightarrow> Some (Init m, sec, (O_msg q m) \<in> seeds)
|
|
96 |
| _ \<Rightarrow> None)"
|
|
97 |
|
|
98 |
fun init_cqm2sms :: "t_msgq \<Rightarrow> t_msg list \<Rightarrow> (t_smsg list) option"
|
|
99 |
where
|
|
100 |
"init_cqm2sms q [] = Some []"
|
|
101 |
| "init_cqm2sms q (m#ms) =
|
|
102 |
(case (init_cqm2sms q ms, init_cm2smsg q m) of
|
|
103 |
(Some sms, Some sm) \<Rightarrow> Some (sm # sms)
|
|
104 |
| _ \<Rightarrow> None)"
|
|
105 |
|
|
106 |
definition init_cq2smsgq :: "t_msgq \<Rightarrow> t_smsgq option"
|
|
107 |
where
|
|
108 |
"init_cq2smsgq q \<equiv> (case (init_sectxt_of_obj (O_msgq q), init_cqm2sms q (init_msgs_of_queue q)) of
|
|
109 |
(Some sec, Some sms) \<Rightarrow> Some (Init q, sec, sms)
|
|
110 |
| _ \<Rightarrow> None)"
|
|
111 |
|
|
112 |
fun init_obj2sobj :: "t_object \<Rightarrow> t_sobject option"
|
|
113 |
where
|
|
114 |
"init_obj2sobj (O_proc p) =
|
|
115 |
(case (init_cp2sproc p) of
|
|
116 |
Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> seeds))
|
|
117 |
| _ \<Rightarrow> None)"
|
|
118 |
| "init_obj2sobj (O_file f) =
|
|
119 |
(if (f \<in> init_files \<and> is_init_file f)
|
|
120 |
then Some (S_file (init_cfs2sfiles (init_same_inode_files f))
|
|
121 |
(\<exists> f'. f' \<in> (init_same_inode_files f) \<and> O_file f \<in> seeds))
|
|
122 |
else None)"
|
|
123 |
| "init_obj2sobj (O_dir f) =
|
|
124 |
(if (is_init_dir f) then
|
|
125 |
(case (init_cf2sfile f) of
|
|
126 |
Some sf \<Rightarrow> Some (S_dir sf)
|
|
127 |
| _ \<Rightarrow> None)
|
|
128 |
else None)"
|
|
129 |
| "init_obj2sobj (O_msgq q) =
|
|
130 |
(case (init_cq2smsgq q) of
|
|
131 |
Some sq \<Rightarrow> Some (S_msgq sq)
|
|
132 |
| _ \<Rightarrow> None)"
|
|
133 |
| "init_obj2sobj (O_shm h) =
|
|
134 |
(case (init_ch2sshm h) of
|
|
135 |
Some sh \<Rightarrow> Some (S_shm sh)
|
|
136 |
| _ \<Rightarrow> None)"
|
|
137 |
| "init_obj2sobj (O_msg q m) =
|
|
138 |
(case (init_cq2smsgq q, init_cm2smsg q m) of
|
|
139 |
(Some sq, Some sm) \<Rightarrow> Some (S_msg sq sm)
|
|
140 |
| _ \<Rightarrow> None)"
|
|
141 |
| "init_obj2sobj _ = None"
|
|
142 |
|
|
143 |
definition
|
|
144 |
"init_static_state \<equiv> {sobj. \<exists> obj. init_alive obj \<and> init_obj2sobj obj = Some sobj}"
|
|
145 |
|
|
146 |
fun is_init_sfile :: "t_sfile \<Rightarrow> bool"
|
|
147 |
where
|
|
148 |
"is_init_sfile (Init _, sec, psec,asec) = True"
|
|
149 |
| "is_init_sfile _ = False"
|
|
150 |
|
|
151 |
fun is_many_sfile :: "t_sfile \<Rightarrow> bool"
|
|
152 |
where
|
|
153 |
"is_many_sfile (Created, sec, psec, asec) = True"
|
|
154 |
| "is_many_sfile _ = False"
|
|
155 |
|
|
156 |
fun is_init_sproc :: "t_sproc \<Rightarrow> bool"
|
|
157 |
where
|
|
158 |
"is_init_sproc (Init p, sec, fds, shms) = True"
|
|
159 |
| "is_init_sproc _ = False"
|
|
160 |
|
|
161 |
fun is_many_sproc :: "t_sproc \<Rightarrow> bool"
|
|
162 |
where
|
|
163 |
"is_many_sproc (Created, sec,fds,shms) = True"
|
|
164 |
| "is_many_sproc _ = False"
|
|
165 |
|
|
166 |
fun is_many_smsg :: "t_smsg \<Rightarrow> bool"
|
|
167 |
where
|
|
168 |
"is_many_smsg (Created,sec,tag) = True"
|
|
169 |
| "is_many_smsg _ = False"
|
|
170 |
|
|
171 |
fun is_many_smsgq :: "t_smsgq \<Rightarrow> bool"
|
|
172 |
where
|
|
173 |
"is_many_smsgq (Created,sec,sms) = (True \<and> (\<forall> sm \<in> (set sms). is_many_smsg sm))"
|
|
174 |
| "is_many_smsgq _ = False"
|
|
175 |
|
|
176 |
fun is_many_sshm :: "t_sshm \<Rightarrow> bool"
|
|
177 |
where
|
|
178 |
"is_many_sshm (Created, sec) = True"
|
|
179 |
| "is_many_sshm _ = False"
|
|
180 |
|
|
181 |
(*
|
|
182 |
fun is_init_sobj :: "t_sobject \<Rightarrow> bool"
|
|
183 |
where
|
|
184 |
"is_init_sobj (S_proc (popt, sec, fds, shms) tag) = (popt \<noteq> None)"
|
|
185 |
| "is_init_sobj (S_file sf tag) = (is_init_sfile sf)"
|
|
186 |
| "is_init_sobj (S_dir sf tag) = (is_init_sfile sf)"
|
|
187 |
| "is_init_sobj (S_msg" *)
|
|
188 |
|
|
189 |
fun is_many :: "t_sobject \<Rightarrow> bool"
|
|
190 |
where
|
|
191 |
"is_many (S_proc (Many, sec, fds, shms) tag) = True"
|
|
192 |
| "is_many (S_file sfs tag) = (\<forall> sf \<in> sfs. is_many_sfile sf)"
|
|
193 |
| "is_many (S_dir sf ) = is_many_sfile sf"
|
|
194 |
| "is_many (S_msgq sq ) = is_many_smsgq sq"
|
|
195 |
| "is_many (S_shm sh ) = is_many_sshm sh"
|
|
196 |
|
|
197 |
(*
|
|
198 |
fun update_ss_sp:: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
|
|
199 |
where
|
|
200 |
"update_ss_sp ss (S_proc sp tag) (S_proc sp' tag') =
|
|
201 |
(if (is_many_sproc sp) then ss \<union> {S_proc sp' tag'}
|
|
202 |
else (ss - {S_proc sp tag}) \<union> {S_proc sp' tag'})"
|
|
203 |
|
|
204 |
fun update_ss_sd:: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
|
|
205 |
where
|
|
206 |
"update_ss_sd ss (S_dir sf tag) (S_dir sf' tag') =
|
|
207 |
(if (is_many_sfile sf) then ss \<union> {S_dir sf' tag'}
|
|
208 |
else (ss - {S_dir sf tag}) \<union> {S_dir sf' tag'})"
|
|
209 |
*)
|
|
210 |
|
|
211 |
definition update_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
|
|
212 |
where
|
|
213 |
"update_ss ss so so' \<equiv> if (is_many so) then ss \<union> {so'} else (ss - {so}) \<union> {so'}"
|
|
214 |
|
|
215 |
definition add_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
|
|
216 |
where
|
|
217 |
"add_ss ss so \<equiv> ss \<union> {so}"
|
|
218 |
|
|
219 |
definition del_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
|
|
220 |
where
|
|
221 |
"del_ss ss so \<equiv> if (is_many so) then ss else ss - {so}"
|
|
222 |
|
|
223 |
(*
|
|
224 |
fun sparent :: "t_sfile \<Rightarrow> t_sfile option"
|
|
225 |
where
|
|
226 |
"sparent (Sroot si sec) = None"
|
|
227 |
| "sparent (Sfile si sec spf) = Some spf"
|
|
228 |
|
|
229 |
inductive is_ancesf :: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool"
|
|
230 |
where
|
|
231 |
"is_ancesf sf sf"
|
|
232 |
| "sparent sf = Some spf \<Longrightarrow> is_ancesf spf sf"
|
|
233 |
| "\<lbrakk>sparent sf = Some spf; is_ancesf saf spf\<rbrakk> \<Longrightarrow> is_ancesf saf sf"
|
|
234 |
|
|
235 |
definition sfile_reparent :: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile"
|
|
236 |
where
|
|
237 |
"sfile_reparent (Sroot)"
|
|
238 |
*)
|
|
239 |
|
|
240 |
(*
|
|
241 |
(* sfds rename aux definitions *)
|
|
242 |
definition sfds_rename_notrelated
|
|
243 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
244 |
where
|
|
245 |
"sfds_rename_notrelated sfds from to sfds' \<equiv>
|
|
246 |
(\<forall> sec flag sf. (sec,flag,sf) \<in> sfds \<and> (\<not> from \<preceq> sf) \<longrightarrow> (sec,flag,sf) \<in> sfds')"
|
|
247 |
|
|
248 |
definition sfds_rename_renamed
|
|
249 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
250 |
where
|
|
251 |
"sfds_rename_renamed sfds sf from to sfds' \<equiv>
|
|
252 |
(\<forall> sec flag sf'. (sec,flag,sf) \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow>
|
|
253 |
(sec, flag, file_after_rename sf' from to) \<in> sfds' \<and> (sec,flag,sf) \<notin> sfds')"
|
|
254 |
|
|
255 |
definition sfds_rename_remain
|
|
256 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
257 |
where
|
|
258 |
"sfds_rename_remain sfds sf from to sfds' \<equiv>
|
|
259 |
(\<forall> sec flag sf'. (sec,flag,sf') \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow>
|
|
260 |
(sec, flag, sf') \<in> sfds' \<and> (sec,flag, file_after_rename sf' from to) \<notin> sfds')"
|
|
261 |
|
|
262 |
(* for not many, choose on renamed or not *)
|
|
263 |
definition sfds_rename_choices
|
|
264 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
265 |
where
|
|
266 |
"sfds_rename_choices sfds sf from to sfds' \<equiv>
|
|
267 |
sfds_rename_remain sfds sf from to sfds' \<or> sfds_rename_renamed sfds sf from to sfds'"
|
|
268 |
|
|
269 |
(* for many, merge renamed with not renamed *)
|
|
270 |
definition sfds_rename_both
|
|
271 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
272 |
where
|
|
273 |
"sfds_rename_both sfds sf from to sfds' \<equiv>
|
|
274 |
(\<forall> sec flag sf'. (sec,flag,sf') \<in> sfds \<and> (sf \<preceq> sf') \<longrightarrow>
|
|
275 |
(sec, flag, sf') \<in> sfds' \<or> (sec,flag, file_after_rename sf' from to) \<in> sfds')"
|
|
276 |
|
|
277 |
(* added to the new sfds, are those only under the new sfile *)
|
|
278 |
definition sfds_rename_added
|
|
279 |
:: "t_sfd set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
280 |
where
|
|
281 |
"sfds_rename_added sfds from to sfds' \<equiv>
|
|
282 |
(\<forall> sec' flag' sf' sec flag. (sec',flag',sf') \<in> sfds' \<and> (sec,flag,sf') \<notin> sfds \<longrightarrow>
|
|
283 |
(\<exists> sf. (sec,flag,sf) \<in> sfds \<and> sf' = file_after_rename from to sf))"
|
|
284 |
|
|
285 |
definition sproc_sfds_renamed
|
|
286 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
287 |
where
|
|
288 |
"sproc_sfds_renamed ss sf from to ss' \<equiv>
|
|
289 |
(\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow>
|
|
290 |
(\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_renamed sfds sf from to sfds'))"
|
|
291 |
|
|
292 |
definition sproc_sfds_remain
|
|
293 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
294 |
where
|
|
295 |
"sproc_sfds_remain ss sf from to ss' \<equiv>
|
|
296 |
(\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow>
|
|
297 |
(\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_remain sfds sf from to sfds'))"
|
|
298 |
|
|
299 |
(* for not many, choose on renamed or not *)
|
|
300 |
definition sproc_sfds_choices
|
|
301 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
302 |
where
|
|
303 |
"sproc_sfds_choices ss sf from to ss' \<equiv>
|
|
304 |
(\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow>
|
|
305 |
(\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_choices sfds sf from to sfds'))"
|
|
306 |
|
|
307 |
(* for many, merge renamed with not renamed *)
|
|
308 |
definition sproc_sfds_both
|
|
309 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
310 |
where
|
|
311 |
"sproc_sfds_both ss sf from to ss' \<equiv>
|
|
312 |
(\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow>
|
|
313 |
(\<exists> sfds'. S_proc (pi,sec,sfds',sshms) tagp \<in> ss \<and> sfds_rename_both sfds sf from to sfds'))"
|
|
314 |
|
|
315 |
(* remove (\<forall> sp tag. S_proc sp tag \<in> ss \<longrightarrow> S_proc sp tag \<in> ss'),
|
|
316 |
* cause sfds contains sfs informations *)
|
|
317 |
definition ss_rename_notrelated
|
|
318 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
319 |
where
|
|
320 |
"ss_rename_notrelated ss sf sf' ss' \<equiv>
|
|
321 |
(\<forall> sq. S_msgq sq \<in> ss \<longrightarrow> S_msgq sq \<in> ss') \<and>
|
|
322 |
(\<forall> pi sec sfds sshms tagp. S_proc (pi,sec,sfds,sshms) tagp \<in> ss \<longrightarrow> (\<exists> sfds'.
|
|
323 |
S_proc (pi,sec,sfds',sshms) tagp \<in> ss'\<and> sfds_rename_notrelated sfds sf sf' sfds')) \<and>
|
|
324 |
(\<forall> sfs sf'' tag. S_file sfs tag \<in> ss \<and> sf'' \<in> sfs \<and> (\<not> sf \<preceq> sf'') \<longrightarrow> (\<exists> sfs'.
|
|
325 |
S_file sfs tag \<in> ss' \<and> sf'' \<in> sfs')) \<and>
|
|
326 |
(\<forall> sf'' tag. S_dir sf'' tag \<in> ss \<and> (\<not> sf \<preceq> sf'') \<longrightarrow> S_dir sf'' tag \<in> ss')"
|
|
327 |
|
|
328 |
(* rename from to, from should definited renamed if not many *)
|
|
329 |
definition all_descendant_sf_renamed
|
|
330 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
331 |
where
|
|
332 |
"all_descendant_sf_renamed ss sf from to ss' \<equiv>
|
|
333 |
(\<forall> sfs sf' tagf. sf \<preceq> sf' \<and> S_file sfs tagf \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'.
|
|
334 |
S_file sfs' tagf \<in> ss' \<and> file_after_rename from to sf' \<in> sfs' \<and> sf' \<notin> sfs')) \<and>
|
|
335 |
(\<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>
|
|
336 |
sproc_sfds_renamed ss sf from to ss'"
|
|
337 |
|
|
338 |
(* not renamed *)
|
|
339 |
definition all_descendant_sf_remain
|
|
340 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
341 |
where
|
|
342 |
"all_descendant_sf_remain ss sf from to ss' \<equiv>
|
|
343 |
(\<forall> sfs sf' tag'. sf \<preceq> sf' \<and> S_file sfs tag' \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'.
|
|
344 |
S_file sfs' tag' \<in> ss \<and> file_after_rename from to sf' \<notin> sfs' \<and> sf' \<in> sfs')) \<and>
|
|
345 |
(\<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>
|
|
346 |
sproc_sfds_remain ss sf from to ss'"
|
|
347 |
|
|
348 |
definition all_descendant_sf_choices
|
|
349 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
350 |
where
|
|
351 |
"all_descendant_sf_choices ss sf from to ss' \<equiv>
|
|
352 |
all_descendant_sf_renamed ss sf from to ss' \<or> all_descendant_sf_remain ss sf from to ss'"
|
|
353 |
|
|
354 |
definition all_descendant_sf_both
|
|
355 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
356 |
where
|
|
357 |
"all_descendant_sf_both ss sf from to ss' \<equiv>
|
|
358 |
(\<forall> sfs sf' tag'. sf \<preceq> sf' \<and> S_file sfs tag' \<in> ss \<and> sf' \<in> sfs \<longrightarrow> (\<exists> sfs'.
|
|
359 |
S_file sfs' tag' \<in> ss \<and> file_after_rename from to sf' \<in> sfs' \<or> sf' \<in> sfs')) \<and>
|
|
360 |
(\<forall> sf' tag'. sf \<preceq> sf' \<and> S_dir sf' tag' \<in> ss \<longrightarrow>
|
|
361 |
S_dir (file_after_rename from to sf') tag' \<in> ss' \<or> S_dir sf' tag' \<in> ss') \<and>
|
|
362 |
sproc_sfds_both ss sf from to ss'"
|
|
363 |
|
|
364 |
definition ss_renamed_file
|
|
365 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
366 |
where
|
|
367 |
"ss_renamed_file ss sf sf' ss' \<equiv>
|
|
368 |
(if (is_many_sfile sf)
|
|
369 |
then all_descendant_sf_choices ss sf sf sf' ss'
|
|
370 |
else all_descendant_sf_renamed ss sf sf sf' ss')"
|
|
371 |
|
|
372 |
(* added to the new sfs, are those only under the new sfile *)
|
|
373 |
definition sfs_rename_added
|
|
374 |
:: "t_sfile set \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_sfile set \<Rightarrow> bool"
|
|
375 |
where
|
|
376 |
"sfs_rename_added sfs from to sfs' \<equiv>
|
|
377 |
(\<forall> sf'. sf' \<in> sfs' \<and> sf' \<notin> sfs \<longrightarrow> (\<exists> sf. sf \<in> sfs \<and> sf' = file_after_rename from to sf))"
|
|
378 |
|
|
379 |
(* added to the new sfile, are those only under the new sfile *)
|
|
380 |
definition ss_rename_added
|
|
381 |
:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
382 |
where
|
|
383 |
"ss_rename_added ss from to ss' \<equiv>
|
|
384 |
(\<forall> pi sec fds fds' shms tagp. S_proc (pi, sec, fds,shms) tagp \<in> ss \<and>
|
|
385 |
S_proc (pi,sec,fds',shms) tagp \<in> ss' \<longrightarrow> sfds_rename_added fds from to fds') \<and>
|
|
386 |
(\<forall> sq. S_msgq sq \<in> ss' \<longrightarrow> S_msgq sq \<in> ss) \<and>
|
|
387 |
(\<forall> sfs sfs' tagf. S_file sfs' tagf \<in> ss' \<and> S_file sfs tagf \<in> ss \<longrightarrow>
|
|
388 |
sfs_rename_added sfs from to sfs') \<and>
|
|
389 |
(\<forall> sf' tagf. S_dir sf' tagf \<in> ss' \<and> S_dir sf' tagf \<notin> ss \<longrightarrow>
|
|
390 |
(\<exists> sf. S_dir sf tagf \<in> ss \<and> sf' = file_after_rename from to sf))"
|
|
391 |
|
|
392 |
definition sfile_alive :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> bool"
|
|
393 |
where
|
|
394 |
"sfile_alive ss sf \<equiv> (\<exists> sfs tagf. sf \<in> sfs \<and> S_file sfs tagf \<in> ss)"
|
|
395 |
|
|
396 |
definition sf_alive :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> bool"
|
|
397 |
where
|
|
398 |
"sf_alive ss sf \<equiv> (\<exists> tagd. S_dir sf tagd \<in> ss) \<or> sfile_alive ss sf"
|
|
399 |
|
|
400 |
(* constrains that the new static state should satisfy *)
|
|
401 |
definition ss_rename:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
402 |
where
|
|
403 |
"ss_rename ss sf sf' ss' \<equiv>
|
|
404 |
ss_rename_notrelated ss sf sf' ss' \<and>
|
|
405 |
ss_renamed_file ss sf sf' ss' \<and> ss_rename_added ss sf sf' ss' \<and>
|
|
406 |
(\<forall> sf''. sf_alive ss sf'' \<and> sf \<prec> sf'' \<longrightarrow>
|
|
407 |
(if (is_many_sfile sf'')
|
|
408 |
then all_descendant_sf_choices ss sf'' sf sf' ss'
|
|
409 |
else all_descendant_sf_both ss sf'' sf sf' ss'))"
|
|
410 |
|
|
411 |
(* two sfile, the last fname should not be equal *)
|
|
412 |
fun sfile_same_fname:: "t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool"
|
|
413 |
where
|
|
414 |
"sfile_same_fname ((Init n, sec)#spf) ((Init n', sec')#spf') = (n = n')"
|
|
415 |
| "sfile_same_fname _ _ = False"
|
|
416 |
|
|
417 |
(* no same init sfile/only sfile in the target-to spf, should be in static_state addmissble check *)
|
|
418 |
definition ss_rename_no_same_fname:: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> bool"
|
|
419 |
where
|
|
420 |
"ss_rename_no_same_fname ss from spf \<equiv>
|
|
421 |
\<not> (\<exists> to. sfile_same_fname from to \<and> parent to = Some spf \<and> sf_alive ss to)"
|
|
422 |
|
|
423 |
(* is not a function, is a relation (one 2 many)
|
|
424 |
definition update_ss_rename :: "t_static_state \<Rightarrow> t_sfile \<Rightarrow> t_sfile \<Rightarrow> t_static_state"
|
|
425 |
where
|
|
426 |
"update_ss_rename ss sf sf' \<equiv> if (is_many_sfile sf)
|
|
427 |
then (ss \<union> {S_file (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss}
|
|
428 |
\<union> {S_dir (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss})
|
|
429 |
else (ss - {S_file sf'' tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss}
|
|
430 |
- {S_dir sf'' tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss})
|
|
431 |
\<union> {S_file (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_file sf'' tag \<in> ss}
|
|
432 |
\<union> {S_dir (file_after_rename sf sf' sf'') tag | sf'' tag. sf \<preceq> sf'' \<and> S_dir sf'' tag \<in> ss}"
|
|
433 |
*)
|
|
434 |
*)
|
|
435 |
|
|
436 |
fun sectxt_of_sproc :: "t_sproc \<Rightarrow> security_context_t"
|
|
437 |
where
|
|
438 |
"sectxt_of_sproc (pi,sec,fds,shms) = sec"
|
|
439 |
|
|
440 |
fun sectxt_of_sfile :: "t_sfile \<Rightarrow> security_context_t"
|
|
441 |
where
|
|
442 |
"sectxt_of_sfile (fi,sec,psec,asecs) = sec"
|
|
443 |
|
|
444 |
fun asecs_of_sfile :: "t_sfile \<Rightarrow> security_context_t set"
|
|
445 |
where
|
|
446 |
"asecs_of_sfile (fi,sec,psec,asecs) = asecs"
|
|
447 |
|
|
448 |
definition search_check_s :: "security_context_t \<Rightarrow> t_sfile \<Rightarrow> bool \<Rightarrow> bool"
|
|
449 |
where
|
|
450 |
"search_check_s pctxt sf if_file =
|
|
451 |
(if if_file
|
|
452 |
then search_check_file pctxt (sectxt_of_sfile sf) \<and> search_check_allp pctxt (asecs_of_sfile sf)
|
|
453 |
else search_check_dir pctxt (sectxt_of_sfile sf) \<and> search_check_allp pctxt (asecs_of_sfile sf))"
|
|
454 |
|
|
455 |
definition sectxts_of_sfds :: "t_sfd set \<Rightarrow> security_context_t set"
|
|
456 |
where
|
|
457 |
"sectxts_of_sfds sfds \<equiv> {ctxt. \<exists> flag sf. (ctxt, flag, sf) \<in> sfds}"
|
|
458 |
|
|
459 |
definition inherit_fds_check_s :: "security_context_t \<Rightarrow> t_sfd set \<Rightarrow> bool"
|
|
460 |
where
|
|
461 |
"inherit_fds_check_s pctxt sfds \<equiv>
|
|
462 |
(\<forall> ctxt \<in> sectxts_of_sfds sfds. permission_check pctxt ctxt C_fd P_inherit)"
|
|
463 |
|
|
464 |
definition sectxts_of_sproc_sshms :: "t_sproc_sshm set \<Rightarrow> security_context_t set"
|
|
465 |
where
|
|
466 |
"sectxts_of_sproc_sshms sshms \<equiv> {ctxt. \<exists> hi flag. ((hi, ctxt),flag) \<in> sshms}"
|
|
467 |
|
|
468 |
definition inherit_shms_check_s :: "security_context_t \<Rightarrow> t_sproc_sshm set \<Rightarrow> bool"
|
|
469 |
where
|
|
470 |
"inherit_shms_check_s pctxt sshms \<equiv>
|
|
471 |
(\<forall> ctxt \<in> sectxts_of_sproc_sshms sshms. permission_check pctxt ctxt C_shm P_inherit)"
|
|
472 |
|
|
473 |
(*
|
|
474 |
fun info_flow_sshm :: "t_sproc \<Rightarrow> t_sproc \<Rightarrow> bool"
|
|
475 |
where
|
|
476 |
"info_flow_sshm (pi,sec,fds,shms) (pi',sec',fds',shms') =
|
|
477 |
(\<exists> sh flag'. (sh, SHM_RDWR) \<in> shms \<and> (sh, flag') \<in> shms')"
|
|
478 |
*)
|
|
479 |
definition info_flow_sproc_sshms :: "t_sproc_sshm set \<Rightarrow> t_sproc_sshm set \<Rightarrow> bool"
|
|
480 |
where
|
|
481 |
"info_flow_sproc_sshms shms shms' \<equiv> (\<exists> sh flag'. (sh, SHM_RDWR) \<in> shms \<and> (sh, flag') \<in> shms')"
|
|
482 |
|
|
483 |
fun info_flow_sshm :: "t_sproc \<Rightarrow> t_sproc \<Rightarrow> bool"
|
|
484 |
where
|
|
485 |
"info_flow_sshm (pi,sec,fds,shms) (pi',sec',fds',shms') = info_flow_sproc_sshms shms shms'"
|
|
486 |
|
|
487 |
definition update_ss_shms :: "t_static_state \<Rightarrow> t_sproc \<Rightarrow> bool \<Rightarrow> t_static_state"
|
|
488 |
where
|
|
489 |
"update_ss_shms ss spfrom tag \<equiv> {sobj. \<exists> sobj' \<in> ss.
|
|
490 |
(case sobj' of
|
|
491 |
S_proc sp tagp \<Rightarrow> if (info_flow_sshm spfrom sp)
|
|
492 |
then if (is_many_sproc sp)
|
|
493 |
then (sobj = S_proc sp tagp \<or> sobj = S_proc sp (tagp \<or> tag))
|
|
494 |
else (sobj = S_proc sp (tagp \<or> tag))
|
|
495 |
else (sobj = S_proc sp tag)
|
|
496 |
| _ \<Rightarrow> sobj = sobj')}"
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
(* all reachable static states(sobjects set) *)
|
|
501 |
inductive_set static :: "t_static_state set"
|
|
502 |
where
|
|
503 |
s_init: "init_static_state \<in> static"
|
|
504 |
| s_execve: "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds, shms) tagp \<in> ss; S_file sfs tagf \<in> ss;
|
|
505 |
(fi,fsec,pfsec,asecs) \<in> sfs; npctxt_execve pctxt fsec = Some pctxt';
|
|
506 |
grant_execve pctxt fsec pctxt'; search_check_s pctxt (fi,fsec,pfsec,asecs) True;
|
|
507 |
inherit_fds_check_s pctxt' fds'; fds' \<subseteq> fds\<rbrakk>
|
|
508 |
\<Longrightarrow> (update_ss ss (S_proc (pi, pctxt, fds, shms) tagp)
|
|
509 |
(S_proc (pi, pctxt', fds', {}) (tagp \<or> tagf))) \<in> static"
|
|
510 |
| s_clone: "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds, shms) tagp \<in> ss;
|
|
511 |
permission_check pctxt pctxt C_process P_fork;
|
|
512 |
inherit_fds_check_s pctxt fds'; fds' \<subseteq> fds;
|
|
513 |
inherit_shms_check_s pctxt shms'; shms' \<subseteq> shms\<rbrakk>
|
|
514 |
\<Longrightarrow> (add_ss ss (S_proc (Created, pctxt, fds', shms') tagp)) \<in> static"
|
|
515 |
| s_kill: "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds, shms) tagp \<in> ss;
|
|
516 |
S_proc (pi', pctxt', fds', shms') tagp' \<in> ss;
|
|
517 |
permission_check pctxt pctxt' C_process P_sigkill\<rbrakk>
|
|
518 |
\<Longrightarrow> (del_ss ss (S_proc (pi', pctxt', fds', shms') tagp')) \<in> static"
|
|
519 |
| s_ptrace: "\<lbrakk>ss \<in> static; S_proc sp tagp \<in> ss; S_proc sp' tagp' \<in> ss;
|
|
520 |
permission_check (sextxt_of_sproc sp) (sectxt_of_sproc sp') C_process P_ptrace\<rbrakk>
|
|
521 |
\<Longrightarrow> (update_ss_shms (update_ss_shms ss sp tagp) sp' tagp') \<in> static"
|
|
522 |
| s_exit: "\<lbrakk>ss \<in> static; S_proc sp tagp \<in> ss\<rbrakk> \<Longrightarrow> (del_ss ss (S_proc sp tagp)) \<in> static"
|
|
523 |
| s_open: "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds, shms) tagp \<in> ss; S_file sfs tagf \<in> ss; sf \<in> sfs;
|
|
524 |
search_check_s pctxt sf True; \<not> is_creat_excl_flag flags;
|
|
525 |
oflags_check flags pctxt (sectxt_of_sfile sf); permission_check pctxt pctxt C_fd P_setattr\<rbrakk>
|
|
526 |
\<Longrightarrow> (update_ss ss (S_proc (pi, pctxt, fds, shms) tagp)
|
|
527 |
(S_proc (pi, pctxt, fds \<union> {(pctxt,flags,sf)}, shms) tagp)) \<in> static"
|
|
528 |
| s_open': "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds, shms) tagp \<in> ss; is_creat_excl_flag flags;
|
|
529 |
S_dir (pfi,fsec,pfsec,asecs) \<in> ss; search_check_s pctxt (pfi,fsec,pfsec,asecs) False;
|
|
530 |
nfsec = nfctxt_create pctxt fsec C_file; oflags_check flags pctxt nfsec;
|
|
531 |
permission_check pctxt fsec C_dir P_add_rename; permission_check pctxt pctxt C_fd P_setattr\<rbrakk>
|
|
532 |
\<Longrightarrow> (update_ss (add_ss ss (S_file {(Created, nfsec, Some fsec, asecs \<union> {fsec})} tagp))
|
|
533 |
(S_proc (pi, pctxt, fds, shms) tagp)
|
|
534 |
(S_proc (pi, pctxt, fds \<union> {(pctxt, flags, (Created, nfsec, Some fsec, asecs \<union> {fsec}))}, shms) tagp)
|
|
535 |
) \<in> static"
|
|
536 |
| S_readf: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; (fdctxt,flags,sf) \<in> fds;
|
|
537 |
permission_check pctxt fdctxt C_fd P_setattr; S_file sfs tagf \<in> ss; sf \<in> sfs;
|
|
538 |
permission_check pctxt (sectxt_of_sfile sf) C_file P_read; is_read_flag flags\<rbrakk>
|
|
539 |
\<Longrightarrow> (update_ss_shms ss (pi, pctxt,fds,shms) (tagp \<or> tagf)) \<in> static"
|
|
540 |
| S_writef: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; (fdctxt,flags,sf) \<in> fds;
|
|
541 |
permission_check pctxt fdctxt C_fd P_setattr; sf \<in> sfs; S_file sfs tagf \<in> ss;
|
|
542 |
permission_check pctxt (sectxt_of_sfile sf) C_file P_write; is_write_flag flags\<rbrakk>
|
|
543 |
\<Longrightarrow> (update_ss ss (S_file sfs tagf) (S_file sfs (tagp \<or> tagf))) \<in> static"
|
|
544 |
| S_unlink: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_file sfs tagf \<in> ss;
|
|
545 |
(Init f,fsec,Some pfsec,asecs) \<in> sfs;
|
|
546 |
search_check_s pctxt (Init f,fsec,Some pfsec,asecs) True;
|
|
547 |
permission_check pctxt fsec C_file P_unlink;
|
|
548 |
permission_check pctxt pfsec C_dir P_remove_name\<rbrakk>
|
|
549 |
\<Longrightarrow> ((ss - {S_file sfs tagf}) \<union> {S_file (sfs - {(Init f,fsec,Some pfsec,asecs)}) tagf}) \<in> static"
|
|
550 |
| S_rmdir: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss;
|
|
551 |
S_dir (fi,fsec,Some pfsec,asecs) \<in> ss;
|
|
552 |
search_check_s pctxt (fi,fsec,Some pfsec,asecs) False;
|
|
553 |
permission_check pctxt fsec C_dir P_rmdir;
|
|
554 |
permission_check pctxt pfsec C_dir P_remove_name\<rbrakk>
|
|
555 |
\<Longrightarrow> (del_ss ss (S_dir (fi,fsec,Some pfsec,asecs))) \<in> static"
|
|
556 |
| S_mkdir: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_dir (fi,fsec,pfsec,asecs) \<in> ss;
|
|
557 |
search_check_s pctxt (fi,fsec,pfsec,asecs) False;
|
|
558 |
permission_check pctxt (nfctxt_create pctxt fsec C_dir) C_dir P_create;
|
|
559 |
permission_check pctxt fsec C_dir P_add_name\<rbrakk>
|
|
560 |
\<Longrightarrow> (add_ss ss (S_dir (Created,nfctxt_create pctxt fsec C_dir,Some fsec,asecs \<union> {fsec}))) \<in> static"
|
|
561 |
| s_link: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_dir (pfi,pfsec,ppfsec,asecs) \<in> ss;
|
|
562 |
S_file sfs tagf \<in> ss; sf \<in> sfs; nfsec = nfctxt_create pctxt pfsec C_file;
|
|
563 |
search_check_s pctxt (pfi,pfsec,ppfsec,asecs) False; search_check_s pctxt sf True;
|
|
564 |
permission_check pctxt (sectxt_of_sfile sf) C_file P_link;
|
|
565 |
permission_check pctxt pfsec C_dir P_add_name\<rbrakk>
|
|
566 |
\<Longrightarrow> (update_ss ss (S_file sfs tagf)
|
|
567 |
(S_file (sfs \<union> {(Created,nfsec,Some pfsec, asecs \<union> {pfsec})}) tagf)) \<in> static"
|
|
568 |
| s_trunc: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_file sfs tagf \<in> ss; sf \<in> sfs;
|
|
569 |
search_check_s pctxt sf True; permission_check pctxt (sectxt_of_sfile sf) C_file P_setattr\<rbrakk>
|
|
570 |
\<Longrightarrow> (update_ss ss (S_file sfs tagf) (S_file sfs (tagf \<or> tagp))) \<in> static"
|
|
571 |
(*
|
|
572 |
| s_rename: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_file sfs tagf \<in> ss;
|
|
573 |
(sf#spf') \<in> sfs; S_dir spf tagpf \<in> ss; \<not>((sf#spf') \<preceq> (sf#spf));
|
|
574 |
search_check_s pctxt spf False; search_check_s pctxt (sf#spf') True;
|
|
575 |
sectxt_of_sfile (sf#spf') = Some fctxt; sectxt_of_sfile spf = Some pfctxt;
|
|
576 |
permission_check pctxt fctxt C_file P_rename;
|
|
577 |
permission_check pctxt pfctxt C_dir P_add_name;
|
|
578 |
ss_rename ss (sf#spf') (sf#spf) ss';
|
|
579 |
ss_rename_no_same_fname ss (sf#spf') (sf#spf)\<rbrakk>
|
|
580 |
\<Longrightarrow> ss' \<in> static"
|
|
581 |
| s_rename': "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_dir (sf#spf') tagf \<in> ss;
|
|
582 |
S_dir spf tagpf \<in> ss; \<not>((sf#spf') \<preceq> (sf#spf));
|
|
583 |
search_check_s pctxt spf False; search_check_s pctxt (sf#spf') True;
|
|
584 |
sectxt_of_sfile (sf#spf') = Some fctxt; sectxt_of_sfile spf = Some pfctxt;
|
|
585 |
permission_check pctxt fctxt C_dir P_reparent;
|
|
586 |
permission_check pctxt pfctxt C_dir P_add_name;
|
|
587 |
ss_rename ss (sf#spf') (sf#spf) ss';
|
|
588 |
ss_rename_no_same_fname ss (sf#spf') (sf#spf)\<rbrakk>
|
|
589 |
\<Longrightarrow> ss' \<in> static"
|
|
590 |
*)
|
|
591 |
| s_createq: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss;
|
|
592 |
permission_check pctxt pctxt C_msgq P_associate;
|
|
593 |
permission_check pctxt pctxt C_msgq P_create\<rbrakk>
|
|
594 |
\<Longrightarrow> (add_ss ss (S_msgq (Created,pctxt,[]))) \<in> static"
|
|
595 |
| s_sendmsg: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_msgq (qi,qctxt,sms) \<in> ss;
|
|
596 |
permission_check pctxt qctxt C_msgq P_enqueue;
|
|
597 |
permission_check pctxt qctxt C_msgq P_write;
|
|
598 |
permission_check pctxt pctxt C_msg P_create\<rbrakk>
|
|
599 |
\<Longrightarrow> (update_ss ss (S_msgq (qi,qctxt,sms))
|
|
600 |
(S_msgq (qi,qctxt,sms @ [(Created, pctxt, tagp)]))) \<in> static"
|
|
601 |
| s_recvmsg: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss;
|
|
602 |
S_msgq (qi,qctxt,(mi,mctxt,tagm)#sms) \<in> ss;
|
|
603 |
permission_check pctxt qctxt C_msgq P_read;
|
|
604 |
permission_check pctxt mctxt C_msg P_receive\<rbrakk>
|
|
605 |
\<Longrightarrow> (update_ss_shms ss (pi,pctxt,fds,shms) (tagp \<or> tagm)) \<in> static"
|
|
606 |
| s_removeq: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_msgq (qi,qctxt,sms) \<in> ss;
|
|
607 |
permission_check pctxt qctxt C_msgq P_destroy\<rbrakk>
|
|
608 |
\<Longrightarrow> (del_ss ss (S_msgq (qi,qctxt,sms))) \<in> static"
|
|
609 |
| s_createh: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss;
|
|
610 |
permission_check pctxt pctxt C_shm P_associate;
|
|
611 |
permission_check pctxt pctxt C_shm P_create\<rbrakk>
|
|
612 |
\<Longrightarrow> (add_ss ss (S_shm (Created, pctxt))) \<in> static"
|
|
613 |
| s_attach: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_shm (hi,hctxt) \<in> ss;
|
|
614 |
if flag = SHM_RDONLY then permission_check pctxt hctxt C_shm P_read
|
|
615 |
else (permission_check pctxt hctxt C_shm P_read \<and>
|
|
616 |
permission_check pctxt hctxt C_shm P_write)\<rbrakk>
|
|
617 |
\<Longrightarrow> (update_ss ss (S_proc (pi,pctxt,fds,shms) tagp)
|
|
618 |
(S_proc (pi,pctxt,fds,shms \<union> {((hi,hctxt),flag)}) tagp)) \<in> static"
|
|
619 |
| s_detach: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_shm sh \<in> ss;
|
|
620 |
(sh,flag) \<in> shms; \<not> is_many_sshm sh\<rbrakk>
|
|
621 |
\<Longrightarrow> (update_ss ss (S_proc (pi,pctxt,fds,shms) tagp)
|
|
622 |
(S_proc (pi,pctxt,fds,shms - {(sh,flag)}) tagp)) \<in> static"
|
|
623 |
| s_deleteh: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_shm (hi,hctxt) \<in> ss;
|
|
624 |
permission_check pctxt hctxt C_shm P_destroy; \<not> is_many_sshm sh\<rbrakk>
|
|
625 |
\<Longrightarrow> (remove_sproc_sshm (del_ss ss (S_shm (hi,hctxt))) (hi,hctxt)) \<in> static"
|
|
626 |
|
|
627 |
(*
|
|
628 |
fun smsg_related :: "t_msg \<Rightarrow> t_smsg list \<Rightarrow> bool"
|
|
629 |
where
|
|
630 |
"smsg_related m [] = False"
|
|
631 |
| "smsg_related m ((mi, sec, tag)#sms) =
|
|
632 |
(if (mi = Init m) then True else smsg_related m sms)"
|
|
633 |
|
|
634 |
fun smsgq_smsg_related :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsgq \<Rightarrow> bool"
|
|
635 |
where
|
|
636 |
"smsgq_smsg_related q m (qi, sec, smsgslist) = ((qi = Init q) \<and> (smsg_related m smsgslist))"
|
|
637 |
|
|
638 |
fun smsg_relatainted :: "t_msg \<Rightarrow> t_smsg list \<Rightarrow> bool"
|
|
639 |
where
|
|
640 |
"smsg_relatainted m [] = False"
|
|
641 |
| "smsg_relatainted m ((mi, sec, tag)#sms) =
|
|
642 |
(if (mi = Init m \<and> tag = True) then True else smsg_relatainted m sms)"
|
|
643 |
|
|
644 |
fun smsgq_smsg_relatainted :: "t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsgq \<Rightarrow> bool"
|
|
645 |
where
|
|
646 |
"smsgq_smsg_relatainted q m (qi, sec, smsgslist) =
|
|
647 |
((qi = Init q) \<and> (smsg_relatainted m smsgslist))"
|
|
648 |
*)
|
|
649 |
|
|
650 |
fun sfile_related :: "t_sfile \<Rightarrow> t_file \<Rightarrow> bool"
|
|
651 |
where
|
|
652 |
"sfile_related (fi,sec,psec,asecs) f = (fi = Init f)"
|
|
653 |
(*
|
|
654 |
fun sproc_related :: "t_process \<Rightarrow> t_sproc \<Rightarrow> bool"
|
|
655 |
where
|
|
656 |
"sproc_related p (pi, sec, fds, shms) = (pi = Init p)"
|
|
657 |
*)
|
|
658 |
fun init_obj_related :: "t_sobject \<Rightarrow> t_object \<Rightarrow> bool"
|
|
659 |
where
|
|
660 |
"init_obj_related (S_proc (Init p, sec, fds, shms) tag) (O_proc p') = (p = p')"
|
|
661 |
| "init_obj_related (S_file sfs tag) (O_file f) = (\<exists> sf \<in> sfs. sfile_related sf f)"
|
|
662 |
| "init_obj_related (S_dir sf) (O_dir f) = (sfile_related sf f)"
|
|
663 |
| "init_obj_related (S_msgq (Init q, sec, sms)) (O_msgq q') = (q = q')"
|
|
664 |
| "init_obj_related (S_shm (Init h, sec)) (O_shm h') = (h = h')"
|
|
665 |
| "init_obj_related (S_msg (Init q, sec, sms) (Init m, secm, tagm)) (O_msg q' m') = (q = q' \<and> m = m')"
|
|
666 |
| "init_obj_related _ _ = False"
|
|
667 |
|
|
668 |
fun tainted_s :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> bool"
|
|
669 |
where
|
|
670 |
"tainted_s ss (S_proc sp tag) = (S_proc sp tag \<in> ss \<and> tag = True)"
|
|
671 |
| "tainted_s ss (S_file sfs tag) = (S_file sfs tag \<in> ss \<and> tag = True)"
|
|
672 |
| "tainted_s ss (S_msg (qi, sec, sms) (mi, secm, tag)) =
|
|
673 |
(S_msgq (qi, sec, sms) \<in> ss \<and> (mi,sec,tag) \<in> set sms \<and> tag = True)"
|
|
674 |
| "tainted_s ss _ = False"
|
|
675 |
|
|
676 |
(*
|
|
677 |
fun tainted_s :: "t_object \<Rightarrow> t_static_state \<Rightarrow> bool"
|
|
678 |
where
|
|
679 |
"tainted_s (O_proc p) ss = (\<exists> sp. S_proc sp True \<in> ss \<and> sproc_related p sp)"
|
|
680 |
| "tainted_s (O_file f) ss = (\<exists> sfs sf. S_file sfs True \<in> ss \<and> sf \<in> sfs \<and> sfile_related f sf)"
|
|
681 |
| "tainted_s (O_msg q m) ss = (\<exists> sq. S_msgq sq \<in> ss \<and> smsgq_smsg_relatainted q m sq)"
|
|
682 |
| "tainted_s _ ss = False"
|
|
683 |
*)
|
|
684 |
|
|
685 |
definition taintable_s :: "t_object \<Rightarrow> bool"
|
|
686 |
where
|
|
687 |
"taintable_s obj \<equiv> \<exists> ss \<in> static. \<exists> sobj. tainted_s ss sobj \<and> init_obj_related sobj obj \<and> init_alive obj"
|
|
688 |
|
|
689 |
definition deletable_s :: "t_object \<Rightarrow> bool"
|
|
690 |
where
|
|
691 |
"deletable_s obj \<equiv> init_alive obj \<and> (\<exists> ss \<in> static. \<forall> sobj \<in> ss. \<not> init_obj_related sobj obj)"
|
|
692 |
|
|
693 |
definition undeletable_s :: "t_object \<Rightarrow> bool"
|
|
694 |
where
|
|
695 |
"undeletable_s obj \<equiv> init_alive obj \<and> (\<forall> ss \<in> static. \<exists> sobj \<in> ss. init_obj_related sobj obj)"
|
|
696 |
|
|
697 |
|
|
698 |
(**************** translation from dynamic to static *******************)
|
|
699 |
|
|
700 |
definition cf2sfile :: "t_state \<Rightarrow> t_file \<Rightarrow> bool \<Rightarrow> t_sfile option"
|
|
701 |
where
|
|
702 |
"cf2sfile s f Is_file \<equiv>
|
|
703 |
case (parent f) of
|
|
704 |
None \<Rightarrow> if Is_file then None else Some sroot
|
|
705 |
| Some pf \<Rightarrow> if Is_file
|
|
706 |
then (case (sectxt_of_obj s (O_file f), sectxt_of_obj s (O_dir pf), get_parentfs_ctxts s pf) of
|
|
707 |
(Some sec, Some psec, Some asecs) \<Rightarrow>
|
|
708 |
Some (if (\<not> deleted (O_file f) s \<and> is_init_file f) then Init f else Created, sec, Some psec, set asecs)
|
|
709 |
| _ \<Rightarrow> None)
|
|
710 |
else (case (sectxt_of_obj s (O_dir f), sectxt_of_obj s (O_dir pf), get_parentfs_ctxts s pf) of
|
|
711 |
(Some sec, Some psec, Some asecs) \<Rightarrow>
|
|
712 |
Some (if (\<not> deleted (O_dir f) s \<and> is_init_dir f) then Init f else Created, sec, Some psec, set asecs)
|
|
713 |
| _ \<Rightarrow> None)"
|
|
714 |
|
|
715 |
definition cfs2sfiles :: "t_state \<Rightarrow> t_file set \<Rightarrow> t_sfile set"
|
|
716 |
where
|
|
717 |
"cfs2sfiles s fs \<equiv> {sf. \<exists> f \<in> fs. cf2sfile s f True = Some sf}"
|
|
718 |
|
|
719 |
(* here cf2sfile is passed with True, because, process' fds are only for files not dirs *)
|
|
720 |
definition cfd2sfd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_sfd option"
|
|
721 |
where
|
|
722 |
"cfd2sfd s p fd \<equiv>
|
|
723 |
(case (file_of_proc_fd s p fd, flags_of_proc_fd s p fd, sectxt_of_obj s (O_fd p fd)) of
|
|
724 |
(Some f, Some flags, Some sec) \<Rightarrow> (case (cf2sfile s f True) of
|
|
725 |
Some sf \<Rightarrow> Some (sec, flags, sf)
|
|
726 |
| _ \<Rightarrow> None)
|
|
727 |
| _ \<Rightarrow> None)"
|
|
728 |
|
|
729 |
|
|
730 |
definition cpfd2sfds :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sfd set"
|
|
731 |
where
|
|
732 |
"cpfd2sfds s p \<equiv> {sfd. \<exists> fd sfd f. file_of_proc_fd s p fd = Some f \<and> cfd2sfd s p fd = Some sfd}"
|
|
733 |
|
|
734 |
definition ch2sshm :: "t_state \<Rightarrow> t_shm \<Rightarrow> t_sshm option"
|
|
735 |
where
|
|
736 |
"ch2sshm s h \<equiv> (case (sectxt_of_obj s (O_shm h)) of
|
|
737 |
Some sec \<Rightarrow>
|
|
738 |
Some (if (\<not> deleted (O_shm h) s \<and> h \<in> init_shms) then Init h else Created, sec)
|
|
739 |
| _ \<Rightarrow> None)"
|
|
740 |
|
|
741 |
definition cph2spshs :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sproc_sshm set"
|
|
742 |
where
|
|
743 |
"cph2spshs s p \<equiv> {(sh, flag) | sh flag h. (p, flag) \<in> procs_of_shm s h \<and> ch2sshm s h = Some sh}"
|
|
744 |
|
|
745 |
definition cp2sproc :: "t_state \<Rightarrow> t_process \<Rightarrow> t_sproc option"
|
|
746 |
where
|
|
747 |
"cp2sproc s p \<equiv> (case (sectxt_of_obj s (O_proc p)) of
|
|
748 |
Some sec \<Rightarrow>
|
|
749 |
Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) then Init p else Created, sec,
|
|
750 |
cpfd2sfds s p, cph2spshs s p)
|
|
751 |
| _ \<Rightarrow> None)"
|
|
752 |
|
|
753 |
definition cm2smsg :: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_msg \<Rightarrow> t_smsg option"
|
|
754 |
where
|
|
755 |
"cm2smsg s q m \<equiv> (case (sectxt_of_obj s (O_msg q m)) of
|
|
756 |
Some sec \<Rightarrow>
|
|
757 |
Some (if (\<not> deleted (O_msg q m) s \<and> m \<in> set (init_msgs_of_queue q)) then Init m else Created,
|
|
758 |
sec, O_msg q m \<in> tainted s)
|
|
759 |
| _ \<Rightarrow> None)"
|
|
760 |
|
|
761 |
fun cqm2sms:: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_msg list \<Rightarrow> (t_smsg list) option"
|
|
762 |
where
|
|
763 |
"cqm2sms s q [] = Some []"
|
|
764 |
| "cqm2sms s q (m#ms) =
|
|
765 |
(case (cqm2sms s q ms, cm2smsg s q m) of
|
|
766 |
(Some sms, Some sm) \<Rightarrow> Some (sm#sms)
|
|
767 |
| _ \<Rightarrow> None)"
|
|
768 |
|
|
769 |
definition cq2smsgq :: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_smsgq option"
|
|
770 |
where
|
|
771 |
"cq2smsgq s q \<equiv> (case (sectxt_of_obj s (O_msgq q), cqm2sms s q (msgs_of_queue s q)) of
|
|
772 |
(Some sec, Some sms) \<Rightarrow>
|
|
773 |
Some (if (\<not> deleted (O_msgq q) s \<and> q \<in> init_msgqs) then Init q else Created,
|
|
774 |
sec, sms)
|
|
775 |
| _ \<Rightarrow> None)"
|
|
776 |
|
|
777 |
fun co2sobj :: "t_state \<Rightarrow> t_object \<Rightarrow> t_sobject option"
|
|
778 |
where
|
|
779 |
"co2sobj s (O_proc p) =
|
|
780 |
(case (cp2sproc s p) of
|
|
781 |
Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> tainted s))
|
|
782 |
| _ \<Rightarrow> None)"
|
|
783 |
| "co2sobj s (O_file f) =
|
|
784 |
(if (f \<in> current_files s) then
|
|
785 |
Some (S_file (cfs2sfiles s (same_inode_files s f)) (O_file f \<in> tainted s))
|
|
786 |
else None)"
|
|
787 |
| "co2sobj s (O_dir f) =
|
|
788 |
(case (cf2sfile s f False) of
|
|
789 |
Some sf \<Rightarrow> Some (S_dir sf)
|
|
790 |
| _ \<Rightarrow> None)"
|
|
791 |
| "co2sobj s (O_msgq q) =
|
|
792 |
(case (cq2smsgq s q) of
|
|
793 |
Some sq \<Rightarrow> Some (S_msgq sq)
|
|
794 |
| _ \<Rightarrow> None)"
|
|
795 |
| "co2sobj s (O_shm h) =
|
|
796 |
(case (ch2sshm s h) of
|
|
797 |
Some sh \<Rightarrow> Some (S_shm sh)
|
|
798 |
| _ \<Rightarrow> None)"
|
|
799 |
| "co2sobj s (O_msg q m) =
|
|
800 |
(case (cq2smsgq s q, cm2smsg s q m) of
|
|
801 |
(Some sq, Some sm) \<Rightarrow> Some (S_msg sq sm)
|
|
802 |
| _ \<Rightarrow> None)"
|
|
803 |
| "co2sobj s _ = None"
|
|
804 |
|
|
805 |
|
|
806 |
(***************** for backward proof when Instancing static objects ******************)
|
|
807 |
|
|
808 |
definition next_nat :: "nat set \<Rightarrow> nat"
|
|
809 |
where
|
|
810 |
"next_nat nset = (Max nset) + 1"
|
|
811 |
|
|
812 |
definition new_proc :: "t_state \<Rightarrow> t_process"
|
|
813 |
where
|
|
814 |
"new_proc \<tau> = next_nat (current_procs \<tau>)"
|
|
815 |
|
|
816 |
definition new_inode_num :: "t_state \<Rightarrow> nat"
|
|
817 |
where
|
|
818 |
"new_inode_num \<tau> = next_nat (current_inode_nums \<tau>)"
|
|
819 |
|
|
820 |
definition new_msgq :: "t_state \<Rightarrow> t_msgq"
|
|
821 |
where
|
|
822 |
"new_msgq s = next_nat (current_msgqs s)"
|
|
823 |
|
|
824 |
definition new_msg :: "t_state \<Rightarrow> t_msgq \<Rightarrow> nat"
|
|
825 |
where
|
|
826 |
"new_msg s q = next_nat (set (msgs_of_queue s q))"
|
|
827 |
|
|
828 |
definition new_shm :: "t_state \<Rightarrow> nat"
|
|
829 |
where
|
|
830 |
"new_shm \<tau> = next_nat (current_shms \<tau>)"
|
|
831 |
|
|
832 |
definition new_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd"
|
|
833 |
where
|
|
834 |
"new_proc_fd \<tau> p = next_nat (current_proc_fds \<tau> p)"
|
|
835 |
|
|
836 |
definition all_fname_under_dir:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname set"
|
|
837 |
where
|
|
838 |
"all_fname_under_dir d \<tau> = {fn. \<exists> f. fn # d = f \<and> f \<in> current_files \<tau>}"
|
|
839 |
|
|
840 |
fun fname_all_a:: "nat \<Rightarrow> t_fname"
|
|
841 |
where
|
|
842 |
"fname_all_a 0 = []" |
|
|
843 |
"fname_all_a (Suc n) = ''a''@(fname_all_a n)"
|
|
844 |
|
|
845 |
definition fname_length_set :: "t_fname set \<Rightarrow> nat set"
|
|
846 |
where
|
|
847 |
"fname_length_set fns = length`fns"
|
|
848 |
|
|
849 |
definition next_fname:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname"
|
|
850 |
where
|
|
851 |
"next_fname pf \<tau> = fname_all_a ((Max (fname_length_set (all_fname_under_dir pf \<tau>))) + 1)"
|
|
852 |
|
|
853 |
definition new_childf:: "t_file \<Rightarrow> t_state \<Rightarrow> t_file"
|
|
854 |
where
|
|
855 |
"new_childf pf \<tau> = next_fname pf \<tau> # pf"
|
|
856 |
|
|
857 |
definition s2ss :: "t_state \<Rightarrow> t_static_state"
|
|
858 |
where
|
|
859 |
"s2ss s \<equiv> {sobj. \<exists> obj. alive s obj \<and> co2sobj s obj = Some sobj}"
|
|
860 |
|
|
861 |
end
|
|
862 |
|
|
863 |
end |