diff -r 924ab7a4e7fa -r 271e9818b6f6 simple_selinux/Alive_prop.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simple_selinux/Alive_prop.thy Mon Dec 02 10:52:40 2013 +0800 @@ -0,0 +1,335 @@ +theory Alive_prop +imports Main Flask_type Flask Current_files_prop Current_sockets_prop Init_prop Proc_fd_of_file_prop +begin + +context flask begin + +lemma distinct_queue_msgs: + "\q \ current_msgqs s; valid s\ \ distinct (msgs_of_queue s q)" +apply (induct s) +apply (simp add:init_msgs_distinct) +apply (frule vd_cons, frule vt_grant_os, case_tac a) +apply auto +apply (case_tac "msgs_of_queue s q", simp+) +done + +lemma received_msg_notin: + "\hd (msgs_of_queue s q) \ set (tl (msgs_of_queue s q)); q \ current_msgqs s; valid s\ \ False" +apply (drule distinct_queue_msgs, simp) +apply (case_tac "msgs_of_queue s q", auto) +done + +lemma other_msg_remains: + "\m \ hd (msgs_of_queue s q); q \ current_msgqs s; valid s\ + \ (m \ set (tl (msgs_of_queue s q))) = (m \ set (msgs_of_queue s q))" +apply (drule distinct_queue_msgs, simp) +apply (case_tac "msgs_of_queue s q", auto) +done + +lemma is_tcp_in_current: + "is_tcp_sock \ s \ s \ current_sockets \" +by (auto simp:is_tcp_sock_def current_sockets_def split:option.splits) + +lemma is_udp_in_current: + "is_udp_sock \ s \ s \ current_sockets \" +by (auto simp:is_udp_sock_def current_sockets_def split:option.splits) + +(************ alive simpset **************) + +lemma alive_open: + "valid (Open p f flag fd opt # s) \ alive (Open p f flag fd opt # s) = ( + \ obj. case obj of + O_fd p' fd' \ if (p' = p \ fd' = fd) then True + else alive s obj + | O_file f' \ (if (opt = None) then alive s obj + else if (f = f') then True + else alive s obj) + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + dest:is_dir_in_current split:if_splits option.splits) +done + +(* sock is not inherited on Execve, Clone cases, cause I simplified it with os_grant. + * chunhan, 2013-11-20 +lemma alive_execve: + "valid (Execve p f fds # s) \ alive (Execve p f fds # s) = ( + \ obj. case obj of + O_fd p' fd \ (if (p = p' \ fd \ fds) then alive s (O_fd p fd) + else if (p = p') then False + else alive s (O_fd p' fd)) + | O_tcp_sock (p', fd) \ (if (p = p' \ fd \ fds) then alive s (O_tcp_sock (p, fd)) + else if (p = p') then False + else alive s (O_tcp_sock (p', fd))) + | O_udp_sock (p', fd) \ (if (p = p' \ fd \ fds) then alive s (O_udp_sock (p, fd)) + else if (p = p') then False + else alive s (O_udp_sock (p', fd))) + | _ \ alive s obj )" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + dest:is_dir_in_current split:if_splits option.splits) + +done + +lemma alive_clone: + "valid (Clone p p' fds shms # s) \ alive (Clone p p' fds shms # s) = ( + \ obj. case obj of + O_proc p'' \ if (p'' = p') then True else alive s obj + | O_fd p'' fd \ if (p'' = p' \ fd \ fds) then True + else if (p'' = p') then False + else alive s obj + | O_tcp_sock (p'', fd) \ (if (p'' = p' \ fd \ fds) then alive s (O_tcp_sock (p, fd)) + else if (p'' = p') then False + else alive s (O_tcp_sock (p'', fd))) + | O_udp_sock (p'', fd) \ (if (p'' = p' \ fd \ fds) then alive s (O_udp_sock (p, fd)) + else if (p'' = p') then False + else alive s (O_udp_sock (p'', fd))) + | _ \ alive s obj )" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current split:if_splits option.splits) +done +*) + +lemma alive_execve: + "valid (Execve p f fds # s) \ alive (Execve p f fds # s) = ( + \ obj. case obj of + O_fd p' fd \ (if (p = p' \ fd \ fds) then alive s (O_fd p fd) + else if (p = p') then False + else alive s (O_fd p' fd)) + | O_tcp_sock (p', fd) \ (if (p = p') then False + else alive s (O_tcp_sock (p', fd))) + | O_udp_sock (p', fd) \ (if (p = p') then False + else alive s (O_udp_sock (p', fd))) + | _ \ alive s obj )" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + dest:is_dir_in_current split:if_splits option.splits + dest:file_fds_subset_pfds[where s = s] udp_notin_file_fds tcp_notin_file_fds) +done + +lemma alive_clone: + "valid (Clone p p' fds # s) \ alive (Clone p p' fds # s) = ( + \ obj. case obj of + O_proc p'' \ if (p'' = p') then True else alive s obj + | O_fd p'' fd \ if (p'' = p' \ fd \ fds) then True + else if (p'' = p') then False + else alive s obj + | O_tcp_sock (p'', fd) \ (if (p'' = p') then False + else alive s (O_tcp_sock (p'', fd))) + | O_udp_sock (p'', fd) \ (if (p'' = p') then False + else alive s (O_udp_sock (p'', fd))) + | _ \ alive s obj )" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current split:if_splits option.splits + dest:file_fds_subset_pfds[where s = s] udp_notin_file_fds tcp_notin_file_fds) +done + +lemma alive_kill: + "valid (Kill p p' # s) \ alive (Kill p p' # s) = ( + \ obj. case obj of + O_proc p'' \ if (p'' = p') then False else alive s obj + | O_fd p'' fd \ if (p'' = p') then False else alive s obj + | O_tcp_sock (p'', fd) \ if (p'' = p') then False else alive s obj + | O_udp_sock (p'', fd) \ if (p'' = p') then False else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current split:if_splits option.splits) +done + +lemma alive_exit: + "valid (Exit p' # s) \ alive (Exit p' # s) = ( + \ obj. case obj of + O_proc p'' \ if (p'' = p') then False else alive s obj + | O_fd p'' fd \ if (p'' = p') then False else alive s obj + | O_tcp_sock (p'', fd) \ if (p'' = p') then False else alive s obj + | O_udp_sock (p'', fd) \ if (p'' = p') then False else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current split:if_splits option.splits) +done + +lemma alive_closefd: + "valid (CloseFd p fd # s) \ alive (CloseFd p fd # s) = ( + \ obj. case obj of + O_fd p' fd' \ if (p' = p \ fd' = fd) then False else alive s obj + | O_tcp_sock (p', fd') \ if (p' = p \ fd' = fd) then False else alive s obj + | O_udp_sock (p', fd') \ if (p' = p \ fd' = fd) then False else alive s obj + | O_file f \ (case (file_of_proc_fd s p fd) of + Some f' \ (if (f = f' \ proc_fd_of_file s f = {(p, fd)} \ f \ files_hung_by_del s) + then False else alive s obj) + | _ \ alive s obj) + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current file_of_pfd_is_file' split:if_splits option.splits) +done + +lemma alive_unlink: + "valid (UnLink p f # s) \ alive (UnLink p f # s) = ( + \ obj. case obj of + O_file f' \ if (f' = f \ proc_fd_of_file s f = {}) then False else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current file_of_pfd_is_file' file_dir_conflict + split:if_splits option.splits) +done + +lemma alive_rmdir: + "valid (Rmdir p d # s) \ alive (Rmdir p d # s) = (alive s) (O_dir d := False)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current file_of_pfd_is_file' file_dir_conflict + split:if_splits option.splits) +done + +lemma alive_mkdir: + "valid (Mkdir p d inum # s) \ alive (Mkdir p d inum # s) = (alive s) (O_dir d := True)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current file_of_pfd_is_file' is_file_in_current + split:if_splits option.splits) +done + +(* +lemma alive_linkhard: + "valid (LinkHard p f f' # s) \ alive (LinkHard p f f' # s) = (alive s) (O_file f' := True)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current + dest:is_dir_in_current file_of_pfd_is_file' is_file_in_current + split:if_splits option.splits) +done +*) + +lemma alive_createmsgq: + "valid (CreateMsgq p q # s) \ alive (CreateMsgq p q # s) = (alive s) (O_msgq q := True)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def) +done + +lemma alive_sendmsg: + "valid (SendMsg p q m # s) \ alive (SendMsg p q m # s) = (alive s) (O_msg q m := True)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def) +done + +lemma alive_recvmsg: + "valid (RecvMsg p q m # s) \ alive (RecvMsg p q m # s) = (alive s) (O_msg q m := False)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def other_msg_remains + dest:received_msg_notin) +done + +lemma alive_removemsgq: + "valid (RemoveMsgq p q # s) \ alive (RemoveMsgq p q # s) = ( + \ obj. case obj of + O_msgq q' \ if (q' = q) then False else alive s obj + | O_msg q' m \ if (q' = q) then False else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def) +done + +(* +lemma alive_createshm: + "valid (CreateShM p h # s) \ alive (CreateShM p h # s) = (alive s) (O_shm h := True)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def) +done + +lemma alive_deleteshm: + "valid (DeleteShM p h # s) \ alive (DeleteShM p h # s) = (alive s) (O_shm h := False)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def) +done +*) + +lemma alive_createsock: + "valid (CreateSock p af st fd inum # s) \ alive (CreateSock p af st fd inum # s) = ( + \ obj. case obj of + O_fd p' fd' \ if (p' = p \ fd' = fd) then True else alive s obj + | O_tcp_sock (p', fd') \ if (p' = p \ fd' = fd \ st = STREAM) then True else alive s obj + | O_udp_sock (p', fd') \ if (p' = p \ fd' = fd \ st = DGRAM) then True else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current split:t_socket_type.splits) +done + +lemma alive_accept: + "valid (Accept p fd addr port fd' inum # s) \ alive (Accept p fd addr port fd' inum # s) = ( + \ obj. case obj of + O_fd p' fd'' \ if (p' = p \ fd'' = fd') then True else alive s obj + | O_tcp_sock (p', fd'') \ if (p' = p \ fd'' = fd') then True else alive s obj + | _ \ alive s obj)" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac obj) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current split:t_socket_type.splits) +done + +lemma alive_other: + "\valid (e # s); + \ p f flag fd opt. e \ Open p f flag fd opt; + \ p f fds. e \ Execve p f fds; + \ p p' fds. e \ Clone p p' fds; + \ p p'. e \ Kill p p'; + \ p. e \ Exit p; + \ p fd. e \ CloseFd p fd; + \ p f. e \ UnLink p f; + \ p d. e \ Rmdir p d; + \ p d inum. e \ Mkdir p d inum; + \ p f f'. e \ LinkHard p f f'; + \ p q. e \ CreateMsgq p q; + \ p q m. e \ SendMsg p q m; + \ p q m. e \ RecvMsg p q m; + \ p q. e \ RemoveMsgq p q; + \ p af st fd inum. e \ CreateSock p af st fd inum; + \ p fd addr port fd' inum. e \ Accept p fd addr port fd' inum\ + \ alive (e # s) = alive s" +apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac x, case_tac [!] e) +apply (auto simp:current_files_simps current_sockets_simps is_file_simps is_dir_simps + is_tcp_sock_simps is_udp_sock_simps dir_is_empty_def + intro:is_tcp_in_current is_udp_in_current split:t_socket_type.splits) +done + +lemmas alive_simps = alive_open alive_execve alive_clone alive_kill alive_exit alive_closefd alive_unlink + alive_rmdir alive_mkdir alive_createmsgq alive_removemsgq + alive_createsock alive_accept alive_other alive_sendmsg alive_recvmsg + + +end + +end \ No newline at end of file