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