Flask.thy
changeset 6 8779d321cc2e
parent 4 e9c5594d5963
child 7 f27882976251
equal deleted inserted replaced
5:0c209a3e2647 6:8779d321cc2e
   205                                       | _                 \<Rightarrow> False)
   205                                       | _                 \<Rightarrow> False)
   206                          | _      \<Rightarrow> False)"
   206                          | _      \<Rightarrow> False)"
   207 
   207 
   208 definition init_same_inode_files :: "t_file \<Rightarrow> t_file set"
   208 definition init_same_inode_files :: "t_file \<Rightarrow> t_file set"
   209 where
   209 where
   210   "init_same_inode_files f \<equiv> {f'. init_inum_of_file f = init_inum_of_file f'}"
   210   "init_same_inode_files f \<equiv> if is_init_file f then {f'. init_inum_of_file f = init_inum_of_file f'} else {}"
   211 
   211 
   212 fun init_alive :: "t_object \<Rightarrow> bool"
   212 fun init_alive :: "t_object \<Rightarrow> bool"
   213 where
   213 where
   214   "init_alive (O_proc p)     = (p \<in> init_procs)"
   214   "init_alive (O_proc p)     = (p \<in> init_procs)"
   215 | "init_alive (O_file f)     = (is_init_file f)"
   215 | "init_alive (O_file f)     = (is_init_file f)"
   355      (case st of 
   355      (case st of 
   356         STREAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)
   356         STREAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)
   357       | DGRAM  \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_UDP_SOCK) )"
   357       | DGRAM  \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_UDP_SOCK) )"
   358 | "itag_of_inum (Accept p fd addr lport' fd' ino # \<tau>) = 
   358 | "itag_of_inum (Accept p fd addr lport' fd' ino # \<tau>) = 
   359      (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)"
   359      (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)"
   360 | "itag_of_inum (_ # \<tau>) = itag_of_inum \<tau>"  (* may be sth wrong with nettemp representing addr \<times> netdev in statical analysis ??? *)
   360 | "itag_of_inum (_ # \<tau>) = itag_of_inum \<tau>"  
   361 
   361 
   362 definition is_file:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
   362 definition is_file:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
   363 where
   363 where
   364   "is_file \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
   364   "is_file \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
   365                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
   365                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
   480 where
   480 where
   481   "current_inode_nums \<tau> = current_file_inums \<tau> \<union> current_sock_inums \<tau>"
   481   "current_inode_nums \<tau> = current_file_inums \<tau> \<union> current_sock_inums \<tau>"
   482 
   482 
   483 definition same_inode_files :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file set"
   483 definition same_inode_files :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file set"
   484 where
   484 where
   485   "same_inode_files s f \<equiv> {f'. inum_of_file s f = inum_of_file s f'}"
   485   "same_inode_files s f \<equiv> if is_file s f then {f'. inum_of_file s f = inum_of_file s f'} else {}"
   486 
   486 
   487 fun flags_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_open_flags option"
   487 fun flags_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_open_flags option"
   488 where
   488 where
   489   "flags_of_proc_fd [] p fd = init_oflags_of_proc_fd p fd" 
   489   "flags_of_proc_fd [] p fd = init_oflags_of_proc_fd p fd" 
   490 | "flags_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' = 
   490 | "flags_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' = 
   612 where
   612 where
   613   "os_grant \<tau> (Open p f flags fd inumopt) = (
   613   "os_grant \<tau> (Open p f flags fd inumopt) = (
   614      case inumopt of
   614      case inumopt of
   615        Some ino \<Rightarrow>
   615        Some ino \<Rightarrow>
   616     (p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> 
   616     (p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> 
   617      (\<exists> pf. parent f = Some pf \<and> pf \<in> current_files \<tau> \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and>
   617      (\<exists> pf. parent f = Some pf \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and>
   618      is_creat_flag flags \<and> fd \<notin> (current_proc_fds \<tau> p) \<and> ino \<notin> (current_inode_nums \<tau>))
   618      is_creat_flag flags \<and> fd \<notin> (current_proc_fds \<tau> p) \<and> ino \<notin> (current_inode_nums \<tau>))
   619    |   None     \<Rightarrow>
   619    |   None     \<Rightarrow>
   620     (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> \<not> is_creat_excl_flag flags \<and> is_file \<tau> f \<and>
   620     (p \<in> current_procs \<tau> \<and> \<not> is_creat_excl_flag flags \<and> is_file \<tau> f \<and>
   621      fd \<notin> (current_proc_fds \<tau> p))           )"
   621      fd \<notin> (current_proc_fds \<tau> p))           )"
   622 (*(if (is_dir \<tau> f) then (is_dir_flag flags \<and> \<not> is_write_flag flags) else (\<not> is_dir_flag flags)),
   622 (*(if (is_dir \<tau> f) then (is_dir_flag flags \<and> \<not> is_write_flag flags) else (\<not> is_dir_flag flags)),
   623   here open is not applied to directories, readdir is for that, but it is not security-related *)
   623   here open is not applied to directories, readdir is for that, but it is not security-related *)
   624 | "os_grant \<tau> (CloseFd p fd)                  = 
   624 | "os_grant \<tau> (CloseFd p fd)                  = 
   625     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p)"
   625     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p)"
   626 | "os_grant \<tau> (UnLink p f)                    = 
   626 | "os_grant \<tau> (UnLink p f)                    = 
   627     (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f \<and> f \<notin> files_hung_by_del \<tau>)"
   627     (p \<in> current_procs \<tau> \<and> is_file \<tau> f \<and> f \<notin> files_hung_by_del \<tau>)"
   628 | "os_grant \<tau> (Rmdir p f)                     = 
   628 | "os_grant \<tau> (Rmdir p f)                     = 
   629     (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> dir_is_empty \<tau> f \<and> f \<notin> files_hung_by_del \<tau> \<and> f \<noteq> [])" (* root file cannot be deleted *)
   629     (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 *)
   630 | "os_grant \<tau> (Mkdir p f ino)                 = 
   630 | "os_grant \<tau> (Mkdir p f ino)                 = 
   631     (p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> 
   631     (p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> 
   632      (\<exists> pf. parent f = Some pf \<and> pf \<in> current_files \<tau> \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and>
   632      (\<exists> pf. parent f = Some pf \<and> is_dir \<tau> pf \<and> pf \<notin> files_hung_by_del \<tau>) \<and>
   633      ino \<notin> (current_inode_nums \<tau>))"
   633      ino \<notin> (current_inode_nums \<tau>))"
   634 | "os_grant \<tau> (LinkHard p f\<^isub>1 f\<^isub>2)              = 
   634 | "os_grant \<tau> (LinkHard p f\<^isub>1 f\<^isub>2)              = 
   635     (p \<in> current_procs \<tau> \<and> f\<^isub>1 \<in> current_files \<tau> \<and> f\<^isub>2 \<notin> current_files \<tau> \<and> 
   635     (p \<in> current_procs \<tau> \<and> is_file \<tau> f\<^isub>1 \<and> f\<^isub>2 \<notin> current_files \<tau> \<and> 
   636      (\<exists> pf\<^isub>2. parent f\<^isub>2 = Some pf\<^isub>2 \<and> pf\<^isub>2 \<in> current_files \<tau> \<and> is_dir \<tau> pf\<^isub>2 \<and> 
   636      (\<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>))"
   637              pf\<^isub>2 \<notin> files_hung_by_del \<tau>) \<and> is_file \<tau> f\<^isub>1)"
       
   638 | "os_grant \<tau> (Truncate p f len)              = 
   637 | "os_grant \<tau> (Truncate p f len)              = 
   639     (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f)"
   638     (p \<in> current_procs \<tau> \<and> is_file \<tau> f)"
   640 (*
   639 (*
   641 | "os_grant \<tau> (FTruncate p fd len)            = 
   640 | "os_grant \<tau> (FTruncate p fd len)            = 
   642     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> 
   641     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> 
   643      (\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f) \<and> 
   642      (\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f) \<and> 
   644      (\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))"
   643      (\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))"
   650 | "os_grant \<tau> (WriteFile p fd)                = 
   649 | "os_grant \<tau> (WriteFile p fd)                = 
   651     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> 
   650     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> 
   652      (\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau>) \<and> 
   651      (\<exists> f. file_of_proc_fd \<tau> p fd = Some f \<and> f \<in> current_files \<tau>) \<and> 
   653      (\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))"
   652      (\<exists> flags. flags_of_proc_fd \<tau> p fd = Some flags \<and> is_write_flag flags))"
   654 | "os_grant \<tau> (Execve p f fds)                = 
   653 | "os_grant \<tau> (Execve p f fds)                = 
   655     (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> is_file \<tau> f \<and> fds \<subseteq> current_proc_fds \<tau> p)" (* file_at_writing_by \<tau> f = {} *)
   654     (p \<in> current_procs \<tau> \<and> is_file \<tau> f \<and> fds \<subseteq> current_proc_fds \<tau> p)" (* file_at_writing_by \<tau> f = {} *)
   656 (*
   655 (*
   657 | "os_grant \<tau> (Rename p f\<^isub>2 f\<^isub>3)                = 
   656 | "os_grant \<tau> (Rename p f\<^isub>2 f\<^isub>3)                = 
   658     (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>
   657     (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>
   659      (\<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> 
   658      (\<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> 
   660              pf\<^isub>3 \<notin> files_hung_by_del \<tau>) )"
   659              pf\<^isub>3 \<notin> files_hung_by_del \<tau>) )"
   687      socket_state \<tau> (p, fd) = Some SS_create)" (* ?? !! (case addr of INET_ADDR ip port \<Rightarrow> ip \<in> local_ipaddrs)) *)
   686      socket_state \<tau> (p, fd) = Some SS_create)" (* ?? !! (case addr of INET_ADDR ip port \<Rightarrow> ip \<in> local_ipaddrs)) *)
   688 | "os_grant \<tau> (Connect p fd addr)             = 
   687 | "os_grant \<tau> (Connect p fd addr)             = 
   689     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   688     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   690      socket_state \<tau> (p, fd) = Some SS_bind)"
   689      socket_state \<tau> (p, fd) = Some SS_bind)"
   691 | "os_grant \<tau> (Listen p fd)                   = 
   690 | "os_grant \<tau> (Listen p fd)                   = 
   692     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   691     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> is_tcp_sock \<tau> (p, fd) \<and>
   693      socket_state \<tau> (p, fd) = Some SS_bind \<and> is_tcp_sock \<tau> (p, fd))" (* Listen and Accept should only be used for TCP sever side *)
   692      socket_state \<tau> (p, fd) = Some SS_bind)" (* Listen and Accept should only be used for TCP sever side *)
   694 | "os_grant \<tau> (SendSock p fd)                 = 
   693 | "os_grant \<tau> (SendSock p fd)                 = 
   695     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   694     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   696      socket_in_sending \<tau> (p, fd))"
   695      socket_in_sending \<tau> (p, fd))"
   697 | "os_grant \<tau> (RecvSock p fd)                 = 
   696 | "os_grant \<tau> (RecvSock p fd)                 = 
   698     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   697     (p \<in> current_procs \<tau> \<and> fd \<in> current_proc_fds \<tau> p \<and> (p, fd) \<in> current_sockets \<tau> \<and> 
   714     (p\<^isub>1 \<in> current_procs \<tau> \<and> p\<^isub>2 \<in> current_procs \<tau>)" (* a process can trace itself right? *)
   713     (p\<^isub>1 \<in> current_procs \<tau> \<and> p\<^isub>2 \<in> current_procs \<tau>)" (* a process can trace itself right? *)
   715 
   714 
   716 fun alive :: "t_state \<Rightarrow> t_object \<Rightarrow> bool"
   715 fun alive :: "t_state \<Rightarrow> t_object \<Rightarrow> bool"
   717 where
   716 where
   718   "alive s (O_proc p)     = (p \<in> current_procs s)"
   717   "alive s (O_proc p)     = (p \<in> current_procs s)"
   719 | "alive s (O_file f)     = (f \<in> current_files s \<and> is_file s f)"
   718 | "alive s (O_file f)     = (is_file s f)"
   720 | "alive s (O_dir  f)     = (f \<in> current_files s \<and> is_dir s f)"
   719 | "alive s (O_dir  f)     = (is_dir s f)"
   721 | "alive s (O_fd p fd)    = (fd \<in> current_proc_fds s p)"
   720 | "alive s (O_fd p fd)    = (fd \<in> current_proc_fds s p)"
   722 | "alive s (O_node n)     = (n \<in> init_nodes)"
   721 | "alive s (O_node n)     = (n \<in> init_nodes)"
   723 | "alive s (O_tcp_sock k) = (k \<in> current_sockets s \<and> is_tcp_sock s k)"
   722 | "alive s (O_tcp_sock k) = (is_tcp_sock s k)"
   724 | "alive s (O_udp_sock k) = (k \<in> current_sockets s \<and> is_udp_sock s k)"
   723 | "alive s (O_udp_sock k) = (is_udp_sock s k)"
   725 | "alive s (O_shm  h)     = (h \<in> current_shms s)"
   724 | "alive s (O_shm  h)     = (h \<in> current_shms s)"
   726 | "alive s (O_msgq q)     = (q \<in> current_msgqs s)"
   725 | "alive s (O_msgq q)     = (q \<in> current_msgqs s)"
   727 | "alive s (O_msg q m)    = (m \<in> set (msgs_of_queue s q) \<and> q \<in> current_msgqs s)"
   726 | "alive s (O_msg q m)    = (m \<in> set (msgs_of_queue s q) \<and> q \<in> current_msgqs s)"
   728 
   727 
   729 (* deleted objects should be "taintable" objects, objects like fd should not be in consideration *)
   728 (* deleted objects should be "taintable" objects, objects like fd should not be in consideration *)