author | chunhan |
Tue, 07 Jan 2014 22:04:06 +0800 | |
changeset 90 | 003cac7b8bf5 |
parent 78 | 030643fab8a1 |
permissions | -rwxr-xr-x |
1 | 1 |
theory Flask |
2 |
imports Main Flask_type OS_type_def File_renaming |
|
3 |
begin |
|
4 |
||
5 |
(****** Policy-language-level rule match/auxiliary functions ******) |
|
6 |
||
7 |
fun patt_match :: "'a patt \<Rightarrow> 'a \<Rightarrow> bool" |
|
8 |
where |
|
9 |
"patt_match (Single x) y = (x = y)" |
|
10 |
| "patt_match (Set s) x = (x \<in> s)" |
|
11 |
| "patt_match (Tilde s) x = (x \<notin> s)" |
|
12 |
| "patt_match Asterisk x = True" |
|
13 |
||
14 |
(* match a target with a patt, but including the SELF special |
|
15 |
* patt_match_self patt target source |
|
16 |
*) |
|
17 |
fun patt_match_self :: "(type_t patt) target_with_self_t \<Rightarrow> type_t \<Rightarrow> type_t \<Rightarrow> bool" |
|
18 |
where |
|
19 |
"patt_match_self Self tt st = (tt = st)" |
|
20 |
| "patt_match_self (Not_self (Single p)) tt st = (tt = p)" |
|
21 |
| "patt_match_self (Not_self (Set p)) tt st = (tt \<in> p)" |
|
22 |
| "patt_match_self (Not_self (Tilde p)) tt st = (tt \<notin> p)" |
|
23 |
| "patt_match_self (Not_self Asterisk) tt st = True" |
|
24 |
||
25 |
(* list lookup: find the first one *) |
|
26 |
fun lookup :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a option" |
|
27 |
where |
|
28 |
"lookup [] P = None" |
|
29 |
| "lookup (x # xs) P = (if (P x) then Some x else lookup xs P)" |
|
30 |
||
31 |
(* list member: if exists an element satisfy predicate P *) |
|
32 |
fun member :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" |
|
33 |
where |
|
34 |
"member [] P = False" |
|
35 |
| "member (x # xs) P = (if (P x) then True else member xs P)" |
|
36 |
||
37 |
(******* socket related aux functions ********) |
|
38 |
fun is_remote_request :: "t_event \<Rightarrow> bool" |
|
39 |
where |
|
40 |
"is_remote_request (Accept p fd addr port fd' i) = True" |
|
41 |
| "is_remote_request (Connect p fd addr) = True" |
|
42 |
| "is_remote_request (SendSock p fd) = True" |
|
43 |
| "is_remote_request (RecvSock p fd) = True" |
|
44 |
| "is_remote_request e = False" |
|
45 |
||
46 |
fun ip_of_addr:: "t_sock_addr \<Rightarrow> t_inet_addr" |
|
47 |
where |
|
48 |
"ip_of_addr (INET_ADDR saddr sport) = saddr" |
|
49 |
||
50 |
fun port_of_addr:: "t_sock_addr \<Rightarrow> t_socket_port" |
|
51 |
where |
|
52 |
"port_of_addr (INET_ADDR saddr sport) = sport" |
|
53 |
||
54 |
fun after_bind:: "t_sock_state option \<Rightarrow> bool" |
|
55 |
where |
|
56 |
"after_bind None = False" |
|
57 |
| "after_bind (Some SS_create) = False" |
|
58 |
| "after_bind _= True" (* after bind , it should have local addr *) |
|
59 |
||
60 |
fun after_conacc:: "t_sock_state option \<Rightarrow> bool" |
|
61 |
where |
|
62 |
"after_conacc None = False" |
|
63 |
| "after_conacc (Some SS_create) = False" |
|
64 |
| "after_conacc (Some SS_bind) = False" |
|
65 |
| "after_conacc (Some SS_listen) = False" |
|
66 |
| "after_conacc _ = True" (* after connect or accept, it should have remote addr *) |
|
67 |
||
68 |
(* inet_addr_compare addr1 addr2 \<equiv> addr1 \<le> addr2; but in \<le>'s def,there is a \<exists>, is not a function*) |
|
69 |
fun subnet_addr :: "t_inet_addr \<Rightarrow> t_inet_addr \<Rightarrow> bool" |
|
70 |
where |
|
71 |
"subnet_addr [] addr = True" |
|
72 |
| "subnet_addr (x#xs) [] = False" |
|
73 |
| "subnet_addr (x#xs) (y#ys) = ((x = y) \<and> subnet_addr xs ys)" |
|
74 |
||
75 |
definition port_in_range :: "t_socket_port \<Rightarrow> t_socket_port \<Rightarrow> t_socket_port \<Rightarrow> bool" |
|
76 |
where |
|
77 |
"port_in_range minp maxp p \<equiv> ((p < maxp \<or> p = maxp) \<and> (p > minp \<or> p = minp))" |
|
78 |
||
79 |
(* initial value of initiate state constrains aux function *) |
|
80 |
definition bidirect_in_init :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> bool" |
|
81 |
where |
|
82 |
"bidirect_in_init S f \<equiv> (\<forall> a. a \<in> S \<longrightarrow> (\<exists> b. f a = Some b)) \<and> |
|
83 |
(\<forall> a b. f a = Some b \<longrightarrow> a \<in> S)" |
|
84 |
||
85 |
fun is_file_itag :: "t_inode_tag \<Rightarrow> bool" |
|
86 |
where |
|
87 |
"is_file_itag Tag_FILE = True" |
|
88 |
| "is_file_itag tag = False" |
|
89 |
||
90 |
fun is_dir_itag :: "t_inode_tag \<Rightarrow> bool" |
|
91 |
where |
|
92 |
"is_dir_itag Tag_DIR = True" |
|
93 |
| "is_dir_itag tag = False" |
|
94 |
||
95 |
fun is_file_dir_itag :: "t_inode_tag \<Rightarrow> bool" |
|
96 |
where |
|
97 |
"is_file_dir_itag Tag_FILE = True" |
|
98 |
| "is_file_dir_itag Tag_DIR = True" |
|
99 |
| "is_file_dir_itag tag = False" |
|
100 |
||
101 |
fun is_tcp_itag :: "t_inode_tag \<Rightarrow> bool" |
|
102 |
where |
|
103 |
"is_tcp_itag Tag_TCP_SOCK = True" |
|
104 |
| "is_tcp_itag tag = False" |
|
105 |
||
106 |
fun is_udp_itag :: "t_inode_tag \<Rightarrow> bool" |
|
107 |
where |
|
108 |
"is_udp_itag Tag_UDP_SOCK = True" |
|
109 |
| "is_udp_itag tag = False" |
|
110 |
||
111 |
fun is_sock_itag :: "t_inode_tag \<Rightarrow> bool" |
|
112 |
where |
|
113 |
"is_sock_itag Tag_TCP_SOCK = True" |
|
114 |
| "is_sock_itag Tag_UDP_SOCK = True" |
|
115 |
| "is_sock_itag tag = False" |
|
116 |
||
117 |
||
118 |
locale init = |
|
119 |
fixes |
|
120 |
init_files :: "t_file set" |
|
121 |
and init_procs :: "t_process set" |
|
122 |
and init_nodes :: "t_node set" |
|
123 |
and init_sockets :: "t_socket set" |
|
124 |
and init_users :: "user_t set" |
|
125 |
||
126 |
and init_file_of_proc_fd :: "t_process \<Rightarrow> t_fd \<rightharpoonup> t_file" |
|
127 |
and init_fds_of_proc :: "t_process \<Rightarrow> t_fd set" |
|
128 |
and init_oflags_of_proc_fd:: "t_process \<Rightarrow> t_fd \<rightharpoonup> t_open_flags" |
|
129 |
and init_inum_of_file :: "t_file \<rightharpoonup> t_inode_num" |
|
130 |
and init_inum_of_socket:: "t_socket \<rightharpoonup> t_inode_num" |
|
131 |
and init_itag_of_inum:: "t_inode_num \<rightharpoonup> t_inode_tag" |
|
132 |
and init_files_hung_by_del :: "t_file set" |
|
133 |
(* |
|
134 |
and init_file_at_writing_by:: "t_file \<Rightarrow> (t_process \<times> t_fd) set" |
|
135 |
*) |
|
136 |
and init_socket_state :: "t_socket \<rightharpoonup> t_sock_state" |
|
137 |
||
138 |
and init_msgqs :: "t_msgq set" |
|
139 |
and init_msgs_of_queue:: "t_msgq \<Rightarrow> t_msg list" |
|
140 |
and init_shms :: "t_shm set" |
|
141 |
and init_procs_of_shm :: "t_shm \<Rightarrow> (t_process \<times> t_shm_attach_flag) set" |
|
15 | 142 |
and init_flag_of_proc_shm :: "t_process \<Rightarrow> t_shm \<rightharpoonup> t_shm_attach_flag" |
1 | 143 |
|
144 |
assumes |
|
145 |
parent_file_in_init: "\<And> f pf. \<lbrakk>parent f = Some pf; f \<in> init_files\<rbrakk> \<Longrightarrow> pf \<in> init_files" |
|
146 |
and root_is_dir: "\<exists> i. init_inum_of_file [] = Some i \<and> init_itag_of_inum i = Some Tag_DIR" |
|
147 |
and init_file_has_inum: "\<And> f. f \<in> init_files \<Longrightarrow> \<exists> im. init_inum_of_file f = Some im" |
|
148 |
and inof_has_file_tag: "\<And> f im. init_inum_of_file f = Some im \<Longrightarrow> f \<in> init_files \<and> (\<exists> tag. init_itag_of_inum im = Some tag \<and> is_file_dir_itag tag)" |
|
149 |
and init_file_no_son: "\<And> f im. \<lbrakk>init_inum_of_file f = Some im; init_itag_of_inum im = Some Tag_FILE\<rbrakk> \<Longrightarrow> \<not> (\<exists> f' \<in> init_files. parent f' = Some f)" |
|
150 |
and init_parentf_is_dir: "\<And> f pf im. \<lbrakk>parent f = Some pf; f \<in> init_files; init_inum_of_file pf = Some im\<rbrakk> \<Longrightarrow> init_itag_of_inum im = Some Tag_DIR" |
|
151 |
||
152 |
and init_files_hung_valid: "\<And> f. f \<in> init_files_hung_by_del \<Longrightarrow> f \<in> init_files \<and> (\<exists> p fd. init_file_of_proc_fd p fd = Some f)" |
|
153 |
and init_files_hung_valid': "\<And> f im. \<lbrakk>f \<in> init_files_hung_by_del; init_inum_of_file f = Some im\<rbrakk> \<Longrightarrow> |
|
154 |
init_itag_of_inum im = Some Tag_FILE \<or> (init_itag_of_inum im = Some Tag_DIR \<and> \<not> (\<exists> f'. f' \<in> init_files \<and> f \<prec> f'))" |
|
155 |
||
156 |
and init_procfds_valid: "\<And> p fd. fd \<in> init_fds_of_proc p \<Longrightarrow> p \<in> init_procs \<and> ((\<exists> f \<in> init_files. init_file_of_proc_fd p fd = Some f) \<or> (p, fd) \<in> init_sockets)" |
|
70 | 157 |
and init_filefd_valid: "\<And> p fd f. init_file_of_proc_fd p fd = Some f \<Longrightarrow> fd \<in> init_fds_of_proc p \<and> (\<exists> im. init_inum_of_file f = Some im \<and> init_itag_of_inum im = Some Tag_FILE) \<and> p \<in> init_procs \<and> (\<exists> flags. init_oflags_of_proc_fd p fd = Some flags) \<and> (p, fd) \<notin> init_sockets" |
1 | 158 |
and init_fileflag_valid: "\<And> p fd flags. init_oflags_of_proc_fd p fd = Some flags \<Longrightarrow> \<exists> f. init_file_of_proc_fd p fd = Some f" |
159 |
||
15 | 160 |
and init_procs_has_shm: "\<And> p h flag. (p,flag) \<in> init_procs_of_shm h \<Longrightarrow> p \<in> init_procs \<and> h \<in> init_shms \<and> init_flag_of_proc_shm p h = Some flag" |
161 |
and init_shmflag_has_proc: "\<And> p h flag. init_flag_of_proc_shm p h = Some flag \<Longrightarrow> (p, flag) \<in> init_procs_of_shm h" |
|
1 | 162 |
and init_msgs_distinct: "\<And> q. distinct (init_msgs_of_queue q)" |
4 | 163 |
and init_msgs_valid: "\<And> m q. m \<in> set (init_msgs_of_queue q) \<Longrightarrow> q \<in> init_msgqs" |
1 | 164 |
|
70 | 165 |
and init_socket_has_inode: "\<And> p fd. (p, fd) \<in> init_sockets \<Longrightarrow> \<exists> im. init_inum_of_socket (p, fd) = Some im \<and> p \<in> init_procs \<and> fd \<in> init_fds_of_proc p \<and> init_file_of_proc_fd p fd = None" |
1 | 166 |
and inos_has_sock_tag: "\<And> s im. init_inum_of_socket s = Some im \<Longrightarrow> s \<in> init_sockets \<and> (\<exists> tag. init_itag_of_inum im = Some tag \<and> is_sock_itag tag)" |
167 |
(* |
|
168 |
and init_netobj_has_state: "bidirect_in_init init_netobjs init_netobj_state" |
|
169 |
and init_netobj_has_socktype:"bidirect_in_init init_netobjs init_netobj_socktype" |
|
170 |
and init_netobj_has_laddr: "\<And> s. after_bind (init_netobj_state s) \<Longrightarrow> init_netobj_localaddr s \<noteq> None" |
|
171 |
and init_netobj_has_raddr: "\<And> s. after_conacc (init_netobj_state s) \<Longrightarrow> init_netobj_remoteaddr s \<noteq> None" |
|
172 |
*) |
|
173 |
||
174 |
and init_finite_sets: "finite init_files \<and> finite init_procs \<and> (\<forall> p. finite (init_fds_of_proc p)) \<and> finite init_shms \<and> finite init_msgqs \<and> finite init_users" |
|
175 |
||
176 |
begin |
|
177 |
||
178 |
definition is_init_file:: "t_file \<Rightarrow> bool" |
|
179 |
where |
|
180 |
"is_init_file f \<equiv> (case (init_inum_of_file f) of |
|
181 |
Some i \<Rightarrow> (case (init_itag_of_inum i) of |
|
182 |
Some Tag_FILE \<Rightarrow> True |
|
183 |
| _ \<Rightarrow> False) |
|
184 |
| _ \<Rightarrow> False)" |
|
185 |
||
186 |
definition is_init_dir:: "t_file \<Rightarrow> bool" |
|
187 |
where |
|
188 |
"is_init_dir f \<equiv> (case (init_inum_of_file f) of |
|
189 |
Some i \<Rightarrow> (case (init_itag_of_inum i) of |
|
190 |
Some Tag_DIR \<Rightarrow> True |
|
191 |
| _ \<Rightarrow> False) |
|
192 |
| _ \<Rightarrow> False)" |
|
193 |
||
194 |
definition is_init_tcp_sock:: "t_socket \<Rightarrow> bool" |
|
195 |
where |
|
196 |
"is_init_tcp_sock s \<equiv> (case (init_inum_of_socket s) of |
|
197 |
Some i \<Rightarrow> (case (init_itag_of_inum i) of |
|
198 |
Some Tag_TCP_SOCK \<Rightarrow> True |
|
199 |
| _ \<Rightarrow> False) |
|
200 |
| _ \<Rightarrow> False)" |
|
201 |
||
202 |
definition is_init_udp_sock:: "t_socket \<Rightarrow> bool" |
|
203 |
where |
|
204 |
"is_init_udp_sock s \<equiv> (case (init_inum_of_socket s) of |
|
205 |
Some i \<Rightarrow> (case (init_itag_of_inum i) of |
|
206 |
Some Tag_UDP_SOCK \<Rightarrow> True |
|
207 |
| _ \<Rightarrow> False) |
|
208 |
| _ \<Rightarrow> False)" |
|
209 |
||
2 | 210 |
definition init_same_inode_files :: "t_file \<Rightarrow> t_file set" |
211 |
where |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
212 |
"init_same_inode_files f \<equiv> if is_init_file f then {f'. init_inum_of_file f = init_inum_of_file f'} else {}" |
2 | 213 |
|
1 | 214 |
fun init_alive :: "t_object \<Rightarrow> bool" |
215 |
where |
|
216 |
"init_alive (O_proc p) = (p \<in> init_procs)" |
|
217 |
| "init_alive (O_file f) = (is_init_file f)" |
|
218 |
| "init_alive (O_dir f) = (is_init_dir f)" |
|
219 |
| "init_alive (O_fd p fd) = (fd \<in> init_fds_of_proc p)" |
|
220 |
| "init_alive (O_node n) = (n \<in> init_nodes)" |
|
221 |
| "init_alive (O_tcp_sock k) = (is_init_tcp_sock k)" |
|
222 |
| "init_alive (O_udp_sock k) = (is_init_udp_sock k)" |
|
223 |
| "init_alive (O_shm h) = (h \<in> init_shms)" |
|
224 |
| "init_alive (O_msgq q) = (q \<in> init_msgqs)" |
|
225 |
| "init_alive (O_msg q m) = (m \<in> set (init_msgs_of_queue q) \<and> q \<in> init_msgqs)" |
|
226 |
||
227 |
||
228 |
(************ system listeners, event-related ***********) |
|
229 |
||
230 |
fun file_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_file option" |
|
231 |
where |
|
232 |
"file_of_proc_fd [] p' fd' = (init_file_of_proc_fd p' fd')" |
|
233 |
| "file_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' = |
|
234 |
(if (p' = p \<and> fd = fd') then Some f else file_of_proc_fd \<tau> p' fd')" |
|
235 |
| "file_of_proc_fd (CloseFd p fd # \<tau>) p' fd' = |
|
236 |
(if (p = p' \<and> fd = fd') then None else file_of_proc_fd \<tau> p' fd')" |
|
237 |
(*deleted: if (f\<^isub>3 \<preceq> f\<^isub>1) then None else *) |
|
238 |
(* |
|
239 |
| "file_of_proc_fd (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) p' fd = |
|
240 |
(case (file_of_proc_fd \<tau> p' fd) of |
|
241 |
Some f\<^isub>1 \<Rightarrow> (if (f\<^isub>2 \<preceq> f\<^isub>1) then Some (file_after_rename f\<^isub>2 f\<^isub>3 f\<^isub>1) |
|
242 |
else Some f\<^isub>1) |
|
243 |
| None \<Rightarrow> None )" |
|
244 |
*) |
|
245 |
| "file_of_proc_fd (Execve p f fds # \<tau>) p' fd = |
|
246 |
(if (p' = p \<and> fd \<in> fds) then file_of_proc_fd \<tau> p fd |
|
247 |
else if (p' = p) then None |
|
248 |
else file_of_proc_fd \<tau> p' fd) " |
|
249 |
| "file_of_proc_fd (Clone p p' fds shms # \<tau>) p'' fd = |
|
250 |
(if (p'' = p' \<and> fd \<in> fds) then file_of_proc_fd \<tau> p fd |
|
251 |
else if (p'' = p') then None |
|
252 |
else file_of_proc_fd \<tau> p'' fd)" |
|
253 |
| "file_of_proc_fd (Kill p\<^isub> p\<^isub>' # \<tau>) p'' fd = |
|
254 |
(if (p'' = p\<^isub>') then None else file_of_proc_fd \<tau> p'' fd)" |
|
255 |
| "file_of_proc_fd (Exit p # \<tau>) p' fd = |
|
256 |
(if (p = p') then None else file_of_proc_fd \<tau> p' fd)" |
|
257 |
| "file_of_proc_fd (_ # \<tau>) p fd = file_of_proc_fd \<tau> p fd" |
|
258 |
||
259 |
definition proc_fd_of_file :: "t_state \<Rightarrow> t_file \<Rightarrow> (t_process \<times> t_fd) set" |
|
260 |
where |
|
261 |
"proc_fd_of_file \<tau> f = {(p, fd) | p fd. file_of_proc_fd \<tau> p fd = Some f}" |
|
262 |
||
70 | 263 |
definition proc_file_fds :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd set" |
264 |
where |
|
265 |
"proc_file_fds s p \<equiv> {fd. \<exists> f. file_of_proc_fd s p fd = Some f}" |
|
266 |
||
267 |
definition init_proc_file_fds:: "t_process \<Rightarrow> t_fd set" |
|
268 |
where |
|
269 |
"init_proc_file_fds p \<equiv> {fd. \<exists> f. init_file_of_proc_fd p fd = Some f}" |
|
1 | 270 |
|
271 |
(****** files and directories ******) |
|
272 |
||
273 |
fun files_hung_by_del :: "t_state \<Rightarrow> t_file set" |
|
274 |
where |
|
275 |
"files_hung_by_del [] = init_files_hung_by_del" |
|
276 |
| "files_hung_by_del (UnLink p f # \<tau>) = ( |
|
277 |
if (proc_fd_of_file \<tau> f = {}) then files_hung_by_del \<tau> |
|
278 |
else insert f (files_hung_by_del \<tau>))" |
|
279 |
(* | files_hung_by_del (Rmdir p f) is not need, for open can only apply to file not dir *) |
|
280 |
| "files_hung_by_del (CloseFd p fd # \<tau>) = ( |
|
281 |
case (file_of_proc_fd \<tau> p fd) of |
|
282 |
Some f \<Rightarrow> (if (proc_fd_of_file \<tau> f = {(p, fd)}) |
|
283 |
then files_hung_by_del \<tau> - {f} |
|
284 |
else files_hung_by_del \<tau>) |
|
285 |
| None \<Rightarrow> files_hung_by_del \<tau> )" |
|
286 |
(* |
|
287 |
| "files_hung_by_del (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) = {file_after_rename f\<^isub>2 f\<^isub>3 f\<^isub>1| f\<^isub>1. f\<^isub>1 \<in> files_hung_by_del \<tau>}" (* for rename(2) does not infect on fd of the file, see man -S 2 rename *) |
|
288 |
*) |
|
289 |
| "files_hung_by_del (e # \<tau>) = files_hung_by_del \<tau>" |
|
290 |
declare files_hung_by_del.simps [simp del] |
|
291 |
||
292 |
fun inum_of_file :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_inode_num)" |
|
293 |
where |
|
294 |
"inum_of_file [] = init_inum_of_file" |
|
295 |
| "inum_of_file (Open p f flags fd (Some inum) # \<tau>) = (inum_of_file \<tau>) (f := Some inum)" |
|
296 |
| "inum_of_file (CloseFd p fd # \<tau>) = ( |
|
297 |
case (file_of_proc_fd \<tau> p fd) of |
|
298 |
Some f \<Rightarrow> ( if ((proc_fd_of_file \<tau> f = {(p, fd)}) \<and> (f \<in> files_hung_by_del \<tau>)) |
|
299 |
then (inum_of_file \<tau>) (f := None) |
|
300 |
else inum_of_file \<tau> ) |
|
301 |
| _ \<Rightarrow> (inum_of_file \<tau>) )" |
|
302 |
| "inum_of_file (UnLink p f # \<tau>) = ( |
|
303 |
if (proc_fd_of_file \<tau> f = {}) |
|
304 |
then (inum_of_file \<tau>) (f := None) |
|
305 |
else inum_of_file \<tau> )" |
|
8 | 306 |
| "inum_of_file (Rmdir p f # \<tau>) = (inum_of_file \<tau>) (f := None)" |
1 | 307 |
| "inum_of_file (Mkdir p f ino # \<tau>) = (inum_of_file \<tau>) (f:= Some ino)" |
308 |
| "inum_of_file (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>) = (inum_of_file \<tau>) (f\<^isub>2 := inum_of_file \<tau> f\<^isub>1)" |
|
309 |
(* |
|
310 |
| "inum_of_file (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) = (\<lambda> f. |
|
311 |
if (f\<^isub>2 \<preceq> f) then None |
|
312 |
else if (f\<^isub>3 \<preceq> f) then inum_of_file \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f) |
|
313 |
else inum_of_file \<tau> f )" |
|
314 |
*) |
|
315 |
| "inum_of_file (e # \<tau>) = inum_of_file \<tau>" |
|
316 |
||
317 |
definition current_files :: "t_state \<Rightarrow> t_file set" |
|
318 |
where |
|
319 |
"current_files \<tau> = {f. \<exists> i. inum_of_file \<tau> f = Some i}" |
|
320 |
||
321 |
(* experimentary: for the delete obj's (file or socket) inode num, it is unnecessary for itag_of_inum to be NONE, cause this is the situation blocked by inum_of_file / inum_of_socket !!! *) |
|
322 |
(* delete a file, just recycle its inode num, but not destroy its inode \<dots>, so it is irrelative to these events, like closeFd, Rmdir, UnLink \<dots>*) |
|
323 |
fun itag_of_inum :: "t_state \<Rightarrow> (t_inode_num \<rightharpoonup> t_inode_tag)" |
|
324 |
where |
|
325 |
"itag_of_inum [] = init_itag_of_inum" |
|
326 |
| "itag_of_inum (Open p f flags fd (Some ino) # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_FILE)" |
|
327 |
| "itag_of_inum (Mkdir p f ino # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_DIR)" |
|
328 |
| "itag_of_inum (CreateSock p af st fd ino # \<tau>) = |
|
329 |
(case st of |
|
330 |
STREAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK) |
|
331 |
| DGRAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_UDP_SOCK) )" |
|
332 |
| "itag_of_inum (Accept p fd addr lport' fd' ino # \<tau>) = |
|
333 |
(itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)" |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
334 |
| "itag_of_inum (_ # \<tau>) = itag_of_inum \<tau>" |
1 | 335 |
|
336 |
definition is_file:: "t_state \<Rightarrow> t_file \<Rightarrow> bool" |
|
337 |
where |
|
338 |
"is_file \<tau> f \<equiv> (case (inum_of_file \<tau> f) of |
|
339 |
Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of |
|
340 |
Some Tag_FILE \<Rightarrow> True |
|
341 |
| _ \<Rightarrow> False) |
|
342 |
| _ \<Rightarrow> False)" |
|
343 |
||
344 |
definition is_dir:: "t_state \<Rightarrow> t_file \<Rightarrow> bool" |
|
345 |
where |
|
346 |
"is_dir \<tau> f \<equiv> (case (inum_of_file \<tau> f) of |
|
347 |
Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of |
|
348 |
Some Tag_DIR \<Rightarrow> True |
|
349 |
| _ \<Rightarrow> False) |
|
350 |
| _ \<Rightarrow> False)" |
|
351 |
||
352 |
definition dir_is_empty :: "t_state \<Rightarrow> t_file \<Rightarrow> bool" |
|
353 |
where |
|
354 |
"dir_is_empty \<tau> f \<equiv> is_dir \<tau> f \<and> \<not> (\<exists> f'. f' \<in> current_files \<tau> \<and> f \<prec> f')" |
|
355 |
||
65 | 356 |
definition same_inode_files :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file set" |
357 |
where |
|
358 |
"same_inode_files s f \<equiv> if is_file s f then {f'. inum_of_file s f = inum_of_file s f'} else {}" |
|
359 |
||
360 |
definition has_same_inode :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file \<Rightarrow> bool" |
|
361 |
where |
|
362 |
"has_same_inode s fa fb \<equiv> fb \<in> same_inode_files s fa" |
|
363 |
||
364 |
fun inum_of_socket :: "t_state \<Rightarrow> (t_socket \<rightharpoonup> t_inode_num)" |
|
365 |
where |
|
366 |
"inum_of_socket [] = init_inum_of_socket" |
|
367 |
| "inum_of_socket (CloseFd p fd # \<tau>) = |
|
368 |
(inum_of_socket \<tau>) ((p, fd):= None)" |
|
369 |
| "inum_of_socket (CreateSock p af st fd ino # \<tau>) = |
|
370 |
(inum_of_socket \<tau>) ((p, fd) := Some ino)" |
|
371 |
| "inum_of_socket (Accept p fd addr lport' fd' ino # \<tau>) = |
|
372 |
(inum_of_socket \<tau>) ((p, fd') := Some ino)" |
|
373 |
| "inum_of_socket (Clone p p' fds shms # \<tau>) = |
|
374 |
(\<lambda> (p'', fd). if (p'' = p' \<and> fd \<in> fds) then inum_of_socket \<tau> (p, fd) |
|
375 |
else if (p'' = p') then None |
|
376 |
else inum_of_socket \<tau> (p'',fd))" |
|
377 |
| "inum_of_socket (Execve p f fds # \<tau>) = |
|
378 |
(\<lambda> (p', fd). if (p' = p \<and> fd \<in> fds) then inum_of_socket \<tau> (p, fd) |
|
379 |
else if (p' = p) then None |
|
380 |
else inum_of_socket \<tau> (p', fd))" |
|
381 |
| "inum_of_socket (Kill p\<^isub>1 p\<^isub>2 # \<tau>) = |
|
382 |
(\<lambda> (p, fd). if (p = p\<^isub>2) then None else inum_of_socket \<tau> (p, fd) )" |
|
383 |
| "inum_of_socket (Exit p # \<tau>) = |
|
384 |
(\<lambda> (p', fd). if (p' = p) then None else inum_of_socket \<tau> (p', fd))" |
|
385 |
| "inum_of_socket (_ # \<tau>) = inum_of_socket \<tau>" |
|
386 |
||
387 |
definition current_sockets :: "t_state \<Rightarrow> t_socket set" |
|
388 |
where |
|
389 |
"current_sockets \<tau> = {s. \<exists> i. inum_of_socket \<tau> s = Some i}" |
|
390 |
||
1 | 391 |
definition is_tcp_sock :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool" |
392 |
where |
|
393 |
"is_tcp_sock \<tau> s \<equiv> (case (inum_of_socket \<tau> s) of |
|
394 |
Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of |
|
395 |
Some Tag_TCP_SOCK \<Rightarrow> True |
|
396 |
| _ \<Rightarrow> False) |
|
397 |
| _ \<Rightarrow> False)" |
|
398 |
||
399 |
definition is_udp_sock :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool" |
|
400 |
where |
|
401 |
"is_udp_sock \<tau> s \<equiv> (case (inum_of_socket \<tau> s) of |
|
402 |
Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of |
|
403 |
Some Tag_UDP_SOCK \<Rightarrow> True |
|
404 |
| _ \<Rightarrow> False) |
|
405 |
| _ \<Rightarrow> False)" |
|
406 |
||
407 |
fun current_procs :: "t_state \<Rightarrow> t_process set" |
|
408 |
where |
|
409 |
"current_procs [] = init_procs" |
|
410 |
| "current_procs (Clone p p' fds shms # \<tau>) = (insert p' (current_procs \<tau>))" |
|
411 |
| "current_procs (Exit p # \<tau>) = (current_procs \<tau> - {p})" |
|
412 |
| "current_procs (Kill p p' # \<tau>) = (current_procs \<tau> - {p'})" |
|
413 |
| "current_procs (_ # \<tau>) = current_procs \<tau>" |
|
414 |
||
415 |
fun current_proc_fds :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd set" |
|
416 |
where |
|
417 |
"current_proc_fds [] = init_fds_of_proc" |
|
418 |
| "current_proc_fds (Open p f flags fd iopt # \<tau>) = |
|
419 |
(current_proc_fds \<tau>) (p:= insert fd (current_proc_fds \<tau> p))" |
|
420 |
| "current_proc_fds (CreateSock p sf st newfd newi # \<tau>) = |
|
421 |
(current_proc_fds \<tau>) (p:= insert newfd (current_proc_fds \<tau> p))" |
|
422 |
| "current_proc_fds (Accept p fd raddr port fd' ino # \<tau>) = |
|
423 |
(current_proc_fds \<tau>) (p:= insert fd' (current_proc_fds \<tau> p))" |
|
424 |
| "current_proc_fds (CloseFd p fd # \<tau>) = |
|
425 |
(current_proc_fds \<tau>) (p:= (current_proc_fds \<tau> p) - {fd})" |
|
426 |
| "current_proc_fds (Clone p p' fds shms # \<tau>) = |
|
427 |
(current_proc_fds \<tau>) (p':= fds)" |
|
428 |
| "current_proc_fds (Execve p f fds # \<tau>) = |
|
429 |
(current_proc_fds \<tau>) (p:= fds)" |
|
430 |
| "current_proc_fds (Exit p # \<tau>) = (current_proc_fds \<tau>) (p := {})" |
|
431 |
| "current_proc_fds (Kill p p' # \<tau>) = (current_proc_fds \<tau>) (p' := {})" |
|
432 |
| "current_proc_fds (_ # \<tau>) = current_proc_fds \<tau>" |
|
433 |
||
434 |
fun current_shms :: "t_state \<Rightarrow> t_shm set" |
|
435 |
where |
|
436 |
"current_shms [] = init_shms" |
|
437 |
| "current_shms (CreateShM p newshm # \<tau>) = insert newshm (current_shms \<tau>)" |
|
438 |
| "current_shms (DeleteShM p s # \<tau>) = (current_shms \<tau>) - {s}" |
|
439 |
| "current_shms (e # \<tau>) = current_shms \<tau> " |
|
440 |
||
15 | 441 |
fun flag_of_proc_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_shm \<Rightarrow> t_shm_attach_flag option" |
442 |
where |
|
443 |
"flag_of_proc_shm [] = init_flag_of_proc_shm" |
|
444 |
| "flag_of_proc_shm (Attach p h flag # s) = (\<lambda> p' h'. |
|
445 |
if (p' = p \<and> h' = h) then Some flag else flag_of_proc_shm s p' h')" |
|
446 |
| "flag_of_proc_shm (Detach p h # s) = (\<lambda> p' h'. |
|
447 |
if (p' = p \<and> h' = h) then None else flag_of_proc_shm s p' h')" |
|
448 |
| "flag_of_proc_shm (CreateShM p h # s) = (\<lambda> p' h'. |
|
449 |
if (h' = h) then None else flag_of_proc_shm s p' h')" |
|
450 |
| "flag_of_proc_shm (DeleteShM p h # s) = (\<lambda> p' h'. |
|
451 |
if (h' = h) then None else flag_of_proc_shm s p' h')" |
|
452 |
| "flag_of_proc_shm (Clone p p' fds shms # s) = (\<lambda> p'' h. |
|
453 |
if (p'' = p' \<and> h \<in> shms) then flag_of_proc_shm s p h |
|
454 |
else if (p'' = p') then None |
|
455 |
else flag_of_proc_shm s p'' h)" |
|
456 |
| "flag_of_proc_shm (Execve p f fds # s) = (\<lambda> p' h. |
|
457 |
if (p' = p) then None else flag_of_proc_shm s p' h)" |
|
458 |
| "flag_of_proc_shm (Kill p p' # s) = (\<lambda> p'' h. |
|
459 |
if (p'' = p') then None else flag_of_proc_shm s p'' h)" |
|
460 |
| "flag_of_proc_shm (Exit p # s) = (\<lambda> p' h. |
|
461 |
if (p' = p) then None else flag_of_proc_shm s p' h)" |
|
462 |
| "flag_of_proc_shm (e # s) = flag_of_proc_shm s" |
|
463 |
||
464 |
fun procs_of_shm :: "t_state \<Rightarrow> t_shm \<Rightarrow> (t_process \<times> t_shm_attach_flag) set" |
|
1 | 465 |
where |
466 |
"procs_of_shm [] = init_procs_of_shm" |
|
467 |
| "procs_of_shm (CreateShM p h # \<tau>) = |
|
468 |
(procs_of_shm \<tau>) (h := {})" (* creator may not be the sharer of the shm *) |
|
469 |
| "procs_of_shm (Attach p h flag # \<tau>) = |
|
470 |
(procs_of_shm \<tau>) (h := insert (p, flag) (procs_of_shm \<tau> h))" |
|
471 |
| "procs_of_shm (Detach p h # \<tau>) = |
|
13 | 472 |
(procs_of_shm \<tau>) (h := (procs_of_shm \<tau> h) - {(p,flag) | flag. (p, flag) \<in> procs_of_shm \<tau> h})" |
1 | 473 |
| "procs_of_shm (DeleteShM p h # \<tau>) = (procs_of_shm \<tau>) (h := {})" |
474 |
| "procs_of_shm (Clone p p' fds shms # \<tau>) = |
|
475 |
(\<lambda> h. if (h \<in> shms) |
|
13 | 476 |
then (procs_of_shm \<tau> h) \<union> {(p', flag) | flag. (p, flag) \<in> procs_of_shm \<tau> h} |
1 | 477 |
else procs_of_shm \<tau> h)" |
478 |
| "procs_of_shm (Execve p f fds # \<tau>) = |
|
13 | 479 |
(\<lambda> h. procs_of_shm \<tau> h - {(p, flag) | flag. (p, flag) \<in> procs_of_shm \<tau> h})" |
480 |
| "procs_of_shm (Kill p p' # s) = |
|
481 |
(\<lambda> h. (procs_of_shm s h) - {(p', flag) | flag. (p', flag) \<in> procs_of_shm s h})" |
|
482 |
| "procs_of_shm (Exit p # s) = |
|
483 |
(\<lambda> h. (procs_of_shm s h) - {(p, flag) | flag. (p, flag) \<in> procs_of_shm s h})" |
|
484 |
| "procs_of_shm (e # \<tau>) = procs_of_shm \<tau>" |
|
1 | 485 |
|
26 | 486 |
(* |
25
259a50be4381
wrong of info-flow-shm, it is a inductive(transitive) notion, not a simple relation just between 2 nodes, more information, see 5.7 of ideas_of_selinux.txt
chunhan
parents:
23
diff
changeset
|
487 |
inductive info_flow_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool" |
259a50be4381
wrong of info-flow-shm, it is a inductive(transitive) notion, not a simple relation just between 2 nodes, more information, see 5.7 of ideas_of_selinux.txt
chunhan
parents:
23
diff
changeset
|
488 |
where |
259a50be4381
wrong of info-flow-shm, it is a inductive(transitive) notion, not a simple relation just between 2 nodes, more information, see 5.7 of ideas_of_selinux.txt
chunhan
parents:
23
diff
changeset
|
489 |
"p \<in> current_procs s \<Longrightarrow> info_flow_shm s p p" |
259a50be4381
wrong of info-flow-shm, it is a inductive(transitive) notion, not a simple relation just between 2 nodes, more information, see 5.7 of ideas_of_selinux.txt
chunhan
parents:
23
diff
changeset
|
490 |
| "\<lbrakk>info_flow_shm s p p'; (p', SHM_RDWR) \<in> procs_of_shm s h; (p'', flag) \<in> procs_of_shm s h; p' \<noteq> p''\<rbrakk> |
259a50be4381
wrong of info-flow-shm, it is a inductive(transitive) notion, not a simple relation just between 2 nodes, more information, see 5.7 of ideas_of_selinux.txt
chunhan
parents:
23
diff
changeset
|
491 |
\<Longrightarrow> info_flow_shm s p p''" |
26 | 492 |
*) |
493 |
definition one_flow_shm :: "t_state \<Rightarrow> t_shm \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool" |
|
494 |
where |
|
27 | 495 |
"one_flow_shm s h from to \<equiv> from \<noteq> to \<and> (from, SHM_RDWR) \<in> procs_of_shm s h \<and> |
496 |
(\<exists> flag. (to, flag) \<in> procs_of_shm s h)" |
|
26 | 497 |
|
498 |
fun self_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool" |
|
499 |
where |
|
500 |
"self_shm s p p' = (p = p' \<and> p' \<in> current_procs s)" |
|
501 |
||
1 | 502 |
definition info_flow_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool" |
503 |
where |
|
26 | 504 |
"info_flow_shm s from to \<equiv> (self_shm s from to) \<or> (\<exists> h. one_flow_shm s h from to)" |
505 |
||
1 | 506 |
|
507 |
fun current_msgqs :: "t_state \<Rightarrow> t_msg set" |
|
508 |
where |
|
509 |
"current_msgqs [] = init_msgqs" |
|
510 |
| "current_msgqs (CreateMsgq p q # \<tau>) = insert q (current_msgqs \<tau>)" |
|
511 |
| "current_msgqs (RemoveMsgq p q # \<tau>) = (current_msgqs \<tau>) - {q}" |
|
512 |
| "current_msgqs (_ # \<tau>) = current_msgqs \<tau>" |
|
513 |
||
514 |
fun msgs_of_queue :: "t_state \<Rightarrow> t_msgq \<Rightarrow> t_msg list" |
|
515 |
where |
|
516 |
"msgs_of_queue [] = init_msgs_of_queue" |
|
517 |
| "msgs_of_queue (CreateMsgq p q # \<tau>) = (msgs_of_queue \<tau>)(q := [])" |
|
518 |
| "msgs_of_queue (SendMsg p q m # \<tau>) = (msgs_of_queue \<tau>)(q := msgs_of_queue \<tau> q @ [m])" |
|
519 |
| "msgs_of_queue (RecvMsg p q m # \<tau>) = (msgs_of_queue \<tau>)(q := tl (msgs_of_queue \<tau> q))" |
|
520 |
| "msgs_of_queue (RemoveMsgq p q # \<tau>) = (msgs_of_queue \<tau>)(q := [])" |
|
521 |
| "msgs_of_queue (_ # \<tau>) = msgs_of_queue \<tau>" |
|
522 |
||
523 |
definition current_file_inums :: "t_state \<Rightarrow> t_inode_num set" |
|
524 |
where |
|
525 |
"current_file_inums \<tau> \<equiv> {im. \<exists> f. inum_of_file \<tau> f = Some im}" |
|
526 |
||
527 |
definition current_sock_inums :: "t_state \<Rightarrow> t_inode_num set" |
|
528 |
where |
|
529 |
"current_sock_inums \<tau> = {im. \<exists> s. inum_of_socket \<tau> s = Some im}" |
|
530 |
||
531 |
definition current_inode_nums :: "t_state \<Rightarrow> nat set" |
|
532 |
where |
|
533 |
"current_inode_nums \<tau> = current_file_inums \<tau> \<union> current_sock_inums \<tau>" |
|
534 |
||
535 |
fun flags_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_open_flags option" |
|
536 |
where |
|
537 |
"flags_of_proc_fd [] p fd = init_oflags_of_proc_fd p fd" |
|
538 |
| "flags_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' = |
|
539 |
(if (p = p' \<and> fd = fd') then Some flags else flags_of_proc_fd \<tau> p' fd')" |
|
540 |
| "flags_of_proc_fd (CloseFd p fd # \<tau>) p' fd' = |
|
541 |
(if (p = p' \<and> fd = fd') then None else flags_of_proc_fd \<tau> p' fd')" |
|
542 |
| "flags_of_proc_fd (CreateSock p af st fd ino # \<tau>) p' fd' = |
|
543 |
(if (p = p' \<and> fd = fd') then None else flags_of_proc_fd \<tau> p' fd')" |
|
544 |
| "flags_of_proc_fd (Accept p fd addr lport' fd' ino # \<tau>) p' fd'' = |
|
545 |
(if (p = p' \<and> fd' = fd'') then None else flags_of_proc_fd \<tau> p' fd'')" |
|
546 |
| "flags_of_proc_fd (Clone p p' fds shms # \<tau>) p'' fd = |
|
547 |
(if (p' = p'' \<and> fd \<in> fds) then flags_of_proc_fd \<tau> p fd else flags_of_proc_fd \<tau> p'' fd)" |
|
548 |
| "flags_of_proc_fd (Execve p f fds # \<tau>) p' fd = |
|
549 |
(if (p' = p \<and> fd \<in> fds) then flags_of_proc_fd \<tau> p fd else flags_of_proc_fd \<tau> p' fd)" |
|
550 |
| "flags_of_proc_fd (Kill p\<^isub>1 p\<^isub>2 # \<tau>) p fd = |
|
551 |
(if (p = p\<^isub>2) then None else flags_of_proc_fd \<tau> p fd)" |
|
552 |
| "flags_of_proc_fd (Exit p # \<tau>) p' fd' = |
|
553 |
(if (p = p') then None else flags_of_proc_fd \<tau> p' fd')" |
|
554 |
| "flags_of_proc_fd (e # \<tau>) p fd = flags_of_proc_fd \<tau> p fd" |
|
555 |
||
556 |
(* |
|
557 |
fun file_at_writing_by:: "t_state \<Rightarrow> t_file \<Rightarrow> (t_process \<times> t_fd) set" |
|
558 |
where |
|
559 |
"file_at_writing_by [] f = init_file_at_writing_by f" |
|
560 |
| "file_at_writing_by (Open p f flags fd (Some inum) # \<tau>) f' = ( |
|
561 |
if (f' = f) |
|
562 |
then ( if (is_write_flag flags) |
|
563 |
then {(p, fd)} |
|
564 |
else {} ) |
|
565 |
else file_at_writing_by \<tau> f' )" |
|
566 |
| "file_at_writing_by (Open p f flags fd None # \<tau>) f' = ( |
|
567 |
if (f' = f \<and> is_write_flag flags) |
|
568 |
then insert (p, fd) (file_at_writing_by \<tau> f) |
|
569 |
else file_at_writing_by \<tau> f' )" |
|
570 |
| "file_at_writing_by (Mkdir p f inum # \<tau>) f' = |
|
571 |
(if (f' = f) then {} else file_at_writing_by \<tau> f')" |
|
572 |
| "file_at_writing_by (LinkHard p f f' # \<tau>) f'' = |
|
573 |
(if (f'' = f') then file_at_writing_by \<tau> f else file_at_writing_by \<tau> f'')" |
|
574 |
| "file_at_writing_by (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = ( |
|
575 |
if (f\<^isub>3 \<preceq> f) then file_at_writing_by \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f) |
|
576 |
else file_at_writing_by \<tau> f )" |
|
577 |
| "file_at_writing_by (CloseFd p fd # \<tau>) f = |
|
578 |
(file_at_writing_by \<tau> f - {(p, fd)})" |
|
579 |
| "file_at_writing_by (Clone p p' fds shms # \<tau>) f = |
|
580 |
(file_at_writing_by \<tau> f) \<union> {(p',fd)| fd. fd \<in> fds \<and> (p, fd) \<in> file_at_writing_by \<tau> f}" |
|
581 |
| "file_at_writing_by (Execve p f fds # \<tau>) f' = |
|
582 |
(if (f' = f) then {} else file_at_writing_by \<tau> f')" |
|
583 |
| "file_at_writing_by (Exit p # \<tau>) f = |
|
584 |
(file_at_writing_by \<tau> f - {(p, fd)| fd. (p, fd) \<in> file_at_writing_by \<tau> f})" |
|
585 |
| "file_at_writing_by (Kill p p' # \<tau>) f = |
|
586 |
(file_at_writing_by \<tau> f - {(p', fd)| fd. (p', fd) \<in> file_at_writing_by \<tau> f})" |
|
587 |
| "file_at_writing_by (e # \<tau>) f = file_at_writing_by \<tau> f" |
|
588 |
*) |
|
589 |
||
590 |
definition current_users :: "t_state \<Rightarrow> user_t set" |
|
591 |
where |
|
592 |
"current_users \<tau> \<equiv> init_users" |
|
593 |
||
594 |
fun update_with_shuthow :: "t_sock_state option \<Rightarrow> t_shutdown_how \<Rightarrow> t_sock_state option" |
|
595 |
where |
|
596 |
"update_with_shuthow (Some (SS_trans Trans_Recv)) SHUT_RD = Some (SS_trans Trans_No)" |
|
597 |
| "update_with_shuthow (Some (SS_trans Trans_RS)) SHUT_RD = Some (SS_trans Trans_Send)" |
|
598 |
| "update_with_shuthow (Some (SS_trans Trans_Send)) SHUT_RD = Some (SS_trans Trans_Send)" |
|
599 |
| "update_with_shuthow (Some (SS_trans Trans_No)) SHUT_RD = Some (SS_trans Trans_No)" |
|
600 |
| "update_with_shuthow (Some (SS_trans Trans_Recv)) SHUT_WR = Some (SS_trans Trans_Recv)" |
|
601 |
| "update_with_shuthow (Some (SS_trans Trans_RS)) SHUT_WR = Some (SS_trans Trans_Recv)" |
|
602 |
| "update_with_shuthow (Some (SS_trans Trans_Send)) SHUT_WR = Some (SS_trans Trans_No)" |
|
603 |
| "update_with_shuthow (Some (SS_trans Trans_No)) SHUT_WR = Some (SS_trans Trans_No)" |
|
604 |
| "update_with_shuthow (Some (SS_trans Trans_Recv)) SHUT_RDWR = Some (SS_trans Trans_No)" |
|
605 |
| "update_with_shuthow (Some (SS_trans Trans_RS)) SHUT_RDWR = Some (SS_trans Trans_No)" |
|
606 |
| "update_with_shuthow (Some (SS_trans Trans_Send)) SHUT_RDWR = Some (SS_trans Trans_No)" |
|
607 |
| "update_with_shuthow (Some (SS_trans Trans_No)) SHUT_RDWR = Some (SS_trans Trans_No)" |
|
608 |
| "update_with_shuthow opt1 how = None" |
|
609 |
||
610 |
fun socket_state :: "t_state \<Rightarrow> t_socket \<Rightarrow> t_sock_state option" |
|
611 |
where |
|
612 |
"socket_state [] = init_socket_state" |
|
613 |
| "socket_state (CloseFd p fd # \<tau>) = |
|
614 |
(socket_state \<tau>) ((p, fd):= None)" |
|
615 |
| "socket_state (CreateSock p af st fd ino # \<tau>) = |
|
616 |
(socket_state \<tau>) ((p, fd) := Some SS_create)" |
|
617 |
| "socket_state (Bind p fd addr # \<tau>) = |
|
618 |
(socket_state \<tau>) ((p, fd) := Some SS_bind)" |
|
619 |
| "socket_state (Connect p fd addr # \<tau>) = |
|
620 |
(socket_state \<tau>) ((p, fd) := Some (SS_trans Trans_RS))" |
|
621 |
| "socket_state (Listen p fd # \<tau>) = |
|
622 |
(socket_state \<tau>) ((p, fd) := Some SS_listen)" |
|
623 |
| "socket_state (Accept p fd addr lport' fd' ino # \<tau>) = |
|
624 |
(socket_state \<tau>) ((p, fd') := Some (SS_trans Trans_RS))" |
|
625 |
| "socket_state (Shutdown p fd sh # \<tau>) = |
|
626 |
(socket_state \<tau>) ((p, fd) := update_with_shuthow (socket_state \<tau> (p, fd)) sh)" |
|
627 |
| "socket_state (Clone p p' fds shms # \<tau>) = |
|
628 |
(\<lambda> (p'', fd). if (p'' = p' \<and> fd \<in> fds) then socket_state \<tau> (p, fd) |
|
629 |
else if (p'' = p') then None |
|
630 |
else socket_state \<tau> (p'', fd))" |
|
631 |
| "socket_state (Execve p f fds # \<tau>) = |
|
632 |
(\<lambda> (p', fd). if (p' = p \<and> fd \<in> fds) then socket_state \<tau> (p, fd) |
|
633 |
else if (p' = p) then None |
|
634 |
else socket_state \<tau> (p', fd))" |
|
635 |
| "socket_state (Kill p\<^isub>1 p\<^isub>2 # \<tau>) = |
|
636 |
(\<lambda> (p, fd). if (p = p\<^isub>2) then None else socket_state \<tau> (p, fd))" |
|
637 |
| "socket_state (Exit p # \<tau>) = |
|
638 |
(\<lambda> (p', fd'). if (p = p') then None else socket_state \<tau> (p', fd'))" |
|
639 |
| "socket_state (e # \<tau>) = socket_state \<tau>" |
|
640 |
||
641 |
definition socket_in_trans :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool" |
|
642 |
where |
|
643 |
"socket_in_trans \<tau> s \<equiv> (case (socket_state \<tau> s) of |
|
644 |
Some st \<Rightarrow> (case st of |
|
645 |
SS_trans para \<Rightarrow> True |
|
646 |
| _ \<Rightarrow> False) |
|
647 |
| _ \<Rightarrow> False)" |
|
648 |
||
649 |
definition socket_in_sending :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool" |
|
650 |
where |
|
651 |
"socket_in_sending \<tau> s \<equiv> (socket_state \<tau> s = Some (SS_trans Trans_Send)) \<or> (socket_state \<tau> s = Some (SS_trans Trans_RS))" |
|
652 |
||
653 |
definition socket_in_recving :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool" |
|
654 |
where |
|
655 |
"socket_in_recving \<tau> s \<equiv> (socket_state \<tau> s = Some (SS_trans Trans_Recv)) \<or> (socket_state \<tau> s = Some (SS_trans Trans_RS))" |
|
656 |
||
657 |
||
658 |
(******* admissable check by the OS *******) |
|
659 |
fun os_grant :: "t_state \<Rightarrow> t_event \<Rightarrow> bool" |
|
660 |
where |
|
661 |
"os_grant \<tau> (Open p f flags fd inumopt) = ( |
|
662 |
case inumopt of |
|
663 |
Some ino \<Rightarrow> |
|
664 |
(p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
665 |
(\<exists> pf. parent f = Some pf \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and> |
1 | 666 |
is_creat_flag flags \<and> fd \<notin> (current_proc_fds \<tau> p) \<and> ino \<notin> (current_inode_nums \<tau>)) |
667 |
| None \<Rightarrow> |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
668 |
(p \<in> current_procs \<tau> \<and> \<not> is_creat_excl_flag flags \<and> is_file \<tau> f \<and> |
1 | 669 |
fd \<notin> (current_proc_fds \<tau> p)) )" |
670 |
(*(if (is_dir \<tau> f) then (is_dir_flag flags \<and> \<not> is_write_flag flags) else (\<not> is_dir_flag flags)), |
|
671 |
here open is not applied to directories, readdir is for that, but it is not security-related *) |
|
672 |
| "os_grant \<tau> (CloseFd p fd) = |
|
673 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p)" |
|
674 |
| "os_grant \<tau> (UnLink p f) = |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
675 |
(p \<in> current_procs \<tau> \<and> is_file \<tau> f \<and> f \<notin> files_hung_by_del \<tau>)" |
1 | 676 |
| "os_grant \<tau> (Rmdir p f) = |
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
677 |
(p \<in> current_procs \<tau> \<and> dir_is_empty \<tau> f \<and> f \<notin> files_hung_by_del \<tau> \<and> f \<noteq> [])" (* root file cannot be deleted *) |
1 | 678 |
| "os_grant \<tau> (Mkdir p f ino) = |
679 |
(p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
680 |
(\<exists> pf. parent f = Some pf \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and> |
1 | 681 |
ino \<notin> (current_inode_nums \<tau>))" |
682 |
| "os_grant \<tau> (LinkHard p f\<^isub>1 f\<^isub>2) = |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
683 |
(p \<in> current_procs \<tau> \<and> is_file \<tau> f\<^isub>1 \<and> f\<^isub>2 \<notin> current_files \<tau> \<and> |
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
684 |
(\<exists> pf\<^isub>2. parent f\<^isub>2 = Some pf\<^isub>2 \<and> is_dir \<tau> pf\<^isub>2 \<and> pf\<^isub>2 \<notin> files_hung_by_del \<tau>))" |
1 | 685 |
| "os_grant \<tau> (Truncate p f len) = |
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
686 |
(p \<in> current_procs \<tau> \<and> is_file \<tau> f)" |
1 | 687 |
(* |
688 |
| "os_grant \<tau> (FTruncate p fd len) = |
|
689 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> |
|
690 |
(\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f) \<and> |
|
691 |
(\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))" |
|
692 |
*) |
|
693 |
| "os_grant \<tau> (ReadFile p fd) = |
|
694 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> |
|
695 |
(\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau>) \<and> |
|
696 |
(\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_read_flag flags))" |
|
697 |
| "os_grant \<tau> (WriteFile p fd) = |
|
698 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> |
|
699 |
(\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau>) \<and> |
|
69
fc7151df7f8e
simplifing model, by changing current_proc_fds to proc_file_fds in the Clone & Execve cases of os_grant
chunhan
parents:
68
diff
changeset
|
700 |
(\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))" |
1 | 701 |
| "os_grant \<tau> (Execve p f fds) = |
68
742bed613245
simplifing model, by changing sectxt_of_obj s' (O_proc p) of None \<Rightarrow> False
chunhan
parents:
67
diff
changeset
|
702 |
(p \<in> current_procs \<tau> \<and> is_file \<tau> f \<and> fds \<subseteq> proc_file_fds \<tau> p)" (* file_at_writing_by \<tau> f = {} \<and> fds \<subseteq> current_proc_fds \<tau> p *) |
1 | 703 |
(* |
704 |
| "os_grant \<tau> (Rename p f\<^isub>2 f\<^isub>3) = |
|
705 |
(p \<in> current_procs \<tau> \<and> f\<^isub>2 \<in> current_files \<tau> \<and> \<not>(f\<^isub>2 \<preceq> f\<^isub>3) \<and> f\<^isub>3 \<notin> current_files \<tau> \<and> |
|
706 |
(\<exists> pf\<^isub>3. parent f\<^isub>3 = Some pf\<^isub>3 \<and> pf\<^isub>3 \<in> current_files \<tau> \<and> is_dir \<tau> pf\<^isub>3 \<and> |
|
707 |
pf\<^isub>3 \<notin> files_hung_by_del \<tau>) )" |
|
708 |
*) |
|
709 |
| "os_grant \<tau> (CreateMsgq p q) = |
|
710 |
(p \<in> current_procs \<tau> \<and> q \<notin> (current_msgqs \<tau>))" |
|
711 |
| "os_grant \<tau> (SendMsg p q m) = |
|
712 |
(p \<in> current_procs \<tau> \<and> q \<in> current_msgqs \<tau> \<and> m \<notin> (set (msgs_of_queue \<tau> q)))" |
|
713 |
| "os_grant \<tau> (RecvMsg p q m) = |
|
31 | 714 |
(p \<in> current_procs \<tau> \<and> q \<in> current_msgqs \<tau> \<and> m = hd (msgs_of_queue \<tau> q) \<and> msgs_of_queue \<tau> q \<noteq> [])" |
1 | 715 |
| "os_grant \<tau> (RemoveMsgq p q) = |
716 |
(p \<in> current_procs \<tau> \<and> q \<in> current_msgqs \<tau>)" |
|
717 |
| "os_grant \<tau> (CreateShM p h) = |
|
718 |
(p \<in> current_procs \<tau> \<and> h \<notin> (current_shms \<tau>))" |
|
719 |
| "os_grant \<tau> (Attach p h flag) = |
|
720 |
(p \<in> current_procs \<tau> \<and> h \<in> current_shms \<tau> \<and> \<not> (\<exists> flag. (p, flag) \<in> procs_of_shm \<tau> h))" |
|
721 |
| "os_grant \<tau> (Detach p h) = |
|
722 |
(p \<in> current_procs \<tau> \<and> h \<in> current_shms \<tau> \<and> (\<exists> flag. (p, flag) \<in> procs_of_shm \<tau> h))" |
|
723 |
| "os_grant \<tau> (DeleteShM p h) = |
|
724 |
(p \<in> current_procs \<tau> \<and> h \<in> current_shms \<tau>)" |
|
725 |
| "os_grant \<tau> (CreateSock p af st fd ino) = |
|
726 |
(p \<in> current_procs \<tau> \<and> af = AF_INET \<and> fd \<notin> (current_proc_fds \<tau> p) \<and> |
|
727 |
ino \<notin> (current_inode_nums \<tau>))" |
|
728 |
| "os_grant \<tau> (Accept p fd addr port fd' ino) = |
|
729 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
730 |
fd' \<notin> (current_proc_fds \<tau> p) \<and> socket_state \<tau> (p, fd) = Some SS_listen \<and> |
|
731 |
is_tcp_sock \<tau> (p, fd) \<and> ino \<notin> (current_inode_nums \<tau>))" |
|
732 |
| "os_grant \<tau> (Bind p fd addr) = |
|
733 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
734 |
socket_state \<tau> (p, fd) = Some SS_create)" (* ?? !! (case addr of INET_ADDR ip port \<Rightarrow> ip \<in> local_ipaddrs)) *) |
|
735 |
| "os_grant \<tau> (Connect p fd addr) = |
|
736 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
737 |
socket_state \<tau> (p, fd) = Some SS_bind)" |
|
738 |
| "os_grant \<tau> (Listen p fd) = |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
739 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> is_tcp_sock \<tau> (p, fd) \<and> |
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
740 |
socket_state \<tau> (p, fd) = Some SS_bind)" (* Listen and Accept should only be used for TCP sever side *) |
1 | 741 |
| "os_grant \<tau> (SendSock p fd) = |
742 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
743 |
socket_in_sending \<tau> (p, fd))" |
|
744 |
| "os_grant \<tau> (RecvSock p fd) = |
|
745 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
746 |
socket_in_recving \<tau> (p, fd))" |
|
747 |
| "os_grant \<tau> (Shutdown p fd sh) = |
|
748 |
(p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> |
|
749 |
socket_in_trans \<tau> (p, fd))" |
|
750 |
(* |
|
751 |
| "os_grant \<tau> (ChangeOwner p u) = (p \<in> current_procs \<tau> \<and> u \<in> current_users \<tau>)" |
|
752 |
*) |
|
753 |
| "os_grant \<tau> (Clone p p' fds shms) = |
|
68
742bed613245
simplifing model, by changing sectxt_of_obj s' (O_proc p) of None \<Rightarrow> False
chunhan
parents:
67
diff
changeset
|
754 |
(p \<in> current_procs \<tau> \<and> p' \<notin> (current_procs \<tau>) \<and> fds \<subseteq> proc_file_fds \<tau> p \<and> |
742bed613245
simplifing model, by changing sectxt_of_obj s' (O_proc p) of None \<Rightarrow> False
chunhan
parents:
67
diff
changeset
|
755 |
(\<forall> h \<in> shms. \<exists> flag. (p, flag) \<in> procs_of_shm \<tau> h))" (* current_proc_fds \<rightarrow> proc_file_fds *) |
1 | 756 |
| "os_grant \<tau> (Kill p\<^isub>1 p\<^isub>2) = |
757 |
(p\<^isub>1 \<in> current_procs \<tau> \<and> p\<^isub>2 \<in> current_procs \<tau>)" (* a process can kill itself right? *) |
|
758 |
| "os_grant \<tau> (Exit p) = |
|
759 |
(p \<in> current_procs \<tau>)" |
|
760 |
| "os_grant \<tau> (Ptrace p\<^isub>1 p\<^isub>2) = |
|
761 |
(p\<^isub>1 \<in> current_procs \<tau> \<and> p\<^isub>2 \<in> current_procs \<tau>)" (* a process can trace itself right? *) |
|
762 |
||
763 |
fun alive :: "t_state \<Rightarrow> t_object \<Rightarrow> bool" |
|
764 |
where |
|
765 |
"alive s (O_proc p) = (p \<in> current_procs s)" |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
766 |
| "alive s (O_file f) = (is_file s f)" |
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
767 |
| "alive s (O_dir f) = (is_dir s f)" |
1 | 768 |
| "alive s (O_fd p fd) = (fd \<in> current_proc_fds s p)" |
769 |
| "alive s (O_node n) = (n \<in> init_nodes)" |
|
6
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
770 |
| "alive s (O_tcp_sock k) = (is_tcp_sock s k)" |
8779d321cc2e
remove duplicated pre-condition of current_files in OS_grant, since it is property if is_file/is_dir.
chunhan
parents:
4
diff
changeset
|
771 |
| "alive s (O_udp_sock k) = (is_udp_sock s k)" |
1 | 772 |
| "alive s (O_shm h) = (h \<in> current_shms s)" |
773 |
| "alive s (O_msgq q) = (q \<in> current_msgqs s)" |
|
774 |
| "alive s (O_msg q m) = (m \<in> set (msgs_of_queue s q) \<and> q \<in> current_msgqs s)" |
|
775 |
||
776 |
(* deleted objects should be "taintable" objects, objects like fd should not be in consideration *) |
|
777 |
(* actually, deleted should be renamed as "vanished", cause "exit/closefd" *) |
|
778 |
fun deleted :: "t_object \<Rightarrow> t_event list \<Rightarrow> bool" |
|
779 |
where |
|
780 |
"deleted obj [] = False" |
|
781 |
| "deleted obj (Kill p p' # s) = ((obj = O_proc p') \<or> (\<exists> fd \<in> current_proc_fds s p'. obj = O_fd p' fd) \<or> |
|
782 |
(\<exists> fd. obj = O_tcp_sock (p', fd) \<and> is_tcp_sock s (p',fd)) \<or> |
|
783 |
(\<exists> fd. obj = O_udp_sock (p', fd) \<and> is_udp_sock s (p',fd)) \<or> |
|
784 |
deleted obj s)" |
|
785 |
| "deleted obj (CloseFd p fd # s) = ((obj = O_fd p fd) \<or> (obj = O_tcp_sock (p,fd) \<and> is_tcp_sock s (p,fd)) \<or> |
|
4 | 786 |
(obj = O_udp_sock (p,fd) \<and> is_udp_sock s (p, fd)) \<or> |
787 |
(\<exists> f. obj = O_file f \<and> proc_fd_of_file s f = {(p, fd)} \<and> |
|
788 |
f \<in> files_hung_by_del s) \<or> deleted obj s)" |
|
1 | 789 |
| "deleted obj (Execve p f fds # s) = ((\<exists> fd \<in> current_proc_fds s p. obj = O_fd p fd \<and> fd \<notin> fds) \<or> |
790 |
(\<exists> fd. obj = O_tcp_sock (p, fd) \<and> is_tcp_sock s (p,fd) \<and> fd \<notin> fds) \<or> |
|
791 |
(\<exists> fd. obj = O_udp_sock (p, fd) \<and> is_udp_sock s (p,fd) \<and> fd \<notin> fds) \<or> |
|
792 |
deleted obj s)" |
|
4 | 793 |
| "deleted obj (Clone p p' fds shms # s) = ((\<exists> fd \<in> current_proc_fds s p. obj = O_fd p' fd \<and> fd \<notin> fds) \<or> |
794 |
deleted obj s)" |
|
8 | 795 |
| "deleted obj (UnLink p f # s) = ((proc_fd_of_file s f = {} \<and> obj = O_file f) \<or> deleted obj s)" |
1 | 796 |
| "deleted obj (Rmdir p f # s) = ((obj = O_dir f) \<or> deleted obj s)" |
797 |
| "deleted obj (Exit p # s) = ((obj = O_proc p) \<or> (\<exists> fd \<in> current_proc_fds s p. obj = O_fd p fd) \<or> |
|
798 |
(\<exists> fd. obj = O_tcp_sock (p, fd) \<and> is_tcp_sock s (p,fd)) \<or> |
|
799 |
(\<exists> fd. obj = O_udp_sock (p, fd) \<and> is_udp_sock s (p,fd)) \<or> deleted obj s)" |
|
800 |
(* |
|
801 |
| "deleted obj (Rename p f f' # s) = |
|
802 |
(case obj of |
|
803 |
O_file f'' \<Rightarrow> f \<preceq> f'' \<or> deleted obj s |
|
804 |
| O_dir f'' \<Rightarrow> f \<preceq> f'' \<or> deleted obj s |
|
805 |
| _ \<Rightarrow> deleted obj s)" |
|
806 |
*) |
|
807 |
| "deleted obj (RemoveMsgq p q # s) = (obj = O_msgq q \<or> (\<exists> m. obj = O_msg q m) \<or> deleted obj s)" |
|
808 |
| "deleted obj (DeleteShM p h # s) = (obj = O_shm h \<or> deleted obj s)" |
|
809 |
| "deleted obj (RecvMsg p q m # s) = (obj = O_msg q m \<or> deleted obj s)" |
|
810 |
| "deleted obj (_ # s) = deleted obj s" |
|
811 |
||
812 |
end |
|
813 |
||
814 |
||
815 |
||
816 |
locale flask = init + |
|
817 |
fixes |
|
818 |
(***************** Policy-specific Parameters *************) |
|
819 |
type_transition_rules :: "type_transition_rule_list_t" |
|
820 |
and allowed_rules :: "allowed_rule_list_t" |
|
821 |
and role_allowed_rules :: "role_allow_rule_list_t" |
|
822 |
and role_declaration_rules :: "role_declarations_list_t" |
|
823 |
and role_transition_rules:: "role_transition_rule_list_t" |
|
824 |
and constrains_rules :: "constrains_list_t" |
|
825 |
||
826 |
and init_type_of_obj :: "t_object \<rightharpoonup> type_t" |
|
827 |
and init_user_of_obj :: "t_object \<rightharpoonup> user_t" |
|
828 |
and init_role_of_proc :: "t_process \<rightharpoonup> role_t" |
|
829 |
||
830 |
assumes |
|
831 |
||
832 |
init_obj_has_type: "\<And> obj. init_alive obj \<Longrightarrow> \<exists> t. init_type_of_obj obj = Some t" |
|
833 |
and init_type_has_obj: "\<And> obj t. init_type_of_obj obj = Some t \<Longrightarrow> init_alive obj" |
|
834 |
and init_obj_has_user: "\<And> obj. init_alive obj \<Longrightarrow> \<exists> u. init_user_of_obj obj = Some u" |
|
835 |
and init_user_has_obj: "\<And> obj u. init_user_of_obj obj = Some u \<Longrightarrow> init_alive obj \<and> u \<in> init_users" |
|
836 |
and init_proc_has_role: "bidirect_in_init init_procs init_role_of_proc" |
|
837 |
||
838 |
begin |
|
839 |
||
840 |
(*********** policy-specified computations, not-event-related ************) |
|
841 |
||
842 |
(* security_transition_sid : type_transition_rules |
|
843 |
* It's a system-call offered by security-server? So access-control-checked too? |
|
844 |
* according to selinux, it deals only with execve and file-creation |
|
845 |
* is_execve: if is the execve case |
|
846 |
* is_file: if is the creation of file/dir |
|
847 |
* change from is_execve to is_file, because the new message by default use |
|
848 |
* the type of the sending process too. |
|
849 |
*) |
|
850 |
||
851 |
definition type_transition :: "type_t \<Rightarrow> type_t \<Rightarrow> security_class_t \<Rightarrow> bool \<Rightarrow> type_t" |
|
852 |
where |
|
853 |
"type_transition st rt tc IS_file \<equiv> ( |
|
854 |
case (lookup type_transition_rules |
|
855 |
(\<lambda> (stp, rtp, tc', dt). patt_match stp st \<and> patt_match rtp rt \<and> tc = tc')) of |
|
856 |
None \<Rightarrow> (if IS_file then rt else st) |
|
857 |
| Some (stp,rtp,tc',dt) \<Rightarrow> dt)" |
|
858 |
||
859 |
(* allowed_rule_list *) |
|
860 |
definition TE_allow :: "type_t \<Rightarrow> type_t \<Rightarrow> security_class_t \<Rightarrow> permission_t \<Rightarrow> bool" |
|
861 |
where |
|
862 |
"TE_allow st tt tc perm \<equiv> member allowed_rules |
|
863 |
(\<lambda> (stp, ttp, tc', pp). tc = tc' \<and> patt_match stp st \<and> patt_match_self ttp tt st \<and> |
|
864 |
patt_match pp perm)" |
|
865 |
||
866 |
(* role_allow_rule_list_t *) |
|
867 |
definition role_transition :: "role_t \<Rightarrow> type_t \<Rightarrow> role_t option" |
|
868 |
where |
|
869 |
"role_transition r t \<equiv> |
|
870 |
(case (lookup role_transition_rules (\<lambda> (pr, ft, nr). pr = r \<and> t = ft)) of |
|
871 |
None \<Rightarrow> None |
|
872 |
| Some (pr,ft,nr) \<Rightarrow> Some nr)" |
|
873 |
||
874 |
definition role_decl_check :: "role_t \<Rightarrow> type_t \<Rightarrow> bool" |
|
875 |
where |
|
876 |
"role_decl_check r t \<equiv> member role_declaration_rules (\<lambda> (role, types). r = role \<and> t \<in> types)" |
|
877 |
||
878 |
definition role_allow :: "role_t \<Rightarrow> role_t \<Rightarrow> bool" |
|
879 |
where |
|
880 |
"role_allow r nr \<equiv> member role_allowed_rules (\<lambda> (from, to). r \<in> from \<and> nr \<in> to)" |
|
881 |
||
882 |
(* here don't use lookup, because constrains should all be satisfied, |
|
883 |
* while transitions always choose the "first" one |
|
884 |
*) |
|
885 |
definition constrains_satisfied :: |
|
886 |
"security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_class_t \<Rightarrow> permission_t \<Rightarrow> bool" |
|
887 |
where |
|
888 |
"constrains_satisfied sctxt tctxt c p \<equiv> |
|
889 |
(fold (\<lambda> (cset, pset, P) res. res \<and> (if (c \<in> cset \<and> p \<in> pset) |
|
890 |
then P sctxt tctxt else True)) |
|
891 |
constrains_rules True)" |
|
892 |
||
893 |
(* main interface for TE_allow check and constrains check *) |
|
894 |
fun permission_check:: |
|
895 |
"security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_class_t \<Rightarrow> permission_t \<Rightarrow> bool" |
|
896 |
where |
|
897 |
"permission_check (su,sr,st) (tu,tr,tt) c p = |
|
898 |
((TE_allow st tt c p) \<and> (constrains_satisfied (su,sr,st) (tu,tr,tt) c p))" |
|
899 |
declare permission_check.simps [simp del] |
|
900 |
||
901 |
(* no changeowner ??? : by adding "relabel obj sectxt" event or "login" event? |
|
902 |
* or this explanation: the running of the sever will not grant any login but running |
|
903 |
* of the server-programs! |
|
904 |
*) |
|
905 |
||
906 |
fun user_of_obj :: "t_state \<Rightarrow> t_object \<Rightarrow> user_t option" |
|
907 |
where |
|
908 |
"user_of_obj [] = init_user_of_obj" |
|
909 |
| "user_of_obj (Clone p p' fds shms # s) = |
|
910 |
(\<lambda> obj. case obj of |
|
911 |
O_proc p'' \<Rightarrow> if (p'' = p') then user_of_obj s (O_proc p) else user_of_obj s obj |
|
912 |
| O_fd p'' fd \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then user_of_obj s (O_fd p fd) |
|
913 |
else if (p'' = p') then None |
|
914 |
else user_of_obj s obj |
|
915 |
| O_tcp_sock (p'',fd) \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then user_of_obj s (O_tcp_sock (p, fd)) |
|
916 |
else if (p'' = p') then None |
|
917 |
else user_of_obj s obj |
|
918 |
| O_udp_sock (p'',fd) \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then user_of_obj s (O_udp_sock (p, fd)) |
|
919 |
else if (p'' = p') then None |
|
920 |
else user_of_obj s obj |
|
921 |
| _ \<Rightarrow> user_of_obj s obj)" |
|
922 |
| "user_of_obj (Open p f flags fd iopt # s) = |
|
923 |
(case iopt of |
|
924 |
None \<Rightarrow> (user_of_obj s) ((O_fd p fd) := user_of_obj s (O_proc p)) |
|
925 |
| _ \<Rightarrow> ((user_of_obj s) ((O_fd p fd) := user_of_obj s (O_proc p))) |
|
926 |
((O_file f) := user_of_obj s (O_proc p)))" |
|
927 |
| "user_of_obj (Mkdir p f inum # s) = |
|
928 |
(user_of_obj s) ((O_dir f) := user_of_obj s (O_proc p))" |
|
929 |
| "user_of_obj (LinkHard p f f' # s) = |
|
930 |
(user_of_obj s) ((O_file f') := user_of_obj s (O_proc p))" |
|
931 |
(* |
|
932 |
| "user_of_obj (Rename p f2 f3 # s) = |
|
933 |
(\<lambda> obj. case obj of |
|
934 |
O_file f \<Rightarrow> if (f3 \<preceq> f) then user_of_obj s (O_file (file_before_rename f2 f3 f)) |
|
935 |
else user_of_obj s obj |
|
936 |
| O_dir f \<Rightarrow> if (f3 \<preceq> f) then user_of_obj s (O_dir (file_before_rename f2 f3 f)) |
|
937 |
else user_of_obj s obj |
|
938 |
| _ \<Rightarrow> user_of_obj s obj)" |
|
939 |
*) |
|
940 |
| "user_of_obj (CreateMsgq p q # s) = |
|
941 |
(user_of_obj s) ((O_msgq q) := user_of_obj s (O_proc p))" |
|
942 |
| "user_of_obj (SendMsg p q m # s) = |
|
943 |
(user_of_obj s) ((O_msg q m) := user_of_obj s (O_proc p))" |
|
944 |
| "user_of_obj (CreateShM p h # s) = |
|
945 |
(user_of_obj s) ((O_shm h) := user_of_obj s (O_proc p))" |
|
946 |
| "user_of_obj (CreateSock p af st fd inum # s) = (\<lambda> obj. |
|
947 |
case obj of |
|
948 |
O_fd p' fd' \<Rightarrow> if (p' = p \<and> fd' = fd) then user_of_obj s (O_proc p) |
|
949 |
else user_of_obj s obj |
|
950 |
| O_tcp_sock (p', fd') \<Rightarrow> if (p' = p \<and> fd' = fd \<and> st = STREAM) then user_of_obj s (O_proc p) |
|
951 |
else user_of_obj s obj |
|
952 |
| O_udp_sock (p', fd') \<Rightarrow> if (p' = p \<and> fd' = fd \<and> st = DGRAM) then user_of_obj s (O_proc p) |
|
953 |
else user_of_obj s obj |
|
954 |
| _ \<Rightarrow> user_of_obj s obj )" |
|
955 |
| "user_of_obj (Accept p fd addr port fd' inum # s) = (\<lambda> obj. |
|
956 |
case obj of |
|
957 |
O_fd p' fd'' \<Rightarrow> if (p' = p \<and> fd'' = fd') then user_of_obj s (O_proc p) |
|
958 |
else user_of_obj s obj |
|
959 |
| O_tcp_sock (p', fd'') \<Rightarrow> if (p' = p \<and> fd'' = fd') then user_of_obj s (O_proc p) |
|
960 |
else user_of_obj s obj |
|
961 |
| _ \<Rightarrow> user_of_obj s obj )" |
|
962 |
| "user_of_obj (_ # s) = user_of_obj s" |
|
963 |
||
964 |
fun type_of_obj :: "t_state \<Rightarrow> (t_object \<Rightarrow> type_t option)" |
|
965 |
where |
|
966 |
"type_of_obj [] = init_type_of_obj" |
|
967 |
| "type_of_obj (Clone p p' fds shms # s) = (\<lambda> obj. |
|
968 |
case obj of |
|
969 |
O_proc p'' \<Rightarrow> if (p'' = p') then type_of_obj s (O_proc p) else type_of_obj s obj |
|
970 |
| O_fd p'' fd \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then type_of_obj s (O_fd p fd) |
|
971 |
else if (p'' = p') then None |
|
972 |
else type_of_obj s obj |
|
973 |
| O_tcp_sock (p'', fd) \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then type_of_obj s (O_tcp_sock (p, fd)) |
|
974 |
else if (p'' = p') then None |
|
975 |
else type_of_obj s obj |
|
976 |
| O_udp_sock (p'', fd) \<Rightarrow> if (p'' = p' \<and> fd \<in> fds) then type_of_obj s (O_udp_sock (p, fd)) |
|
977 |
else if (p'' = p') then None |
|
978 |
else type_of_obj s obj |
|
979 |
| _ \<Rightarrow> type_of_obj s obj )" |
|
980 |
| "type_of_obj (Execve p f fds # s) = (type_of_obj s) ((O_proc p) := |
|
981 |
(case (type_of_obj s (O_proc p), type_of_obj s (O_file f)) of |
|
982 |
(Some tp, Some tf) \<Rightarrow> Some (type_transition tp tf C_process False) |
|
983 |
| _ \<Rightarrow> None) )" |
|
984 |
| "type_of_obj (Open p f flags fd (Some inum) # s) = ((type_of_obj s) ((O_file f) := |
|
985 |
(case (parent f) of |
|
986 |
Some pf \<Rightarrow> (case (type_of_obj s (O_proc p), type_of_obj s (O_dir pf)) of |
|
987 |
(Some tp, Some tpf) \<Rightarrow> Some (type_transition tp tpf C_file True) |
|
988 |
| _ \<Rightarrow> None) |
|
989 |
| _ \<Rightarrow> None) )) ((O_fd p fd) := |
|
990 |
type_of_obj s (O_proc p))" |
|
991 |
| "type_of_obj (Open p f flags fd None # s) = (type_of_obj s) ((O_fd p fd) := |
|
992 |
type_of_obj s (O_proc p))" |
|
993 |
| "type_of_obj (Mkdir p f inum # s) = (type_of_obj s) ((O_dir f) := |
|
994 |
(case (parent f) of |
|
995 |
Some pf \<Rightarrow> (case (type_of_obj s (O_proc p), type_of_obj s (O_dir pf)) of |
|
996 |
(Some tp, Some tpf) \<Rightarrow> Some (type_transition tp tpf C_dir True) |
|
997 |
| _ \<Rightarrow> None) |
|
998 |
| _ \<Rightarrow> None) )" |
|
999 |
| "type_of_obj (LinkHard p f f' # s) = (type_of_obj s) ((O_file f') := |
|
1000 |
(case (parent f') of |
|
1001 |
Some pf \<Rightarrow> (case (type_of_obj s (O_proc p), type_of_obj s (O_dir pf)) of |
|
1002 |
(Some tp, Some tpf) \<Rightarrow> Some (type_transition tp tpf C_file True) |
|
1003 |
| _ \<Rightarrow> None) |
|
1004 |
| _ \<Rightarrow> None) )" |
|
1005 |
(* |
|
1006 |
| "type_of_obj (Rename p f f' # s) = (\<lambda> obj. |
|
1007 |
case obj of |
|
1008 |
O_file f'' \<Rightarrow> (if (f' \<preceq> f'') then type_of_obj s (O_file (file_before_rename f f' f'')) |
|
1009 |
else type_of_obj s (O_file f'')) |
|
1010 |
| O_dir f'' \<Rightarrow> (if (f' \<preceq> f'') then type_of_obj s (O_file (file_before_rename f f' f'')) |
|
1011 |
else type_of_obj s (O_file f'')) |
|
1012 |
| _ \<Rightarrow> type_of_obj s obj )" |
|
1013 |
*) |
|
1014 |
| "type_of_obj (CreateMsgq p q # s) = (type_of_obj s) ((O_msgq q) := |
|
1015 |
(case (type_of_obj s (O_proc p)) of |
|
1016 |
Some tp \<Rightarrow> Some tp |
|
1017 |
| _ \<Rightarrow> None) )" |
|
1018 |
| "type_of_obj (SendMsg p q m # s) = (type_of_obj s) ((O_msg q m) := |
|
1019 |
(case (type_of_obj s (O_proc p), type_of_obj s (O_msgq q)) of |
|
1020 |
(Some tp, Some tq) \<Rightarrow> Some (type_transition tp tq C_msg False) |
|
1021 |
| _ \<Rightarrow> None) )" |
|
1022 |
| "type_of_obj (CreateShM p h # s) = (type_of_obj s) ((O_shm h) := |
|
1023 |
(case (type_of_obj s (O_proc p)) of |
|
1024 |
Some tp \<Rightarrow> Some tp |
|
1025 |
| _ \<Rightarrow> None) )" |
|
1026 |
| "type_of_obj (CreateSock p af st fd inum # s) = (\<lambda> obj. |
|
1027 |
case obj of |
|
1028 |
O_fd p' fd' \<Rightarrow> if (p' = p \<and> fd' = fd) then type_of_obj s (O_proc p) |
|
1029 |
else type_of_obj s obj |
|
1030 |
| O_tcp_sock (p', fd') \<Rightarrow> if (p' = p \<and> fd' = fd \<and> st = STREAM) then type_of_obj s (O_proc p) |
|
1031 |
else type_of_obj s obj |
|
1032 |
| O_udp_sock (p', fd') \<Rightarrow> if (p' = p \<and> fd' = fd \<and> st = DGRAM) then type_of_obj s (O_proc p) |
|
1033 |
else type_of_obj s obj |
|
1034 |
| _ \<Rightarrow> type_of_obj s obj )" |
|
1035 |
| "type_of_obj (Accept p fd addr port fd' inum # s) = (\<lambda> obj. |
|
1036 |
case obj of |
|
1037 |
O_fd p' fd'' \<Rightarrow> if (p' = p \<and> fd'' = fd') then type_of_obj s (O_proc p) |
|
1038 |
else type_of_obj s obj |
|
1039 |
| O_tcp_sock (p', fd'') \<Rightarrow> if (p' = p \<and> fd'' = fd') then type_of_obj s (O_proc p) |
|
1040 |
else type_of_obj s obj |
|
1041 |
| _ \<Rightarrow> type_of_obj s obj )" |
|
1042 |
| "type_of_obj (_ # s) = type_of_obj s" |
|
1043 |
||
1044 |
fun role_of_proc :: "t_state \<Rightarrow> (t_process \<Rightarrow> role_t option)" |
|
1045 |
where |
|
1046 |
"role_of_proc [] = init_role_of_proc" |
|
1047 |
| "role_of_proc (Clone p p' fds shms # s) = |
|
1048 |
(role_of_proc s) (p' := role_of_proc s p)" |
|
1049 |
| "role_of_proc (Execve p f fds # s) = (role_of_proc s) (p := |
|
1050 |
(case (role_of_proc s p, type_of_obj s (O_file f)) of |
|
1051 |
(Some r, Some ft) \<Rightarrow> role_transition r ft |
|
1052 |
| _ \<Rightarrow> None) )" |
|
1053 |
| "role_of_proc (_ # s) = role_of_proc s" |
|
1054 |
||
1055 |
fun role_of_obj :: "t_state \<Rightarrow> t_object \<Rightarrow> role_t option" |
|
1056 |
where |
|
1057 |
"role_of_obj s (O_proc p) = role_of_proc s p" |
|
1058 |
| "role_of_obj s _ = Some R_object" (* object_r *) |
|
1059 |
||
1060 |
definition sectxt_of_obj :: "t_state \<Rightarrow> t_object \<Rightarrow> security_context_t option" |
|
1061 |
where |
|
1062 |
"sectxt_of_obj s obj = ( |
|
1063 |
case (user_of_obj s obj, role_of_obj s obj, type_of_obj s obj) of |
|
1064 |
(Some u, Some r, Some t) \<Rightarrow> Some (u, r, t) |
|
1065 |
| _ \<Rightarrow> None)" |
|
1066 |
||
7 | 1067 |
fun init_role_of_obj :: "t_object \<Rightarrow> role_t option" |
1068 |
where |
|
1069 |
"init_role_of_obj (O_proc p) = init_role_of_proc p" |
|
1070 |
| "init_role_of_obj _ = Some R_object" |
|
1071 |
||
1072 |
definition init_sectxt_of_obj :: "t_object \<Rightarrow> security_context_t option" |
|
1073 |
where |
|
1074 |
"init_sectxt_of_obj obj \<equiv> |
|
1075 |
(case (init_user_of_obj obj, init_role_of_obj obj, init_type_of_obj obj) of |
|
1076 |
(Some u, Some r, Some t) \<Rightarrow> Some (u,r,t) |
|
1077 |
| _ \<Rightarrow> None)" |
|
1078 |
||
1079 |
definition sec_of_root :: "security_context_t" |
|
1080 |
where |
|
1081 |
"sec_of_root \<equiv> (case (init_user_of_obj (O_dir []), init_type_of_obj (O_dir [])) of |
|
1082 |
(Some u, Some t) \<Rightarrow> (u, R_object, t))" |
|
1083 |
||
1 | 1084 |
(******* flask granting ******** |
1085 |
* involves three kinds of rules: |
|
1086 |
* 1. allow rule of types, allowed_rule_list_t, main |
|
1087 |
* 2. allow rule of roles, role_allow_rule_list_t, mainly for execve call |
|
1088 |
* 3. constrains, section 3.4.5, user-specifically defined. |
|
1089 |
* Passed all these 3, then grant Yes, else No |
|
1090 |
*) |
|
1091 |
||
1092 |
definition search_check_allp :: "security_context_t \<Rightarrow> security_context_t set \<Rightarrow> bool" |
|
1093 |
where |
|
1094 |
"search_check_allp pctxt sectxts = (\<forall> sec \<in> sectxts. permission_check pctxt sec C_dir P_search)" |
|
1095 |
||
1096 |
definition search_check_file :: "security_context_t \<Rightarrow> security_context_t \<Rightarrow> bool" |
|
1097 |
where |
|
1098 |
"search_check_file sctxt fctxt \<equiv> permission_check sctxt fctxt C_file P_search" |
|
1099 |
||
1100 |
definition search_check_dir :: "security_context_t \<Rightarrow> security_context_t \<Rightarrow> bool" |
|
1101 |
where |
|
1102 |
"search_check_dir sctxt fctxt \<equiv> permission_check sctxt fctxt C_dir P_search" |
|
1103 |
||
1104 |
fun get_parentfs_ctxts :: "t_state \<Rightarrow> t_file \<Rightarrow> (security_context_t list) option" |
|
1105 |
where |
|
1106 |
"get_parentfs_ctxts s [] = |
|
1107 |
(case (sectxt_of_obj s (O_dir [])) of |
|
1108 |
Some ctxt \<Rightarrow> Some [ctxt] |
|
1109 |
| _ \<Rightarrow> None)" |
|
1110 |
| "get_parentfs_ctxts s (f#pf) = |
|
1111 |
(case (get_parentfs_ctxts s pf, sectxt_of_obj s (O_dir (f#pf))) of |
|
1112 |
(Some ctxts, Some ctxt) \<Rightarrow> Some (ctxt#ctxts) |
|
1113 |
| _ \<Rightarrow> None)" |
|
1114 |
||
67 | 1115 |
definition search_check_ctxt:: |
1116 |
"security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_context_t set \<Rightarrow> bool \<Rightarrow> bool" |
|
1117 |
where |
|
1118 |
"search_check_ctxt pctxt fctxt asecs if_file \<equiv> ( |
|
1119 |
if if_file |
|
1120 |
then search_check_file pctxt fctxt \<and> search_check_allp pctxt asecs |
|
1121 |
else search_check_dir pctxt fctxt \<and> search_check_allp pctxt asecs )" |
|
1122 |
||
1 | 1123 |
fun search_check :: "t_state \<Rightarrow> security_context_t \<Rightarrow> t_file \<Rightarrow> bool" |
1124 |
where |
|
1125 |
"search_check s pctxt [] = |
|
1126 |
(case (sectxt_of_obj s (O_dir [])) of |
|
67 | 1127 |
Some fctxt \<Rightarrow> search_check_ctxt pctxt fctxt {} False |
1 | 1128 |
| _ \<Rightarrow> False)" |
1129 |
| "search_check s pctxt (f#pf) = |
|
1130 |
(if (is_file s (f#pf)) |
|
1131 |
then (case (sectxt_of_obj s (O_file (f#pf)), get_parentfs_ctxts s pf) of |
|
67 | 1132 |
(Some fctxt, Some pfctxts) \<Rightarrow> search_check_ctxt pctxt fctxt (set pfctxts) True |
1 | 1133 |
| _ \<Rightarrow> False) |
1134 |
else (case (sectxt_of_obj s (O_dir (f#pf)), get_parentfs_ctxts s pf) of |
|
67 | 1135 |
(Some fctxt, Some pfctxts) \<Rightarrow> search_check_ctxt pctxt fctxt (set pfctxts) False |
1 | 1136 |
| _ \<Rightarrow> False))" |
1137 |
||
1138 |
(* this means we should prove every current fd has a security context! *) |
|
1139 |
definition sectxts_of_fds :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd set \<Rightarrow> security_context_t set" |
|
1140 |
where |
|
1141 |
"sectxts_of_fds s p fds \<equiv> {ctxt. \<exists> fd \<in> fds. sectxt_of_obj s (O_fd p fd) = Some ctxt}" |
|
1142 |
||
67 | 1143 |
definition inherit_fds_check_ctxt:: "security_context_t \<Rightarrow> security_context_t set \<Rightarrow> bool" |
1144 |
where |
|
1145 |
"inherit_fds_check_ctxt p fds \<equiv> (\<forall> ctxt \<in> fds. permission_check p ctxt C_fd P_inherit)" |
|
1146 |
||
1 | 1147 |
definition inherit_fds_check :: "t_state \<Rightarrow> security_context_t \<Rightarrow> t_process \<Rightarrow> t_fd set \<Rightarrow> bool" |
1148 |
where |
|
67 | 1149 |
"inherit_fds_check s npsectxt p fds \<equiv> inherit_fds_check_ctxt npsectxt (sectxts_of_fds s p fds)" |
1 | 1150 |
|
1151 |
fun npctxt_execve :: "security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_context_t option" |
|
1152 |
where |
|
1153 |
"npctxt_execve (pu,pr,pt) (fu,fr,ft) = |
|
1154 |
(case (role_transition pr ft) of |
|
1155 |
Some nr \<Rightarrow> Some (pu, nr, type_transition pt ft C_process False) |
|
1156 |
| _ \<Rightarrow> None)" |
|
1157 |
||
1158 |
fun nfctxt_create :: "security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_class_t \<Rightarrow> security_context_t" |
|
1159 |
where |
|
1160 |
"nfctxt_create (pu,pr,pt) (fu,fr,ft) cls = (pu, R_object, type_transition pt ft cls True)" |
|
1161 |
||
1162 |
fun grant_execve :: |
|
1163 |
"security_context_t \<Rightarrow> security_context_t \<Rightarrow> security_context_t \<Rightarrow> bool" |
|
1164 |
where |
|
1165 |
"grant_execve (up,rp,tp) (uf,rf,tf) (up',nr,nt) = |
|
1166 |
(role_decl_check nr nt \<and> role_allow rp nr \<and> |
|
1167 |
permission_check (up,rp,tp) (uf,rf,tf) C_file P_execute \<and> |
|
1168 |
permission_check (up,nr,nt) (uf,rf,tf) C_file P_entrypoint \<and> |
|
1169 |
permission_check (up,rp,tp) (up,nr,nt) C_process P_transition \<and> |
|
1170 |
permission_check (up,nr,nt) (uf,rf,tf) C_process P_execute)" |
|
1171 |
||
1172 |
definition sectxts_of_shms :: "t_state \<Rightarrow> t_shm set \<Rightarrow> security_context_t set" |
|
1173 |
where |
|
1174 |
"sectxts_of_shms s shms \<equiv> {ctxt. \<exists> h \<in> shms. sectxt_of_obj s (O_shm h) = Some ctxt}" |
|
1175 |
||
67 | 1176 |
definition inherit_shms_check_ctxt:: "security_context_t \<Rightarrow> security_context_t set \<Rightarrow> bool" |
1177 |
where |
|
1178 |
"inherit_shms_check_ctxt p shms \<equiv> (\<forall> ctxt \<in> shms. permission_check p ctxt C_shm P_inherit)" |
|
1179 |
||
1 | 1180 |
definition inherit_shms_check :: "t_state \<Rightarrow> security_context_t \<Rightarrow> t_shm set \<Rightarrow> bool" |
1181 |
where |
|
67 | 1182 |
"inherit_shms_check s npsectxt shms \<equiv> inherit_shms_check_ctxt npsectxt (sectxts_of_shms s shms)" |
1 | 1183 |
|
1184 |
fun perm_of_mflag :: "t_open_must_flag \<Rightarrow> permission_t set" |
|
1185 |
where |
|
1186 |
"perm_of_mflag OF_RDONLY = {P_read}" |
|
1187 |
| "perm_of_mflag OF_WRONLY = {P_write}" |
|
1188 |
| "perm_of_mflag OF_RDWR = {P_read, P_write}" |
|
1189 |
||
1190 |
definition perm_of_oflag :: "t_open_option_flag set \<Rightarrow> permission_t set" |
|
1191 |
where |
|
1192 |
"perm_of_oflag oflags \<equiv> |
|
1193 |
(case (OF_APPEND \<in> oflags, OF_CREAT \<in> oflags) of |
|
1194 |
(True, True) \<Rightarrow> {P_append, P_create} |
|
1195 |
| (True, _ ) \<Rightarrow> {P_append} |
|
1196 |
| (_ , True) \<Rightarrow> {P_create} |
|
1197 |
| _ \<Rightarrow> {})" |
|
1198 |
||
1199 |
definition perms_of_flags :: "t_open_flags \<Rightarrow> permission_t set" |
|
1200 |
where |
|
1201 |
"perms_of_flags flags \<equiv> |
|
1202 |
(case flags of |
|
1203 |
(mflag,oflags) \<Rightarrow> (perm_of_mflag mflag \<union> perm_of_oflag oflags))" |
|
1204 |
||
1205 |
(* |
|
1206 |
definition class_of_flags :: "t_open_flags \<Rightarrow> security_class_t" |
|
1207 |
where |
|
1208 |
"class_of_flags flags \<equiv> |
|
1209 |
(case flags of |
|
1210 |
(mflag, oflags) \<Rightarrow> if (OF_DIRECTORY \<in> oflags) then C_dir else C_file)" |
|
1211 |
||
1212 |
definition obj_of_flags :: "t_open_flags \<Rightarrow> t_file \<Rightarrow> t_object" |
|
1213 |
where |
|
1214 |
"obj_of_flags flags f \<equiv> |
|
1215 |
(case flags of |
|
1216 |
(mflag, oflags) \<Rightarrow> if (OF_DIRECTORY \<in> oflags) then O_dir f else O_file f)" |
|
1217 |
*) |
|
1218 |
||
1219 |
definition oflags_check :: "t_open_flags \<Rightarrow> security_context_t \<Rightarrow> security_context_t \<Rightarrow> bool" |
|
1220 |
where |
|
1221 |
"oflags_check flags pctxt fctxt \<equiv> |
|
1222 |
\<forall> perm \<in> (perms_of_flags flags). permission_check pctxt fctxt C_file perm" |
|
1223 |
||
1224 |
fun grant :: "t_state \<Rightarrow> t_event \<Rightarrow> bool" |
|
1225 |
where |
|
1226 |
"grant s (Execve p f fds) = |
|
1227 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_file f)) of |
|
1228 |
(Some (up, rp, tp), Some (uf, rf, tf)) \<Rightarrow> |
|
1229 |
(case (npctxt_execve (up,rp,tp) (uf,rf,tf)) of |
|
1230 |
Some (pu,nr,nt) \<Rightarrow> ( |
|
1231 |
search_check s (up,rp,tp) f \<and> |
|
1232 |
grant_execve (up,rp,tp) (uf,rf,tf) (up,nr,nt) \<and> |
|
1233 |
inherit_fds_check s (up,nr,nt) p fds) |
|
1234 |
| _ \<Rightarrow> False) |
|
1235 |
| _ \<Rightarrow> False )" |
|
1236 |
| "grant s (Clone p p' fds shms) = |
|
1237 |
(case (sectxt_of_obj s (O_proc p)) of |
|
1238 |
Some (up, rp, tp) \<Rightarrow> |
|
1239 |
(permission_check (up,rp,tp) (up,rp,tp) C_process P_fork \<and> |
|
1240 |
inherit_fds_check s (up,rp,tp) p fds \<and> |
|
1241 |
inherit_shms_check s (up,rp,tp) shms) |
|
1242 |
| _ \<Rightarrow> False )" |
|
1243 |
| "grant s (Kill p p') = |
|
1244 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_proc p')) of |
|
1245 |
(Some (su,sr,st), Some (tu,tr,tt)) \<Rightarrow> |
|
1246 |
permission_check (su,sr,st) (tu,tr,tt) C_process P_sigkill |
|
1247 |
| _ \<Rightarrow> False)" |
|
1248 |
| "grant s (Ptrace p p') = |
|
1249 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_proc p')) of |
|
1250 |
(Some (su,sr,st), Some (tu,tr,tt)) \<Rightarrow> |
|
1251 |
permission_check (su,sr,st) (tu,tr,tt) C_process P_ptrace |
|
1252 |
| _ \<Rightarrow> False)" |
|
1253 |
| "grant s (Exit p) = True" |
|
1254 |
| "grant s (Open p f flags fd None) = |
|
1255 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_file f)) of |
|
1256 |
(Some (pu,pr,pt), Some (fu,fr,ft)) \<Rightarrow> |
|
1257 |
search_check s (pu,pr,pt) f \<and> |
|
1258 |
oflags_check flags (pu,pr,pt) (fu,fr,ft) \<and> |
|
1259 |
permission_check (pu,pr,pt) (pu,pr,pt) C_fd P_setattr |
|
1260 |
| _ \<Rightarrow>False)" |
|
1261 |
| "grant s (Open p f flags fd (Some inum)) = |
|
1262 |
(case (parent f) of |
|
1263 |
Some pf \<Rightarrow> (case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf)) of |
|
1264 |
(Some (pu,pr,pt), Some (pfu,pfr,pft)) \<Rightarrow> |
|
1265 |
(search_check s (pu,pr,pt) pf \<and> |
|
1266 |
oflags_check flags (pu,pr,pt) (nfctxt_create (pu,pr,pt) (pfu,pfr,pft) C_file) \<and> |
|
1267 |
permission_check (pu,pr,pt) (pfu,pfr,pft) C_dir P_add_name \<and> |
|
1268 |
permission_check (pu,pr,pt) (pu,pr,pt) C_fd P_setattr) |
|
1269 |
| _ \<Rightarrow> False) |
|
1270 |
| _ \<Rightarrow> False)" |
|
1271 |
| "grant s (ReadFile p fd) = |
|
1272 |
(case (file_of_proc_fd s p fd) of |
|
1273 |
Some f \<Rightarrow> |
|
1274 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_fd p fd), |
|
1275 |
sectxt_of_obj s (O_file f)) of |
|
1276 |
(Some (pu,pr,pt), Some (fdu,fdr,fdt), Some (fu,fr,ft)) \<Rightarrow> |
|
1277 |
(permission_check (pu,pr,pt) (fdu,fdr,fdt) C_fd P_setattr \<and> |
|
1278 |
permission_check (pu,pr,pt) (fu,fr,ft) C_file P_read) |
|
1279 |
| _ \<Rightarrow> False) |
|
1280 |
| _ \<Rightarrow> False)" |
|
1281 |
| "grant s (WriteFile p fd) = |
|
1282 |
(case (file_of_proc_fd s p fd) of |
|
1283 |
Some f \<Rightarrow> |
|
1284 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_fd p fd), |
|
1285 |
sectxt_of_obj s (O_file f)) of |
|
1286 |
(Some (pu,pr,pt), Some (fdu,fdr,fdt), Some (fu,fr,ft)) \<Rightarrow> |
|
1287 |
(permission_check (pu,pr,pt) (fdu,fdr,fdt) C_fd P_setattr \<and> |
|
1288 |
permission_check (pu,pr,pt) (fu,fr,ft) C_file P_write) |
|
1289 |
| _ \<Rightarrow> False) |
|
1290 |
| _ \<Rightarrow> False)" |
|
1291 |
| "grant s (CloseFd p fd) = True" |
|
1292 |
| "grant s (UnLink p f) = |
|
1293 |
(case (parent f) of |
|
1294 |
Some pf \<Rightarrow> |
|
1295 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf), |
|
1296 |
sectxt_of_obj s (O_file f)) of |
|
1297 |
(Some (pu,pr,pt), Some (du,dr,dt), Some (fu,fr,ft)) \<Rightarrow> |
|
1298 |
(search_check s (pu,pr,pt) f \<and> |
|
1299 |
permission_check (pu,pr,pt) (fu,fr,ft) C_file P_unlink \<and> |
|
1300 |
permission_check (pu,pr,pt) (du,dr,dt) C_dir P_remove_name) |
|
1301 |
| _ \<Rightarrow> False) |
|
1302 |
| _ \<Rightarrow> False)" |
|
1303 |
| "grant s (Rmdir p f) = |
|
1304 |
(case (parent f) of |
|
1305 |
Some pf \<Rightarrow> |
|
1306 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf), |
|
1307 |
sectxt_of_obj s (O_dir f)) of |
|
1308 |
(Some (pu,pr,pt), Some (du,dr,dt), Some (fu,fr,ft)) \<Rightarrow> |
|
1309 |
(search_check s (pu,pr,pt) f \<and> |
|
1310 |
permission_check (pu,pr,pt) (fu,fr,ft) C_dir P_rmdir \<and> |
|
1311 |
permission_check (pu,pr,pt) (du,dr,dt) C_dir P_remove_name) |
|
1312 |
| _ \<Rightarrow> False) |
|
1313 |
| _ \<Rightarrow> False)" |
|
1314 |
| "grant s (Mkdir p f inum) = |
|
1315 |
(case (parent f) of |
|
1316 |
Some pf \<Rightarrow> |
|
1317 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf)) of |
|
1318 |
(Some (pu,pr,pt), Some (du,dr,dt)) \<Rightarrow> |
|
78 | 1319 |
(search_check s (pu,pr,pt) pf \<and> |
1 | 1320 |
permission_check (pu,pr,pt) (nfctxt_create (pu,pr,pt) (du,dr,dt) C_dir) C_dir P_create \<and> |
1321 |
permission_check (pu,pr,pt) (du,dr,dt) C_dir P_add_name) |
|
1322 |
| _ \<Rightarrow> False) |
|
1323 |
| _ \<Rightarrow> False)" |
|
1324 |
| "grant s (LinkHard p f f') = |
|
1325 |
(case (parent f') of |
|
1326 |
Some pf \<Rightarrow> |
|
1327 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf), |
|
1328 |
sectxt_of_obj s (O_file f)) of |
|
1329 |
(Some (pu,pr,pt), Some (du,dr,dt), Some (fu,fr,ft)) \<Rightarrow> |
|
1330 |
(search_check s (pu,pr,pt) f \<and> search_check s (pu,pr,pt) pf \<and> |
|
1331 |
permission_check (pu,pr,pt) (fu,fr,ft) C_file P_link \<and> |
|
1332 |
permission_check (pu,pr,pt) (du,dr,dt) C_dir P_add_name) |
|
1333 |
| _ \<Rightarrow> False) |
|
1334 |
| _ \<Rightarrow> False)" |
|
1335 |
| "grant s (Truncate p f len) = |
|
1336 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_file f)) of |
|
1337 |
(Some (pu,pr,pt), Some (fu,fr,ft)) \<Rightarrow> |
|
1338 |
(search_check s (pu,pr,pt) f \<and> |
|
1339 |
permission_check (pu,pr,pt) (fu,fr,ft) C_file P_setattr) |
|
1340 |
| _ \<Rightarrow> False)" |
|
1341 |
(* |
|
1342 |
| "grant s (Rename p f f') = |
|
1343 |
(case (parent f, parent f') of |
|
1344 |
(Some pf, Some pf') \<Rightarrow> |
|
1345 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_dir pf), |
|
1346 |
sectxt_of_obj s (O_file f), sectxt_of_obj s (O_dir pf')) of |
|
1347 |
(Some (pu,pr,pt), Some (pfu,pfr,pft), Some (fu,fr,ft), |
|
1348 |
Some (pfu',pfr',pft')) \<Rightarrow> |
|
1349 |
(search_check s (pu,pr,pt) f \<and> |
|
1350 |
permission_check (pu,pr,pt) (pfu,pfr,pft) C_dir P_remove_name \<and> |
|
1351 |
(if (is_file s f) |
|
1352 |
then permission_check (pu,pr,pt) (fu,fr,ft) C_file P_rename |
|
1353 |
else permission_check (pu,pr,pt) (fu,fr,ft) C_dir P_reparent) \<and> |
|
1354 |
search_check s (pu,pr,pt) pf' \<and> |
|
1355 |
permission_check (pu,pr,pt) (pfu',pfr',pft') C_dir P_add_name) |
|
1356 |
| _ \<Rightarrow> False) |
|
1357 |
| _ \<Rightarrow> False)" |
|
1358 |
*) |
|
1359 |
| "grant s (CreateMsgq p q) = |
|
1360 |
(case (sectxt_of_obj s (O_proc p)) of |
|
1361 |
Some (pu,pr,pt) \<Rightarrow> |
|
1362 |
(permission_check (pu,pr,pt) (pu,pr,pt) C_msgq P_associate \<and> |
|
1363 |
permission_check (pu,pr,pt) (pu,pr,pt) C_msgq P_create) |
|
1364 |
| _ \<Rightarrow> False)" |
|
1365 |
| "grant s (SendMsg p q m) = |
|
1366 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_msgq q)) of |
|
1367 |
(Some (pu,pr,pt), Some (qu,qr,qt)) \<Rightarrow> |
|
1368 |
(permission_check (pu,pr,pt) (qu,qr,qt) C_msgq P_enqueue \<and> |
|
1369 |
permission_check (pu,pr,pt) (qu,qr,qt) C_msgq P_write \<and> |
|
1370 |
permission_check (pu,pr,pt) (pu,pr,pt) C_msg P_send) |
|
1371 |
| _ \<Rightarrow> False)" |
|
1372 |
| "grant s (RecvMsg p q m) = |
|
1373 |
(case (sectxt_of_obj s (O_proc p),sectxt_of_obj s (O_msgq q),sectxt_of_obj s (O_msg q m)) of |
|
1374 |
(Some (pu,pr,pt), Some (qu,qr,qt), Some (mu,mr,mt)) \<Rightarrow> |
|
1375 |
permission_check (pu,pr,pt) (qu,qr,qt) C_msgq P_read \<and> |
|
1376 |
permission_check (pu,pr,pt) (mu,mr,mt) C_msg P_receive |
|
1377 |
| _ \<Rightarrow> False)" |
|
1378 |
| "grant s (RemoveMsgq p q) = |
|
1379 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_msgq q)) of |
|
1380 |
(Some (pu,pr,pt), Some (qu,qr,qt)) \<Rightarrow> |
|
1381 |
permission_check (pu,pr,pt) (qu,qr,qt) C_msgq P_destroy |
|
1382 |
| _ \<Rightarrow> False)" |
|
1383 |
| "grant s (CreateShM p h) = |
|
1384 |
(case (sectxt_of_obj s (O_proc p)) of |
|
1385 |
Some (pu,pr,pt) \<Rightarrow> |
|
1386 |
(permission_check (pu,pr,pt) (pu,pr,pt) C_shm P_associate \<and> |
|
1387 |
permission_check (pu,pr,pt) (pu,pr,pt) C_shm P_create) |
|
1388 |
| _ \<Rightarrow> False)" |
|
1389 |
| "grant s (Attach p h flag) = |
|
1390 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_shm h)) of |
|
1391 |
(Some (pu,pr,pt), Some (hu,hr,ht)) \<Rightarrow> |
|
1392 |
if flag = SHM_RDONLY |
|
1393 |
then permission_check (pu,pr,pt) (hu,hr,ht) C_shm P_read |
|
1394 |
else permission_check (pu,pr,pt) (hu,hr,ht) C_shm P_read \<and> |
|
1395 |
permission_check (pu,pr,pt) (hu,hr,ht) C_shm P_write |
|
1396 |
| _ \<Rightarrow> False)" |
|
1397 |
| "grant s (Detach p h) = True" (*?*) |
|
1398 |
| "grant s (DeleteShM p h) = |
|
1399 |
(case (sectxt_of_obj s (O_proc p), sectxt_of_obj s (O_shm h)) of |
|
1400 |
(Some (pu,pr,pt), Some (hu,hr,ht)) \<Rightarrow> |
|
1401 |
permission_check (pu,pr,pt) (hu,hr,ht) C_shm P_destroy |
|
1402 |
| _ \<Rightarrow> False)" |
|
1403 |
||
1404 |
||
1405 |
| "grant s _ = False" (* socket event is currently not in consideration *) |
|
1406 |
||
1407 |
inductive valid :: "t_state \<Rightarrow> bool" |
|
1408 |
where |
|
1409 |
"valid []" |
|
1410 |
| "\<lbrakk>valid s; os_grant s e; grant s e\<rbrakk> \<Longrightarrow> valid (e # s)" |
|
1411 |
||
1412 |
(* tobj: object that can be tainted *) |
|
1413 |
fun tobj_in_init :: "t_object \<Rightarrow> bool" |
|
1414 |
where |
|
1415 |
"tobj_in_init (O_proc p) = (p \<in> init_procs)" |
|
19 | 1416 |
| "tobj_in_init (O_file f) = (is_init_file f)" |
1 | 1417 |
(* directory is not taintable |
1418 |
| "tobj_in_init (O_dir f) = (f \<in> init_files)" |
|
1419 |
*) |
|
1420 |
| "tobj_in_init (O_node n) = (n \<in> init_nodes)" |
|
19 | 1421 |
| "tobj_in_init (O_msg q m) = (m \<in> set (init_msgs_of_queue q) \<and> q \<in> init_msgqs)" |
1 | 1422 |
| "tobj_in_init _ = False" (* other kind of obj cannot be tainted *) |
1423 |
||
1424 |
(* no use |
|
1425 |
fun no_del_event:: "t_event list \<Rightarrow> bool" |
|
1426 |
where |
|
1427 |
"no_del_event [] = True" |
|
1428 |
| "no_del_event (Kill p p' # \<tau>) = False" |
|
1429 |
| "no_del_event (CloseFd p fd # \<tau>) = False" |
|
1430 |
| "no_del_event (UnLink p f # \<tau>) = False" |
|
1431 |
| "no_del_event (Rmdir p f # \<tau>) = False" |
|
1432 |
(* |
|
1433 |
| "no_del_event (Rename p f f' # \<tau>) = False" |
|
1434 |
*) |
|
1435 |
| "no_del_event (RemoveMsgq p q # \<tau>) = False" |
|
1436 |
| "no_del_event (RecvMsg p q m # \<tau>) = False" |
|
1437 |
| "no_del_event (_ # \<tau>) = no_del_event \<tau>" |
|
1438 |
*) |
|
1439 |
||
1440 |
end |
|
1441 |
||
1442 |
locale tainting = flask + |
|
1443 |
||
1444 |
fixes seeds :: "t_object set" |
|
1445 |
assumes |
|
23
25e55731ed01
locale of tainting for seeds when same shm/inode bugs
chunhan
parents:
22
diff
changeset
|
1446 |
seeds_in_init: "\<And> obj. obj \<in> seeds \<Longrightarrow> tobj_in_init obj" |
25e55731ed01
locale of tainting for seeds when same shm/inode bugs
chunhan
parents:
22
diff
changeset
|
1447 |
and same_inode_in_seeds: "\<And> f f'. \<lbrakk>O_file f \<in> seeds; has_same_inode [] f f'\<rbrakk> \<Longrightarrow> O_file f' \<in> seeds" |
25e55731ed01
locale of tainting for seeds when same shm/inode bugs
chunhan
parents:
22
diff
changeset
|
1448 |
and flow_shm_in_seeds: "\<And> p p'. \<lbrakk>O_proc p \<in> seeds; info_flow_shm [] p p'\<rbrakk> \<Longrightarrow> O_proc p' \<in> seeds" |
1 | 1449 |
|
1450 |
begin |
|
1451 |
||
1452 |
inductive tainted :: "t_object \<Rightarrow> t_state \<Rightarrow> bool" ("_ \<in> tainted _" [100, 100] 100) |
|
1453 |
where |
|
1454 |
t_init: "obj \<in> seeds \<Longrightarrow> obj \<in> tainted []" |
|
1455 |
| t_clone: "\<lbrakk>O_proc p \<in> tainted s; valid (Clone p p' fds shms # s)\<rbrakk> |
|
1456 |
\<Longrightarrow> O_proc p' \<in> tainted (Clone p p' fds shms # s)" |
|
1457 |
| t_execve: "\<lbrakk>O_file f \<in> tainted s; valid (Execve p f fds # s)\<rbrakk> |
|
1458 |
\<Longrightarrow> O_proc p \<in> tainted (Execve p f fds # s)" |
|
22 | 1459 |
| t_ptrace: "\<lbrakk>O_proc p \<in> tainted s; valid (Ptrace p p' # s); info_flow_shm s p' p''\<rbrakk> |
1 | 1460 |
\<Longrightarrow> O_proc p'' \<in> tainted (Ptrace p p' # s)" |
22 | 1461 |
| t_ptrace':"\<lbrakk>O_proc p' \<in> tainted s; valid (Ptrace p p' # s); info_flow_shm s p p''\<rbrakk> |
1 | 1462 |
\<Longrightarrow> O_proc p'' \<in> tainted (Ptrace p p' # s)" |
1463 |
| t_cfile: "\<lbrakk>O_proc p \<in> tainted s; valid (Open p f flags fd (Some inum) # s)\<rbrakk> |
|
1464 |
\<Longrightarrow> O_file f \<in> tainted (Open p f flags fd (Some inum) # s)" |
|
1465 |
| t_read: "\<lbrakk>O_file f \<in> tainted s; valid (ReadFile p fd # s); |
|
22 | 1466 |
file_of_proc_fd s p fd = Some f; info_flow_shm s p p'\<rbrakk> |
1 | 1467 |
\<Longrightarrow> O_proc p' \<in> tainted (ReadFile p fd # s)" |
1468 |
| t_write: "\<lbrakk>O_proc p \<in> tainted s; valid (WriteFile p fd # s); |
|
1469 |
file_of_proc_fd s p fd = Some f; has_same_inode s f f'\<rbrakk> |
|
1470 |
\<Longrightarrow> O_file f' \<in> tainted (WriteFile p fd # s)" |
|
1471 |
(* directory is not tainted |
|
1472 |
| t_mkdir: "\<lbrakk>O_proc p \<in> tainted s; valid (Mkdir p f inum # s)\<rbrakk> |
|
1473 |
\<Longrightarrow> O_dir f \<in> tainted (Mkdir p f inum # s)" |
|
1474 |
*) |
|
1475 |
| t_link: "\<lbrakk>O_file f \<in> tainted s; valid (LinkHard p f f' # s)\<rbrakk> |
|
1476 |
\<Longrightarrow> O_file f' \<in> tainted (LinkHard p f f' # s)" |
|
1477 |
| t_trunc: "\<lbrakk>O_proc p \<in> tainted s; valid (Truncate p f len # s); len > 0; has_same_inode s f f'\<rbrakk> |
|
1478 |
\<Longrightarrow> O_file f' \<in> tainted (Truncate p f len # s)" |
|
1479 |
(* |
|
1480 |
| t_rename: "\<lbrakk>O_file f'' \<in> tainted s; valid (Rename p f f' # s);f \<preceq> f''\<rbrakk> |
|
1481 |
\<Longrightarrow> O_file (file_after_rename f f' f'') \<in> tainted (Rename p f f' # s)" |
|
1482 |
| t_rename':"\<lbrakk>O_dir f'' \<in> tainted s; valid (Rename p f f' # s);f \<preceq> f''\<rbrakk> |
|
1483 |
\<Longrightarrow> O_dir (file_after_rename f f' f'') \<in> tainted (Rename p f f' # s)" |
|
1484 |
*) |
|
55 | 1485 |
| t_attach1:"\<lbrakk>O_proc p \<in> tainted s; valid (Attach p h SHM_RDWR # s); (p', flag') \<in> procs_of_shm s h; info_flow_shm s p' p''\<rbrakk> |
1486 |
\<Longrightarrow> O_proc p'' \<in> tainted (Attach p h SHM_RDWR # s)" |
|
1487 |
| t_attach2:"\<lbrakk>O_proc p' \<in> tainted s; valid (Attach p h flag # s); (p', SHM_RDWR) \<in> procs_of_shm s h; info_flow_shm s p p''\<rbrakk> |
|
1488 |
\<Longrightarrow> O_proc p'' \<in> tainted (Attach p h flag # s)" |
|
1 | 1489 |
| t_sendmsg:"\<lbrakk>O_proc p \<in> tainted s; valid (SendMsg p q m # s)\<rbrakk> |
1490 |
\<Longrightarrow> O_msg q m \<in> tainted (SendMsg p q m # s)" |
|
22 | 1491 |
| t_recvmsg:"\<lbrakk>O_msg q m \<in> tainted s; valid (RecvMsg p q m # s); info_flow_shm s p p'\<rbrakk> |
1 | 1492 |
\<Longrightarrow> O_proc p' \<in> tainted (RecvMsg p q m # s)" |
1493 |
| t_remain: "\<lbrakk>obj \<in> tainted s; valid (e # s); alive (e # s) obj\<rbrakk> |
|
1494 |
\<Longrightarrow> obj \<in> tainted (e # s)" |
|
1495 |
||
61 | 1496 |
(* reasonable tainted object, fd and sock and msgq and msg is excluded |
1497 |
* this is different from tainted, which already excluded some of them, |
|
1498 |
* tainted not excluded msg, which does not have the meaning of "tainteable", but |
|
1499 |
* but acting as a media to "pass" the virus. We normally will not say that |
|
1500 |
* a message is tableable or not. |
|
1501 |
*) |
|
1502 |
fun appropriate :: "t_object \<Rightarrow> bool" |
|
1503 |
where |
|
1504 |
"appropriate (O_proc p) = (p \<in> init_procs)" |
|
1505 |
| "appropriate (O_file f) = (is_init_file f)" |
|
1506 |
| "appropriate (O_dir f) = False" |
|
1507 |
| "appropriate (O_fd p fd) = False" |
|
1508 |
| "appropriate (O_node n) = False" (* cause socket is temperary not considered *) |
|
1509 |
| "appropriate (O_tcp_sock k) = False" |
|
1510 |
| "appropriate (O_udp_sock k) = False" |
|
1511 |
| "appropriate (O_shm h) = False" |
|
1512 |
| "appropriate (O_msgq q) = False" |
|
1513 |
| "appropriate (O_msg q m) = False" |
|
1514 |
||
1 | 1515 |
definition taintable:: "t_object \<Rightarrow> bool" |
1516 |
where |
|
61 | 1517 |
"taintable obj \<equiv> init_alive obj \<and> appropriate obj \<and> (\<exists> s. obj \<in> tainted s)" |
1 | 1518 |
|
1519 |
definition undeletable :: "t_object \<Rightarrow> bool" |
|
1520 |
where |
|
1521 |
"undeletable obj \<equiv> init_alive obj \<and> \<not> (\<exists> s. valid s \<and> deleted obj s)" |
|
1522 |
||
1523 |
end |
|
1524 |
||
1525 |
end |