rc_theory.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 06 Sep 2013 12:55:12 +0100
changeset 13 dd1499f296ea
parent 6 4294abb1f38c
permissions -rwxr-xr-x
updated to new isabelle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
dcde836219bc add thy files
chunhan
parents:
diff changeset
     1
theory rc_theory
dcde836219bc add thy files
chunhan
parents:
diff changeset
     2
imports Main my_list_prefix
dcde836219bc add thy files
chunhan
parents:
diff changeset
     3
begin
dcde836219bc add thy files
chunhan
parents:
diff changeset
     4
dcde836219bc add thy files
chunhan
parents:
diff changeset
     5
dcde836219bc add thy files
chunhan
parents:
diff changeset
     6
(****************** rc policy (role, type, ... ) type definitions *****************)
dcde836219bc add thy files
chunhan
parents:
diff changeset
     7
(*** normal: user-defined values for policy ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
     8
(*** others: RC special values for RC internal control ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
     9
 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    10
datatype t_client = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    11
  Client1
dcde836219bc add thy files
chunhan
parents:
diff changeset
    12
| Client2
dcde836219bc add thy files
chunhan
parents:
diff changeset
    13
dcde836219bc add thy files
chunhan
parents:
diff changeset
    14
datatype t_normal_role =  
dcde836219bc add thy files
chunhan
parents:
diff changeset
    15
  WebServer 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    16
| WS     "t_client" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    17
| UpLoad "t_client" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    18
| CGI     "t_client"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    19
dcde836219bc add thy files
chunhan
parents:
diff changeset
    20
datatype t_role = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    21
  InheritParentRole 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    22
| UseForcedRole 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    23
| InheritUpMixed 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    24
| InheritUserRole 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    25
| InheritProcessRole 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    26
| NormalRole "t_normal_role" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    27
dcde836219bc add thy files
chunhan
parents:
diff changeset
    28
datatype t_normal_file_type = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    29
  Root_file_type   (* special value, as 0 for root-file in the NordSec paper*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    30
| WebServerLog_file
dcde836219bc add thy files
chunhan
parents:
diff changeset
    31
| WebData_file      "t_client" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    32
| CGI_P_file        "t_client" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    33
| PrivateD_file     "t_client" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    34
| Executable_file   (* basic protection of RC *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    35
dcde836219bc add thy files
chunhan
parents:
diff changeset
    36
datatype t_rc_file_type = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    37
  InheritParent_file_type          
dcde836219bc add thy files
chunhan
parents:
diff changeset
    38
| NormalFile_type t_normal_file_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    39
dcde836219bc add thy files
chunhan
parents:
diff changeset
    40
datatype t_normal_proc_type = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    41
  WebServer_proc
dcde836219bc add thy files
chunhan
parents:
diff changeset
    42
| CGI_P_proc "t_client"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    43
dcde836219bc add thy files
chunhan
parents:
diff changeset
    44
datatype t_rc_proc_type =
dcde836219bc add thy files
chunhan
parents:
diff changeset
    45
  InheritParent_proc_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    46
| NormalProc_type t_normal_proc_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    47
| UseNewRoleType  
dcde836219bc add thy files
chunhan
parents:
diff changeset
    48
dcde836219bc add thy files
chunhan
parents:
diff changeset
    49
datatype t_normal_ipc_type = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    50
  WebIPC
dcde836219bc add thy files
chunhan
parents:
diff changeset
    51
dcde836219bc add thy files
chunhan
parents:
diff changeset
    52
datatype t_normal_rc_type =
dcde836219bc add thy files
chunhan
parents:
diff changeset
    53
  File_type t_normal_file_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    54
| Proc_type t_normal_proc_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    55
| IPC_type  t_normal_ipc_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
    56
dcde836219bc add thy files
chunhan
parents:
diff changeset
    57
dcde836219bc add thy files
chunhan
parents:
diff changeset
    58
dcde836219bc add thy files
chunhan
parents:
diff changeset
    59
(******* Operating System type definitions ********)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    60
dcde836219bc add thy files
chunhan
parents:
diff changeset
    61
type_synonym t_process = nat
dcde836219bc add thy files
chunhan
parents:
diff changeset
    62
dcde836219bc add thy files
chunhan
parents:
diff changeset
    63
type_synonym t_user = nat
dcde836219bc add thy files
chunhan
parents:
diff changeset
    64
dcde836219bc add thy files
chunhan
parents:
diff changeset
    65
type_synonym t_fname = string
dcde836219bc add thy files
chunhan
parents:
diff changeset
    66
dcde836219bc add thy files
chunhan
parents:
diff changeset
    67
type_synonym t_file = "t_fname list" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    68
dcde836219bc add thy files
chunhan
parents:
diff changeset
    69
type_synonym t_ipc = nat
dcde836219bc add thy files
chunhan
parents:
diff changeset
    70
dcde836219bc add thy files
chunhan
parents:
diff changeset
    71
dcde836219bc add thy files
chunhan
parents:
diff changeset
    72
dcde836219bc add thy files
chunhan
parents:
diff changeset
    73
(****** Access Control related type definitions *********)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    74
dcde836219bc add thy files
chunhan
parents:
diff changeset
    75
datatype t_event =
dcde836219bc add thy files
chunhan
parents:
diff changeset
    76
  ChangeOwner  "t_process" "t_user" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    77
| Clone        "t_process" "t_process"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    78
| Execute      "t_process" "t_file" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    79
| CreateFile   "t_process" "t_file" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    80
| CreateIPC    "t_process" "t_ipc" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    81
| ChangeRole   "t_process" "t_normal_role"    (* A process should change to normal role, which not specified in paper! *) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    82
dcde836219bc add thy files
chunhan
parents:
diff changeset
    83
(* below are events added for tainting modelling *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    84
| ReadFile     "t_process" "t_file" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    85
| WriteFile    "t_process" "t_file"     
dcde836219bc add thy files
chunhan
parents:
diff changeset
    86
| Send         "t_process" "t_ipc"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    87
| Recv         "t_process" "t_ipc"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    88
dcde836219bc add thy files
chunhan
parents:
diff changeset
    89
| Kill         "t_process" "t_process"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    90
| DeleteFile   "t_process" "t_file"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    91
| DeleteIPC    "t_process" "t_ipc"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    92
                                  
dcde836219bc add thy files
chunhan
parents:
diff changeset
    93
type_synonym t_state = "t_event list"
dcde836219bc add thy files
chunhan
parents:
diff changeset
    94
             
dcde836219bc add thy files
chunhan
parents:
diff changeset
    95
datatype t_access_type =        (*changed by wch, original: "types access_type = nat" *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
    96
  READ    
dcde836219bc add thy files
chunhan
parents:
diff changeset
    97
| WRITE   
dcde836219bc add thy files
chunhan
parents:
diff changeset
    98
| EXECUTE 
dcde836219bc add thy files
chunhan
parents:
diff changeset
    99
| CHANGE_OWNER
dcde836219bc add thy files
chunhan
parents:
diff changeset
   100
| CREATE
dcde836219bc add thy files
chunhan
parents:
diff changeset
   101
| SEND
dcde836219bc add thy files
chunhan
parents:
diff changeset
   102
| RECEIVE
dcde836219bc add thy files
chunhan
parents:
diff changeset
   103
dcde836219bc add thy files
chunhan
parents:
diff changeset
   104
| DELETE
dcde836219bc add thy files
chunhan
parents:
diff changeset
   105
dcde836219bc add thy files
chunhan
parents:
diff changeset
   106
dcde836219bc add thy files
chunhan
parents:
diff changeset
   107
(****** Some global functions' definition *****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   108
dcde836219bc add thy files
chunhan
parents:
diff changeset
   109
fun parent :: "'a list \<Rightarrow> ('a list) option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   110
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   111
   "parent []     = None"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   112
 | "parent (n#ns) = Some ns"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   113
dcde836219bc add thy files
chunhan
parents:
diff changeset
   114
definition some_in_set :: "'a set \<Rightarrow> 'a"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   115
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   116
  "some_in_set S \<equiv> SOME x. x \<in> S"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   117
dcde836219bc add thy files
chunhan
parents:
diff changeset
   118
lemma nonempty_set_has_ele: "S \<noteq> {} \<Longrightarrow> \<exists> e. e \<in> S" by auto
dcde836219bc add thy files
chunhan
parents:
diff changeset
   119
dcde836219bc add thy files
chunhan
parents:
diff changeset
   120
lemma some_in_set_prop: "S \<noteq> {} \<Longrightarrow> some_in_set S \<in> S"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   121
by (drule nonempty_set_has_ele, auto simp:some_in_set_def intro:someI)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   122
dcde836219bc add thy files
chunhan
parents:
diff changeset
   123
dcde836219bc add thy files
chunhan
parents:
diff changeset
   124
(*********** locale for RC+OS definitions **********)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   125
dcde836219bc add thy files
chunhan
parents:
diff changeset
   126
definition bidirect_in_init :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   127
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   128
  "bidirect_in_init S f \<equiv>  (\<forall> a. a \<in> S \<longrightarrow> (\<exists> b. f a = Some b)) \<and> 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   129
                           (\<forall> a b. f a = Some b \<longrightarrow> a \<in> S)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   130
dcde836219bc add thy files
chunhan
parents:
diff changeset
   131
locale init =
dcde836219bc add thy files
chunhan
parents:
diff changeset
   132
  fixes 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   133
      init_files :: "t_file set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   134
  and init_file_type :: "t_file \<rightharpoonup> t_normal_file_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   135
  and init_initialrole :: "t_file \<rightharpoonup> t_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   136
  and init_forcedrole :: "t_file \<rightharpoonup> t_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   137
  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   138
  and init_processes :: "t_process set "
dcde836219bc add thy files
chunhan
parents:
diff changeset
   139
  and init_process_type :: "t_process \<rightharpoonup> t_normal_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   140
  and init_currentrole :: "t_process \<rightharpoonup> t_normal_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   141
  and init_proc_forcedrole:: "t_process \<rightharpoonup> t_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   142
dcde836219bc add thy files
chunhan
parents:
diff changeset
   143
  and init_ipcs :: "t_ipc set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   144
  and init_ipc_type:: "t_ipc \<rightharpoonup> t_normal_ipc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   145
dcde836219bc add thy files
chunhan
parents:
diff changeset
   146
  and init_users :: "t_user set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   147
  and init_owner :: "t_process \<rightharpoonup> t_user"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   148
  and defrole :: "t_user \<rightharpoonup> t_normal_role" (* defrole should return normalrole, which is not
dcde836219bc add thy files
chunhan
parents:
diff changeset
   149
specified in NordSec paper *) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   150
dcde836219bc add thy files
chunhan
parents:
diff changeset
   151
  and default_fd_create_type :: "t_normal_role \<Rightarrow> t_rc_file_type" (* this func should only
dcde836219bc add thy files
chunhan
parents:
diff changeset
   152
return type for normal role, for RC special role, error ! NordSec paper*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   153
  and default_ipc_create_type :: "t_normal_role \<Rightarrow> t_normal_ipc_type" (* like above, NordSec paper
dcde836219bc add thy files
chunhan
parents:
diff changeset
   154
does not specify the domain is normal roles *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   155
  and default_process_create_type :: "t_normal_role \<Rightarrow> t_rc_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   156
  and default_process_execute_type :: "t_normal_role \<Rightarrow> t_rc_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   157
  and default_process_chown_type :: "t_normal_role \<Rightarrow> t_rc_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   158
dcde836219bc add thy files
chunhan
parents:
diff changeset
   159
  and comproles :: "t_normal_role \<Rightarrow> t_normal_role set" (* NordSec paper do not specify all roles
dcde836219bc add thy files
chunhan
parents:
diff changeset
   160
here are normal *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   161
dcde836219bc add thy files
chunhan
parents:
diff changeset
   162
  and compatible :: "(t_normal_role \<times> t_normal_rc_type \<times> t_access_type) set"  (* NordSec paper do not specify all roles and all types here are normal ! *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   163
dcde836219bc add thy files
chunhan
parents:
diff changeset
   164
  assumes
dcde836219bc add thy files
chunhan
parents:
diff changeset
   165
      parent_file_in_init: "\<And> f pf. \<lbrakk>parent f = Some pf; f \<in> init_files\<rbrakk> \<Longrightarrow> pf \<in> init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   166
  and root_in_filesystem:  "[] \<in> init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   167
  and init_irole_has_file: "\<And> f r. init_initialrole f = Some r \<Longrightarrow> f \<in> init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   168
  and init_frole_has_file: "\<And> f r. init_forcedrole f = Some r \<Longrightarrow> f \<in> init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   169
  and init_ftype_has_file: "\<And> f t. init_file_type f = Some t \<Longrightarrow> f \<in> init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   170
  and
dcde836219bc add thy files
chunhan
parents:
diff changeset
   171
      init_proc_has_role:  "bidirect_in_init init_processes init_currentrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   172
  and init_proc_has_frole: "bidirect_in_init init_processes init_proc_forcedrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   173
  and init_proc_has_type:  "bidirect_in_init init_processes init_process_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   174
  and
dcde836219bc add thy files
chunhan
parents:
diff changeset
   175
      init_ipc_has_type:   "bidirect_in_init init_ipcs init_ipc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   176
  and
dcde836219bc add thy files
chunhan
parents:
diff changeset
   177
      init_user_has_role:  "bidirect_in_init init_users defrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   178
  and init_proc_has_owner: "bidirect_in_init init_processes init_owner"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   179
  and init_owner_valid:    "\<And> p u. init_owner p = Some u \<Longrightarrow> u \<in> init_users"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   180
  and
dcde836219bc add thy files
chunhan
parents:
diff changeset
   181
      init_finite: "finite init_files \<and> finite init_processes \<and> finite init_ipcs \<and> finite init_users"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   182
begin 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   183
dcde836219bc add thy files
chunhan
parents:
diff changeset
   184
(***** Operating System Listeners *****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   185
dcde836219bc add thy files
chunhan
parents:
diff changeset
   186
fun current_files :: "t_state \<Rightarrow> t_file set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   187
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   188
  "current_files [] = init_files"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   189
| "current_files (CreateFile p f # s) = insert f (current_files s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   190
| "current_files (DeleteFile p f # s) = current_files s - {f}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   191
| "current_files (_ # s) = current_files s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   192
dcde836219bc add thy files
chunhan
parents:
diff changeset
   193
fun current_procs :: "t_state \<Rightarrow> t_process set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   194
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   195
  "current_procs [] = init_processes"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   196
| "current_procs (Clone p p' # s) = insert p' (current_procs s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   197
| "current_procs (Kill p p' # s) = current_procs s - {p'} "
dcde836219bc add thy files
chunhan
parents:
diff changeset
   198
| "current_procs (_ # s) = current_procs s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   199
dcde836219bc add thy files
chunhan
parents:
diff changeset
   200
fun current_ipcs :: "t_state \<Rightarrow> t_ipc set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   201
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   202
  "current_ipcs [] = init_ipcs" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   203
| "current_ipcs (CreateIPC p i # s) = insert i (current_ipcs s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   204
| "current_ipcs (DeleteIPC p i # s) = current_ipcs s - {i}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   205
| "current_ipcs (_ # s) = current_ipcs s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   206
dcde836219bc add thy files
chunhan
parents:
diff changeset
   207
fun owner :: "t_state \<Rightarrow> t_process \<rightharpoonup> t_user"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   208
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   209
  "owner [] = init_owner"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   210
| "owner (Clone p p' # \<tau>) = (owner \<tau>) (p' := owner \<tau> p)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   211
| "owner (ChangeOwner p u # \<tau>) = (owner \<tau>) (p := Some u)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   212
| "owner (_ # \<tau>) = owner \<tau>"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   213
dcde836219bc add thy files
chunhan
parents:
diff changeset
   214
(***** functions for rc internal *****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   215
dcde836219bc add thy files
chunhan
parents:
diff changeset
   216
(*** Roles Functions ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   217
dcde836219bc add thy files
chunhan
parents:
diff changeset
   218
(* comments:
dcde836219bc add thy files
chunhan
parents:
diff changeset
   219
We have fix init_initialrole already in locale, why need this function?
dcde836219bc add thy files
chunhan
parents:
diff changeset
   220
 Cause, users may be lazy to specify every file in the initial state to some InheritParent as
dcde836219bc add thy files
chunhan
parents:
diff changeset
   221
initialrole, they can just specify all the important files with special initial role, leaving
dcde836219bc add thy files
chunhan
parents:
diff changeset
   222
all other None, it is init_file_initialrole's job to fill default value(InheritParent) for 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   223
other files. Accutally, this has the point of "Functional default settings" in the 2 section of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   224
the NordSec paper. 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   225
init_file_forcedrole, and init_file_type_aux are of the same meaning. 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   226
*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   227
fun init_file_initialrole :: "t_file \<rightharpoonup> t_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   228
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   229
  "init_file_initialrole [] = (case (init_initialrole []) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   230
                            None   \<Rightarrow> Some UseForcedRole
dcde836219bc add thy files
chunhan
parents:
diff changeset
   231
                          | Some r \<Rightarrow> Some r)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   232
| "init_file_initialrole f  = (case (init_initialrole f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   233
                            None   \<Rightarrow> Some InheritParentRole
dcde836219bc add thy files
chunhan
parents:
diff changeset
   234
                          | Some r \<Rightarrow> Some r)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   235
dcde836219bc add thy files
chunhan
parents:
diff changeset
   236
fun initialrole :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_role)"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   237
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   238
  "initialrole [] = init_file_initialrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   239
| "initialrole (CreateFile p f # s) = (initialrole s) (f:= Some InheritParentRole)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   240
| "initialrole (_ # s) = initialrole s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   241
dcde836219bc add thy files
chunhan
parents:
diff changeset
   242
fun erole_functor :: "(t_file \<rightharpoonup> t_role) \<Rightarrow> t_role \<Rightarrow> (t_file \<rightharpoonup> t_role)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   243
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   244
  "erole_functor rfunc r [] = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   245
     if (rfunc [] = Some InheritParentRole) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   246
     then Some r 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   247
     else rfunc [] )"                             
dcde836219bc add thy files
chunhan
parents:
diff changeset
   248
| "erole_functor rfunc r (n#ns) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   249
     if (rfunc (n#ns) = Some InheritParentRole) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   250
     then erole_functor rfunc r ns 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   251
     else rfunc (n#ns) )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   252
dcde836219bc add thy files
chunhan
parents:
diff changeset
   253
definition effinitialrole :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_role)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   254
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   255
  "effinitialrole s \<equiv> erole_functor (initialrole s) UseForcedRole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   256
dcde836219bc add thy files
chunhan
parents:
diff changeset
   257
fun init_file_forcedrole :: "t_file \<rightharpoonup> t_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   258
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   259
  "init_file_forcedrole [] = ( case (init_forcedrole []) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   260
                                 None   \<Rightarrow> Some InheritUpMixed
dcde836219bc add thy files
chunhan
parents:
diff changeset
   261
                               | Some r \<Rightarrow> Some r )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   262
| "init_file_forcedrole f  = ( case (init_forcedrole f) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   263
                                 None   \<Rightarrow> Some InheritParentRole
dcde836219bc add thy files
chunhan
parents:
diff changeset
   264
                              |  Some r \<Rightarrow> Some r )"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   265
dcde836219bc add thy files
chunhan
parents:
diff changeset
   266
fun forcedrole :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_role)"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   267
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   268
  "forcedrole [] = init_file_forcedrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   269
| "forcedrole (CreateFile p f # s) = (forcedrole s) (f:= Some InheritParentRole)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   270
| "forcedrole (_ # s) = forcedrole s" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   271
dcde836219bc add thy files
chunhan
parents:
diff changeset
   272
definition effforcedrole :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_role)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   273
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   274
  "effforcedrole s \<equiv> erole_functor (forcedrole s) InheritUpMixed"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   275
dcde836219bc add thy files
chunhan
parents:
diff changeset
   276
fun proc_forcedrole :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_role)" (* $6.7$ *) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   277
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   278
  "proc_forcedrole [] = init_proc_forcedrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   279
| "proc_forcedrole (Execute p f # s) = (proc_forcedrole s) (p := effforcedrole s f)"    
dcde836219bc add thy files
chunhan
parents:
diff changeset
   280
| "proc_forcedrole (Clone p p' # s) = (proc_forcedrole s) (p' := proc_forcedrole s p)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   281
| "proc_forcedrole (e # s) = proc_forcedrole s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   282
dcde836219bc add thy files
chunhan
parents:
diff changeset
   283
fun currentrole :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_normal_role)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   284
where 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   285
  "currentrole [] = init_currentrole"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   286
| "currentrole (Clone p p' # \<tau>) = (currentrole \<tau>) (p' := currentrole \<tau> p)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   287
| "currentrole (Execute p f # \<tau>) = (currentrole \<tau>) (p := 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   288
     case (effinitialrole \<tau> f) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   289
       Some ir \<Rightarrow> (case ir of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   290
                     NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   291
                   | UseForcedRole \<Rightarrow> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   292
                       case (effforcedrole \<tau> f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   293
                         Some fr \<Rightarrow> (case fr of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   294
                                       NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   295
                                     | InheritUserRole \<Rightarrow> (defrole \<circ>\<^sub>m (owner \<tau>)) p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   296
                                     | InheritProcessRole \<Rightarrow> currentrole \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   297
                                     | InheritUpMixed \<Rightarrow> currentrole \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   298
                                     | _ \<Rightarrow> None )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   299
                       | _ \<Rightarrow> None    )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   300
                   | _  \<Rightarrow> None )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   301
     | _ \<Rightarrow> None                                   )"       
dcde836219bc add thy files
chunhan
parents:
diff changeset
   302
| "currentrole (ChangeOwner p u # \<tau>) = (currentrole \<tau>) (p := 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   303
     case (proc_forcedrole \<tau> p) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   304
       Some fr \<Rightarrow> (case fr of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   305
                     NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   306
                   | InheritProcessRole \<Rightarrow> currentrole \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   307
                   | InheritUserRole \<Rightarrow> defrole u
dcde836219bc add thy files
chunhan
parents:
diff changeset
   308
                   | InheritUpMixed \<Rightarrow> defrole u
dcde836219bc add thy files
chunhan
parents:
diff changeset
   309
                   | _ \<Rightarrow> None)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   310
     | _ \<Rightarrow> None                                       )"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   311
| "currentrole (ChangeRole p r # \<tau>) = (currentrole \<tau>) (p := Some r)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   312
| "currentrole (_ # \<tau>) = currentrole \<tau>"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   313
dcde836219bc add thy files
chunhan
parents:
diff changeset
   314
(*** Types Functions ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   315
dcde836219bc add thy files
chunhan
parents:
diff changeset
   316
fun init_file_type_aux :: "t_file \<rightharpoonup> t_rc_file_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   317
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   318
  "init_file_type_aux f = (if (f \<in> init_files)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   319
                         then (case (init_file_type f) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   320
                                 Some t \<Rightarrow> Some (NormalFile_type t)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   321
                               | _      \<Rightarrow> Some InheritParent_file_type)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   322
                         else None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   323
dcde836219bc add thy files
chunhan
parents:
diff changeset
   324
fun type_of_file :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_rc_file_type)" (* (6) *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   325
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   326
  "type_of_file [] = init_file_type_aux" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   327
| "type_of_file (CreateFile p f # s) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   328
     case (currentrole s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   329
       Some r \<Rightarrow> (type_of_file s) (f := Some (default_fd_create_type r))
dcde836219bc add thy files
chunhan
parents:
diff changeset
   330
     | _      \<Rightarrow> (type_of_file s) (f := None))" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   331
| "type_of_file (_ # s) = type_of_file s"  (* add by wch *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   332
dcde836219bc add thy files
chunhan
parents:
diff changeset
   333
fun etype_aux:: "(t_file \<rightharpoonup> t_rc_file_type) \<Rightarrow> (t_file \<rightharpoonup> t_normal_file_type)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   334
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   335
  "etype_aux typf [] = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   336
     case (typf []) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   337
       Some InheritParent_file_type \<Rightarrow> Some Root_file_type
dcde836219bc add thy files
chunhan
parents:
diff changeset
   338
     | Some (NormalFile_type t) \<Rightarrow> Some t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   339
     | None \<Rightarrow> None )"        
dcde836219bc add thy files
chunhan
parents:
diff changeset
   340
| "etype_aux typf (n#ns) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   341
     case (typf (n#ns)) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   342
       Some InheritParent_file_type \<Rightarrow> etype_aux typf ns
dcde836219bc add thy files
chunhan
parents:
diff changeset
   343
     | Some (NormalFile_type t) \<Rightarrow> Some t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   344
     | None \<Rightarrow> None )"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   345
dcde836219bc add thy files
chunhan
parents:
diff changeset
   346
definition etype_of_file :: "t_state \<Rightarrow> (t_file \<rightharpoonup> t_normal_file_type)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   347
    (* etype is always normal *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   348
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   349
  "etype_of_file s \<equiv> etype_aux (type_of_file s)"              
dcde836219bc add thy files
chunhan
parents:
diff changeset
   350
dcde836219bc add thy files
chunhan
parents:
diff changeset
   351
definition pct :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_rc_proc_type)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   352
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   353
  "pct s p \<equiv> (case (currentrole s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   354
                Some r \<Rightarrow> Some (default_process_create_type r)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   355
              | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   356
dcde836219bc add thy files
chunhan
parents:
diff changeset
   357
definition pet :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_rc_proc_type)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   358
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   359
  "pet s p \<equiv> (case (currentrole s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   360
                Some r \<Rightarrow> Some (default_process_execute_type r)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   361
              | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   362
dcde836219bc add thy files
chunhan
parents:
diff changeset
   363
definition pot :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_rc_proc_type)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   364
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   365
  "pot s p \<equiv> (case (currentrole s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   366
                Some r \<Rightarrow> Some (default_process_chown_type r)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   367
              | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   368
dcde836219bc add thy files
chunhan
parents:
diff changeset
   369
fun type_of_process :: "t_state \<Rightarrow> (t_process \<rightharpoonup> t_normal_proc_type)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   370
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   371
  "type_of_process [] = init_process_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   372
| "type_of_process (Clone p p' # \<tau>) = (type_of_process \<tau>) (p' := 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   373
     case (pct \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   374
       Some InheritParent_proc_type \<Rightarrow> type_of_process \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   375
     | Some (NormalProc_type tp)    \<Rightarrow> Some tp
dcde836219bc add thy files
chunhan
parents:
diff changeset
   376
     | _                            \<Rightarrow> None               )" (*6.80*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   377
| "type_of_process (Execute p f # \<tau>) = (type_of_process \<tau>) (p :=
dcde836219bc add thy files
chunhan
parents:
diff changeset
   378
     case (pet \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   379
       Some InheritParent_proc_type \<Rightarrow> type_of_process \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   380
     | Some (NormalProc_type tp)    \<Rightarrow> Some tp
dcde836219bc add thy files
chunhan
parents:
diff changeset
   381
     | _                            \<Rightarrow> None                )" (*6.82*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   382
| "type_of_process (ChangeOwner p u # \<tau>) = (type_of_process \<tau>) (p :=
dcde836219bc add thy files
chunhan
parents:
diff changeset
   383
     case (pot \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   384
       Some InheritParent_proc_type \<Rightarrow> type_of_process \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   385
     | Some UseNewRoleType          \<Rightarrow> (case (pct (ChangeOwner p u # \<tau>) p) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   386
                                          Some InheritParent_proc_type \<Rightarrow> type_of_process \<tau> p
dcde836219bc add thy files
chunhan
parents:
diff changeset
   387
                                        | Some (NormalProc_type tp)    \<Rightarrow> Some tp
dcde836219bc add thy files
chunhan
parents:
diff changeset
   388
                                        | _                            \<Rightarrow> None)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   389
     | Some (NormalProc_type tp)    \<Rightarrow> Some tp
dcde836219bc add thy files
chunhan
parents:
diff changeset
   390
     | _                            \<Rightarrow> None                    )"   (* the UseNewRoleType case is refered with Nordsec paper 4 (11), and it is not right??! of just
dcde836219bc add thy files
chunhan
parents:
diff changeset
   391
use "pct" *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   392
| "type_of_process (_ # \<tau>) = type_of_process \<tau>" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   393
dcde836219bc add thy files
chunhan
parents:
diff changeset
   394
fun type_of_ipc :: "t_state \<Rightarrow> (t_ipc \<rightharpoonup> t_normal_ipc_type)" (* (14) *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   395
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   396
  "type_of_ipc [] = init_ipc_type" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   397
| "type_of_ipc (CreateIPC p i # s) = (type_of_ipc s) (i := 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   398
     case (currentrole s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   399
       Some r \<Rightarrow> Some (default_ipc_create_type r)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   400
     | _      \<Rightarrow> None                                )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   401
| "type_of_ipc (_ # s) = type_of_ipc s" (* add by wch *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   402
dcde836219bc add thy files
chunhan
parents:
diff changeset
   403
(*** RC access control ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   404
fun rc_grant :: "t_state \<Rightarrow> t_event \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   405
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   406
  "rc_grant \<tau> (CreateFile p f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   407
     case (parent f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   408
       Some pf \<Rightarrow> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   409
         case (currentrole \<tau> p, etype_of_file \<tau> pf) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   410
           (Some r, Some t) \<Rightarrow> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   411
              case (default_fd_create_type r) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   412
                InheritParent_file_type \<Rightarrow> (r, File_type t, WRITE) \<in> compatible 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   413
              | NormalFile_type t' \<Rightarrow> (r, File_type t, WRITE) \<in> compatible \<and> (r, File_type t', CREATE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   414
                               )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   415
         | _               \<Rightarrow> False )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   416
     | _       \<Rightarrow> False                         )"  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   417
| "rc_grant \<tau> (ReadFile p f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   418
     case (currentrole \<tau> p, etype_of_file \<tau> f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   419
        (Some r, Some t) \<Rightarrow> (r, File_type t, READ) \<in> compatible 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   420
     | _                \<Rightarrow> False                )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   421
| "rc_grant \<tau> (WriteFile p f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   422
     case (currentrole \<tau> p, etype_of_file \<tau> f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   423
       (Some r, Some t) \<Rightarrow> (r, File_type t, WRITE) \<in> compatible 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   424
     | _      \<Rightarrow> False                          )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   425
| "rc_grant \<tau> (Execute p f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   426
     case (currentrole \<tau> p, etype_of_file \<tau> f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   427
       (Some r, Some t) \<Rightarrow> (r, File_type t, EXECUTE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   428
     | _                \<Rightarrow> False               )"     
dcde836219bc add thy files
chunhan
parents:
diff changeset
   429
| "rc_grant \<tau> (ChangeOwner p u) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   430
     case (currentrole \<tau> p, type_of_process \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   431
       (Some r, Some t) \<Rightarrow> (r, Proc_type t, CHANGE_OWNER) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   432
     | _      \<Rightarrow> False                         )" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   433
| "rc_grant \<tau> (Clone p newproc) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   434
     case (currentrole \<tau> p, type_of_process \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   435
       (Some r, Some t) \<Rightarrow> (r, Proc_type t, CREATE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   436
     | _      \<Rightarrow> False                         )" (* premiss of no limit to clone is removed to locale assumptions *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   437
| "rc_grant \<tau> (ChangeRole p r) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   438
     case (currentrole \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   439
       Some cr \<Rightarrow> r \<in> comproles cr
dcde836219bc add thy files
chunhan
parents:
diff changeset
   440
     | _       \<Rightarrow> False                        )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   441
| "rc_grant \<tau> (Send p i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   442
     case (currentrole \<tau> p, type_of_ipc \<tau> i) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   443
       (Some r, Some t) \<Rightarrow> (r, IPC_type t, SEND) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   444
     | _                \<Rightarrow> False               )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   445
| "rc_grant \<tau> (Recv p i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   446
     case (currentrole \<tau> p, type_of_ipc \<tau> i) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   447
       (Some r, Some t) \<Rightarrow> (r, IPC_type t, RECEIVE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   448
     | _                \<Rightarrow> False               )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   449
| "rc_grant \<tau> (CreateIPC p i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   450
     case (currentrole \<tau> p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   451
       Some r \<Rightarrow> (r, IPC_type (default_ipc_create_type r), CREATE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   452
     | _      \<Rightarrow> False                         )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   453
| "rc_grant \<tau> (DeleteFile p f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   454
     case (currentrole \<tau> p, etype_of_file \<tau> f) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   455
       (Some r, Some t) \<Rightarrow> (r, File_type t, DELETE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   456
     | _                \<Rightarrow> False               )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   457
| "rc_grant \<tau> (DeleteIPC p i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   458
     case (currentrole \<tau> p, type_of_ipc \<tau> i) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   459
       (Some r, Some t) \<Rightarrow> (r, IPC_type t, DELETE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   460
     | _                \<Rightarrow> False               )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   461
| "rc_grant \<tau> (Kill p p') = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   462
     case (currentrole \<tau> p, type_of_process \<tau> p') of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   463
       (Some r, Some t) \<Rightarrow> (r, Proc_type t, DELETE) \<in> compatible
dcde836219bc add thy files
chunhan
parents:
diff changeset
   464
     | _                \<Rightarrow> False               )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   465
dcde836219bc add thy files
chunhan
parents:
diff changeset
   466
(* new file pathname is user-defined, so os just check if its unexistence *) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   467
fun os_grant :: "t_state \<Rightarrow> t_event \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   468
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   469
  "os_grant \<tau> (Execute p f)    = (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   470
| "os_grant \<tau> (CreateFile p f) = (p \<in> current_procs \<tau> \<and> f \<notin> current_files \<tau> \<and> (\<exists> pf. (parent f = Some pf) \<and> pf \<in> current_files \<tau>))"  (*cannot create disk, ?? or f = [] ??*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   471
| "os_grant \<tau> (ChangeRole p r) = (p \<in> current_procs \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   472
| "os_grant \<tau> (ReadFile p f)   = (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   473
| "os_grant \<tau> (WriteFile p f)  = (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   474
| "os_grant \<tau> (ChangeOwner p u)= (p \<in> current_procs \<tau> \<and> u \<in> init_users)"
6
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   475
| "os_grant \<tau> (CreateIPC p i)  = (p \<in> current_procs \<tau> \<and> i \<notin> current_ipcs \<tau>)" (* i = new_ipc \<tau> *)
1
dcde836219bc add thy files
chunhan
parents:
diff changeset
   476
| "os_grant \<tau> (Send p i)       = (p \<in> current_procs \<tau> \<and> i \<in> current_ipcs \<tau>)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   477
| "os_grant \<tau> (Recv p i)       = (p \<in> current_procs \<tau> \<and> i \<in> current_ipcs \<tau>)"
6
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   478
| "os_grant \<tau> (Clone p p')     = (p \<in> current_procs \<tau> \<and> p' \<notin> current_procs \<tau>)" (* p' = new_proc \<tau> *)
1
dcde836219bc add thy files
chunhan
parents:
diff changeset
   479
| "os_grant \<tau> (Kill p p')      = (p \<in> current_procs \<tau> \<and> p' \<in> current_procs \<tau>)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   480
| "os_grant \<tau> (DeleteFile p f) = (p \<in> current_procs \<tau> \<and> f \<in> current_files \<tau> \<and> \<not> (\<exists>fn. fn # f \<in> current_files \<tau>))"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   481
| "os_grant \<tau> (DeleteIPC p i)  = (p \<in> current_procs \<tau> \<and> i \<in> current_ipcs \<tau>)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   482
dcde836219bc add thy files
chunhan
parents:
diff changeset
   483
(**** system valid state ****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   484
dcde836219bc add thy files
chunhan
parents:
diff changeset
   485
inductive valid :: "t_state \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   486
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   487
  vs_nil:  "valid []"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   488
| vs_step: "\<lbrakk>valid s; os_grant s e; rc_grant s e\<rbrakk> \<Longrightarrow> valid (e # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   489
dcde836219bc add thy files
chunhan
parents:
diff changeset
   490
end
dcde836219bc add thy files
chunhan
parents:
diff changeset
   491
dcde836219bc add thy files
chunhan
parents:
diff changeset
   492
(*** more RC constrains of type system in formalisation ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   493
dcde836219bc add thy files
chunhan
parents:
diff changeset
   494
locale rc_basic = init +
dcde836219bc add thy files
chunhan
parents:
diff changeset
   495
  assumes 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   496
      init_initialrole_valid: "\<And> f r. init_initialrole f = Some r \<Longrightarrow> r = InheritParentRole \<or> r = UseForcedRole \<or> (\<exists> nr. r = NormalRole nr)"   (* 6.10 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   497
  and init_forcedrole_valid:  "\<And> f r. init_forcedrole f = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole \<or> r = InheritParentRole \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)"  (* 6.11 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   498
  and init_proc_forcedrole_valid: "\<And> p r. init_proc_forcedrole p = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)"  (* 6.7 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   499
  and default_fd_create_type_valid: "\<And> nr t. default_fd_create_type nr = t \<Longrightarrow> t = InheritParent_file_type \<or> (\<exists> nt. t = NormalFile_type nt)" (*6.16*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   500
  and default_process_create_type_valid: "\<And> nr t. default_process_create_type nr = t \<Longrightarrow> t = InheritParent_proc_type \<or> (\<exists> nt. t = NormalProc_type nt)" (*6.18*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   501
  and default_process_chown_type_valid: "\<And> nr t. default_process_chown_type nr = t \<Longrightarrow> t = InheritParent_proc_type \<or> t = UseNewRoleType \<or> (\<exists> nt. t = NormalProc_type nt)" (*6.19*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   502
  and default_process_execute_type_valid: "\<And> nr t. default_process_execute_type nr = t \<Longrightarrow> t = InheritParent_proc_type \<or> (\<exists> nt. t = NormalProc_type nt)" (*6.20*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   503
dcde836219bc add thy files
chunhan
parents:
diff changeset
   504
begin
dcde836219bc add thy files
chunhan
parents:
diff changeset
   505
dcde836219bc add thy files
chunhan
parents:
diff changeset
   506
lemma init_file_initialrole_valid: "init_file_initialrole f = Some r \<Longrightarrow> r = InheritParentRole \<or> r = UseForcedRole \<or> (\<exists> nr. r = NormalRole nr)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   507
apply (induct f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   508
by (auto simp:init_file_initialrole.simps dest:init_initialrole_valid split:option.splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   509
dcde836219bc add thy files
chunhan
parents:
diff changeset
   510
lemma initialrole_valid: "initialrole \<tau> f = Some r \<Longrightarrow> r = InheritParentRole \<or> r = UseForcedRole \<or> (\<exists> nr. r = NormalRole nr)"   (* 6.10 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   511
apply (induct \<tau> arbitrary:f)  defer
dcde836219bc add thy files
chunhan
parents:
diff changeset
   512
apply (case_tac a)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   513
apply (auto simp:initialrole.simps dest:init_file_initialrole_valid 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   514
            split:option.splits if_splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   515
done
dcde836219bc add thy files
chunhan
parents:
diff changeset
   516
dcde836219bc add thy files
chunhan
parents:
diff changeset
   517
lemma effinitialrole_valid: "effinitialrole \<tau> f = Some r \<Longrightarrow> r = UseForcedRole \<or> (\<exists> nr. r = NormalRole nr)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   518
apply (induct f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   519
apply (auto simp:effinitialrole_def dest:initialrole_valid split:option.splits if_splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   520
done
dcde836219bc add thy files
chunhan
parents:
diff changeset
   521
dcde836219bc add thy files
chunhan
parents:
diff changeset
   522
lemma init_file_forcedrole_valid: 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   523
  "init_file_forcedrole f = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole \<or> r = InheritParentRole \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   524
apply (induct f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   525
by (auto simp:init_file_forcedrole.simps dest:init_forcedrole_valid split:option.splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   526
dcde836219bc add thy files
chunhan
parents:
diff changeset
   527
lemma forcedrole_valid: "forcedrole \<tau> f = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole \<or> r = InheritParentRole \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)"  (* 6.10 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   528
apply (induct \<tau> arbitrary:f) defer 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   529
apply (case_tac a)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   530
apply (auto simp:forcedrole.simps dest:init_file_forcedrole_valid 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   531
           split:option.splits if_splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   532
done
dcde836219bc add thy files
chunhan
parents:
diff changeset
   533
dcde836219bc add thy files
chunhan
parents:
diff changeset
   534
lemma effforcedrole_valid: "effforcedrole \<tau> f = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole  \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   535
apply (induct f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   536
apply (auto simp:effforcedrole_def dest:forcedrole_valid split:option.splits if_splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   537
done
dcde836219bc add thy files
chunhan
parents:
diff changeset
   538
dcde836219bc add thy files
chunhan
parents:
diff changeset
   539
lemma proc_forcedrole_valid: "proc_forcedrole \<tau> p = Some r \<Longrightarrow> r = InheritUserRole \<or> r = InheritProcessRole \<or> r = InheritUpMixed \<or> (\<exists> nr. r = NormalRole nr)"  (* 6.7 *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   540
apply (induct \<tau> arbitrary:p) defer
dcde836219bc add thy files
chunhan
parents:
diff changeset
   541
apply (case_tac a)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   542
apply (auto simp:proc_forcedrole.simps dest:init_proc_forcedrole_valid effforcedrole_valid 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   543
           split:option.splits if_splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   544
done
dcde836219bc add thy files
chunhan
parents:
diff changeset
   545
dcde836219bc add thy files
chunhan
parents:
diff changeset
   546
lemma pct_valid: "pct \<tau> p = Some t \<Longrightarrow> t = InheritParent_proc_type \<or> (\<exists> nt. t = NormalProc_type nt)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   547
by (auto simp:pct_def default_process_create_type_valid split:option.splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   548
  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   549
lemma pot_valid: "pot \<tau> p = Some t \<Longrightarrow> t = InheritParent_proc_type \<or> t = UseNewRoleType \<or> (\<exists> nt. t = NormalProc_type nt)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   550
by (auto simp:pot_def default_process_chown_type_valid split:option.splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   551
dcde836219bc add thy files
chunhan
parents:
diff changeset
   552
lemma pet_valid: "pet \<tau> p = Some t \<Longrightarrow> t = InheritParent_proc_type \<or> (\<exists> nt. t = NormalProc_type nt)" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   553
by (simp add:pet_def default_process_execute_type_valid map_comp_def split:option.splits)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   554
dcde836219bc add thy files
chunhan
parents:
diff changeset
   555
end
dcde836219bc add thy files
chunhan
parents:
diff changeset
   556
dcde836219bc add thy files
chunhan
parents:
diff changeset
   557
(******* Reachable/tainting related type definitions  ********)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   558
 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   559
datatype t_object = 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   560
  Proc "t_process" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   561
| File "t_file"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   562
| IPC  "t_ipc"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   563
dcde836219bc add thy files
chunhan
parents:
diff changeset
   564
fun object_in_init :: "t_object \<Rightarrow> t_file set \<Rightarrow> t_process set \<Rightarrow> t_ipc set \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   565
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   566
  "object_in_init (Proc p) init_files init_procs init_ipcs = (p \<in> init_procs)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   567
| "object_in_init (File f) init_files init_procs init_ipcs = (f \<in> init_files)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   568
| "object_in_init (IPC i) init_files init_procs init_ipcs = (i \<in> init_ipcs)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   569
dcde836219bc add thy files
chunhan
parents:
diff changeset
   570
(*** locale for dynamic tainting ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   571
dcde836219bc add thy files
chunhan
parents:
diff changeset
   572
locale tainting = rc_basic + 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   573
dcde836219bc add thy files
chunhan
parents:
diff changeset
   574
fixes seeds :: "t_object set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   575
dcde836219bc add thy files
chunhan
parents:
diff changeset
   576
assumes
dcde836219bc add thy files
chunhan
parents:
diff changeset
   577
  seeds_in_init: "\<And> obj. obj \<in> seeds \<Longrightarrow> object_in_init obj init_files init_processes init_ipcs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   578
begin
dcde836219bc add thy files
chunhan
parents:
diff changeset
   579
dcde836219bc add thy files
chunhan
parents:
diff changeset
   580
lemma finite_seeds: "finite seeds"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   581
proof-
dcde836219bc add thy files
chunhan
parents:
diff changeset
   582
  have "finite {obj. object_in_init obj init_files init_processes init_ipcs}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   583
  proof-
dcde836219bc add thy files
chunhan
parents:
diff changeset
   584
    have "finite {File f| f. f \<in> init_files}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   585
      using init_finite by auto
dcde836219bc add thy files
chunhan
parents:
diff changeset
   586
    moreover have "finite {Proc p| p. p \<in> init_processes}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   587
      using init_finite by auto
dcde836219bc add thy files
chunhan
parents:
diff changeset
   588
    moreover have "finite {IPC i| i. i \<in> init_ipcs}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   589
      using init_finite by auto
dcde836219bc add thy files
chunhan
parents:
diff changeset
   590
    ultimately have "finite ({File f| f. f \<in> init_files} \<union> {Proc p| p. p \<in> init_processes} \<union> {IPC i| i. i \<in> init_ipcs})"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   591
      by auto
dcde836219bc add thy files
chunhan
parents:
diff changeset
   592
    thus ?thesis
dcde836219bc add thy files
chunhan
parents:
diff changeset
   593
      apply (rule_tac B = "({File f| f. f \<in> init_files} \<union> {Proc p| p. p \<in> init_processes} \<union> {IPC i| i. i \<in> init_ipcs})" in finite_subset)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   594
      by (auto, case_tac x, simp+)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   595
  qed
dcde836219bc add thy files
chunhan
parents:
diff changeset
   596
  with seeds_in_init
dcde836219bc add thy files
chunhan
parents:
diff changeset
   597
  show ?thesis
dcde836219bc add thy files
chunhan
parents:
diff changeset
   598
    by (rule_tac finite_subset, auto)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   599
qed
dcde836219bc add thy files
chunhan
parents:
diff changeset
   600
dcde836219bc add thy files
chunhan
parents:
diff changeset
   601
fun exists :: "t_state \<Rightarrow> t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   602
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   603
  "exists s (File f) = (f \<in> current_files s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   604
| "exists s (Proc p) = (p \<in> current_procs s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   605
| "exists s (IPC  i) = (i \<in> current_ipcs  s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   606
dcde836219bc add thy files
chunhan
parents:
diff changeset
   607
inductive tainted :: "t_object \<Rightarrow> t_state \<Rightarrow> bool" ("_ \<in> tainted _" [100, 100] 100)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   608
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   609
  t_init:  "obj \<in> seeds \<Longrightarrow> obj \<in> tainted []"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   610
| t_clone: "\<lbrakk>Proc p \<in> tainted s; valid (Clone p p' # s)\<rbrakk> \<Longrightarrow> Proc p' \<in> tainted (Clone p p' # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   611
| t_exec:  "\<lbrakk>File f \<in> tainted s; valid (Execute p f # s)\<rbrakk> \<Longrightarrow> Proc p \<in> tainted (Execute p f # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   612
| t_cfile: "\<lbrakk>Proc p \<in> tainted s; valid (CreateFile p f # s)\<rbrakk> \<Longrightarrow> File f \<in> tainted (CreateFile p f # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   613
| t_cipc:  "\<lbrakk>Proc p \<in> tainted s; valid (CreateIPC p i # s)\<rbrakk> \<Longrightarrow> IPC i \<in> tainted (CreateIPC p i # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   614
| t_read:  "\<lbrakk>File f \<in> tainted s; valid (ReadFile p f # s)\<rbrakk> \<Longrightarrow> Proc p \<in> tainted (ReadFile p f # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   615
| t_write: "\<lbrakk>Proc p \<in> tainted s; valid (WriteFile p f # s)\<rbrakk> \<Longrightarrow> File f \<in> tainted (WriteFile p f # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   616
| t_send:  "\<lbrakk>Proc p \<in> tainted s; valid (Send p i # s)\<rbrakk> \<Longrightarrow> IPC i \<in> tainted (Send p i # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   617
| t_recv:  "\<lbrakk>IPC i \<in> tainted s; valid (Recv p i # s)\<rbrakk> \<Longrightarrow> Proc p \<in> tainted (Recv p i # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   618
| t_remain:"\<lbrakk>obj \<in> tainted s; valid (e # s); exists (e # s) obj\<rbrakk> \<Longrightarrow> obj \<in> tainted (e # s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   619
dcde836219bc add thy files
chunhan
parents:
diff changeset
   620
definition taintable:: "t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   621
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   622
  "taintable obj \<equiv> \<exists> s. obj \<in> tainted s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   623
dcde836219bc add thy files
chunhan
parents:
diff changeset
   624
fun deleted :: "t_object \<Rightarrow> t_event list \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   625
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   626
  "deleted obj [] = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   627
| "deleted obj (Kill p p' # \<tau>) = ((obj = Proc p') \<or> deleted obj \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   628
| "deleted obj (DeleteFile p f # \<tau>) = ((obj = File f) \<or> deleted obj \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   629
| "deleted obj (DeleteIPC p i # \<tau>) = ((obj = IPC i) \<or> deleted obj \<tau>)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   630
| "deleted obj (_ # \<tau>) = deleted obj \<tau>"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   631
dcde836219bc add thy files
chunhan
parents:
diff changeset
   632
definition undeletable :: "t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   633
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   634
  "undeletable obj \<equiv> exists [] obj \<and> \<not> (\<exists> s. valid s \<and> deleted obj s)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   635
dcde836219bc add thy files
chunhan
parents:
diff changeset
   636
fun no_del_event:: "t_event list \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   637
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   638
  "no_del_event [] = True"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   639
| "no_del_event (Kill p p' # \<tau>) = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   640
| "no_del_event (DeleteFile p f # \<tau>) = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   641
| "no_del_event (DeleteIPC p i # \<tau>) = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   642
| "no_del_event (_ # \<tau>) = no_del_event \<tau>"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   643
dcde836219bc add thy files
chunhan
parents:
diff changeset
   644
end
dcde836219bc add thy files
chunhan
parents:
diff changeset
   645
dcde836219bc add thy files
chunhan
parents:
diff changeset
   646
dcde836219bc add thy files
chunhan
parents:
diff changeset
   647
(***** locale for statical world *****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   648
dcde836219bc add thy files
chunhan
parents:
diff changeset
   649
type_synonym t_sprocess = "t_normal_role \<times> t_role \<times> t_normal_proc_type \<times> t_user"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   650
dcde836219bc add thy files
chunhan
parents:
diff changeset
   651
type_synonym t_sfile = "t_normal_file_type \<times> t_file"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   652
dcde836219bc add thy files
chunhan
parents:
diff changeset
   653
type_synonym t_sipc = "t_normal_ipc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   654
dcde836219bc add thy files
chunhan
parents:
diff changeset
   655
datatype t_sobject =
dcde836219bc add thy files
chunhan
parents:
diff changeset
   656
  SProc "t_sprocess" "t_process option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   657
| SFile "t_sfile"    "t_file option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   658
| SIPC  "t_sipc"     "t_ipc option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   659
| Unknown
dcde836219bc add thy files
chunhan
parents:
diff changeset
   660
dcde836219bc add thy files
chunhan
parents:
diff changeset
   661
locale tainting_s_complete = tainting
dcde836219bc add thy files
chunhan
parents:
diff changeset
   662
dcde836219bc add thy files
chunhan
parents:
diff changeset
   663
begin 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   664
dcde836219bc add thy files
chunhan
parents:
diff changeset
   665
definition chown_role_aux:: "t_normal_role \<Rightarrow> t_role \<Rightarrow> t_user \<Rightarrow> t_normal_role option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   666
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   667
  "chown_role_aux cr fr u \<equiv> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   668
     case fr of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   669
       NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   670
     | InheritProcessRole \<Rightarrow> Some cr
dcde836219bc add thy files
chunhan
parents:
diff changeset
   671
     | _ \<Rightarrow> defrole u       )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   672
dcde836219bc add thy files
chunhan
parents:
diff changeset
   673
definition chown_type_aux:: "t_normal_role \<Rightarrow> t_normal_role \<Rightarrow> t_normal_proc_type \<Rightarrow> t_normal_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   674
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   675
  "chown_type_aux cr nr t \<equiv> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   676
     case (default_process_chown_type cr) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   677
       InheritParent_proc_type   \<Rightarrow> t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   678
     | UseNewRoleType            \<Rightarrow> (case (default_process_create_type nr) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   679
                                      InheritParent_proc_type \<Rightarrow> t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   680
                                     | NormalProc_type tp      \<Rightarrow> tp)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   681
     | NormalProc_type tp        \<Rightarrow> tp )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   682
dcde836219bc add thy files
chunhan
parents:
diff changeset
   683
definition exec_type_aux :: "t_normal_role \<Rightarrow> t_normal_proc_type \<Rightarrow> t_normal_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   684
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   685
  "exec_type_aux cr t \<equiv> (case (default_process_execute_type cr) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   686
                           InheritParent_proc_type \<Rightarrow> t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   687
                         | NormalProc_type tp      \<Rightarrow>tp)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   688
dcde836219bc add thy files
chunhan
parents:
diff changeset
   689
definition exec_role_aux :: "t_normal_role \<Rightarrow> t_file \<Rightarrow> t_user \<Rightarrow> t_normal_role option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   690
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   691
 "exec_role_aux cr sd u \<equiv> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   692
    case (erole_functor init_file_initialrole UseForcedRole sd) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   693
      Some ir \<Rightarrow> (case ir of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   694
                     NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   695
                   | UseForcedRole \<Rightarrow> (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   696
                       case (erole_functor init_file_forcedrole InheritUpMixed sd) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   697
                         Some fr \<Rightarrow> (case fr of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   698
                                       NormalRole r \<Rightarrow> Some r
dcde836219bc add thy files
chunhan
parents:
diff changeset
   699
                                     | InheritUserRole \<Rightarrow> defrole u 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   700
                                     | _ \<Rightarrow> Some cr )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   701
                       | None    \<Rightarrow> None )     
dcde836219bc add thy files
chunhan
parents:
diff changeset
   702
                   | _  \<Rightarrow> None )
dcde836219bc add thy files
chunhan
parents:
diff changeset
   703
     | _ \<Rightarrow> None            )"       
dcde836219bc add thy files
chunhan
parents:
diff changeset
   704
dcde836219bc add thy files
chunhan
parents:
diff changeset
   705
definition clone_type_aux :: "t_normal_role \<Rightarrow> t_normal_proc_type \<Rightarrow> t_normal_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   706
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   707
  "clone_type_aux r t \<equiv> (case (default_process_create_type r) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   708
                           InheritParent_proc_type \<Rightarrow> t
dcde836219bc add thy files
chunhan
parents:
diff changeset
   709
                         | NormalProc_type tp      \<Rightarrow> tp)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   710
dcde836219bc add thy files
chunhan
parents:
diff changeset
   711
(* all the static objects that dynamic objects referring to *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   712
(* they should all be in a finite set ? *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   713
(* besides, they're no clone case for all_sobjs, we have no "SProc ... None" case, Clone p p', p' statically viewed as p too, so the many2many mapping becomes to many2one, which makes all succeeded*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   714
inductive_set all_sobjs :: "t_sobject set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   715
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   716
  af_init:  "\<lbrakk>f \<in> init_files; etype_aux init_file_type_aux f = Some t\<rbrakk> \<Longrightarrow> SFile (t, f) (Some f) \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   717
| af_cfd:   "\<lbrakk>SFile (t, sd) sf \<in> all_sobjs; SProc (r, fr, pt, u) sp \<in> all_sobjs; default_fd_create_type r = NormalFile_type t'; (r, File_type t, WRITE) \<in> compatible; (r, File_type t', CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t', sd) None \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   718
| af_cfd':  "\<lbrakk>SFile (t, sd) sf \<in> all_sobjs; SProc (r, fr, pt, u) sp \<in> all_sobjs; default_fd_create_type r = InheritParent_file_type; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) None \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   719
dcde836219bc add thy files
chunhan
parents:
diff changeset
   720
| ai_init:  "init_ipc_type i = Some t \<Longrightarrow> SIPC t (Some i) \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   721
| ai_cipc:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> all_sobjs; (r, IPC_type (default_ipc_create_type r), CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC (default_ipc_create_type r) None \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   722
dcde836219bc add thy files
chunhan
parents:
diff changeset
   723
| ap_init:  "\<lbrakk>init_currentrole p = Some r; init_proc_forcedrole p = Some fr; init_process_type p = Some t; init_owner p = Some u\<rbrakk> \<Longrightarrow> SProc (r, fr, t, u) (Some p) \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   724
| ap_crole: "\<lbrakk>SProc (r, fr, t, u) sp \<in> all_sobjs; r' \<in> comproles r\<rbrakk> \<Longrightarrow> SProc (r', fr, t, u) sp \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   725
| ap_chown: "\<lbrakk>SProc (r, fr, t, u') sp \<in> all_sobjs; u \<in> init_users; chown_role_aux r fr u = Some nr; (r, Proc_type t, CHANGE_OWNER) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (nr, fr, chown_type_aux r nr t, u) sp \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   726
| ap_exec:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> all_sobjs; SFile (t, sd) sf \<in> all_sobjs; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> all_sobjs" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   727
| ap_clone: "SProc (r, fr, pt, u) sp \<in> all_sobjs \<Longrightarrow> SProc (r, fr, clone_type_aux r pt, u) sp \<in> all_sobjs"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   728
dcde836219bc add thy files
chunhan
parents:
diff changeset
   729
fun init_obj2sobj :: "t_object \<Rightarrow> t_sobject"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   730
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   731
  "init_obj2sobj (File f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   732
     case (etype_aux init_file_type_aux f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   733
       Some t \<Rightarrow> SFile (t, f) (Some f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   734
     | _      \<Rightarrow> Unknown      )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   735
| "init_obj2sobj (Proc p) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   736
     case (init_currentrole p, init_proc_forcedrole p, init_process_type p, init_owner p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   737
       (Some r, Some fr, Some t, Some u) \<Rightarrow> SProc (r, fr, t, u) (Some p)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   738
     | _  \<Rightarrow> Unknown          )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   739
| "init_obj2sobj (IPC i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   740
     case (init_ipc_type i) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   741
       Some t \<Rightarrow> SIPC t (Some i)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   742
     | _      \<Rightarrow> Unknown      )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   743
dcde836219bc add thy files
chunhan
parents:
diff changeset
   744
inductive_set tainted_s :: "t_sobject set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   745
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   746
  ts_init: "obj \<in> seeds \<Longrightarrow> init_obj2sobj obj \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   747
| ts_exec1: "\<lbrakk>SFile (t, sd) sf \<in> tainted_s; SProc (r, fr, pt, u) sp \<in> all_sobjs; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   748
| ts_exec2: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; SFile (t, sd) sf \<in> all_sobjs; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   749
| ts_cfd:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; SFile (t, sd) sf \<in> all_sobjs; default_fd_create_type r = NormalFile_type t'; (r, File_type t, WRITE) \<in> compatible; (r, File_type t', CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t', sd) None \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   750
| ts_cfd': "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; SFile (t, sd) sf \<in> all_sobjs; default_fd_create_type r = InheritParent_file_type; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) None \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   751
| ts_cipc: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; (r, IPC_type (default_ipc_create_type r), CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC (default_ipc_create_type r) None \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   752
| ts_read: "\<lbrakk>SFile (t, sd) sf \<in> tainted_s; SProc (r, fr, pt, u) sp \<in> all_sobjs; (r, File_type t, READ) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (r, fr, pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   753
| ts_write: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; SFile (t, sd) sf \<in> all_sobjs; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) sf \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   754
| ts_recv: "\<lbrakk>SIPC t si \<in> tainted_s; SProc (r, fr, pt, u) sp \<in> all_sobjs; (r, IPC_type t, RECEIVE) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (r, fr, pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   755
| ts_send: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; SIPC t si \<in> all_sobjs; (r, IPC_type t, SEND) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC t si \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   756
| ts_crole: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; r' \<in> comproles r\<rbrakk> \<Longrightarrow> SProc (r', fr, pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   757
| ts_chown: "\<lbrakk>SProc (r, fr, t, u') sp \<in> tainted_s; u \<in> init_users; chown_role_aux r fr u = Some nr; (r, Proc_type t, CHANGE_OWNER) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (nr, fr, chown_type_aux r nr t, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   758
| ts_clone: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s; (r, Proc_type pt, CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (r, fr, clone_type_aux r pt, u) sp \<in> tainted_s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   759
dcde836219bc add thy files
chunhan
parents:
diff changeset
   760
(*** mapping function from dynamic 2 statical ****)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   761
dcde836219bc add thy files
chunhan
parents:
diff changeset
   762
fun source_dir:: "t_state \<Rightarrow> t_file \<Rightarrow> t_file option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   763
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   764
   "source_dir s []     = (if ([] \<in> init_files \<and> \<not> (deleted (File []) s)) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   765
                           then Some [] 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   766
                           else None
dcde836219bc add thy files
chunhan
parents:
diff changeset
   767
                          )"                                 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   768
 | "source_dir s (f#pf) = (if ((f#pf) \<in> init_files \<and> \<not> (deleted (File (f#pf)) s)) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   769
                           then Some (f#pf)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   770
                           else source_dir s pf
dcde836219bc add thy files
chunhan
parents:
diff changeset
   771
                          )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   772
dcde836219bc add thy files
chunhan
parents:
diff changeset
   773
(* cf2sfile's properities should all be under condition: f is not deleted in \<tau>*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   774
fun cf2sfile:: "t_state \<Rightarrow> t_file \<Rightarrow> t_sfile option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   775
where 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   776
  "cf2sfile s f = (case (etype_of_file s f, source_dir s f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   777
                     (Some t, Some sd) \<Rightarrow> Some (t, sd)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   778
                   | _                 \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   779
dcde836219bc add thy files
chunhan
parents:
diff changeset
   780
fun cp2sproc:: "t_state \<Rightarrow> t_process \<Rightarrow> t_sprocess option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   781
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   782
  "cp2sproc s p = (case (currentrole s p, proc_forcedrole s p, type_of_process s p, owner s p) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   783
                     (Some r, Some  fr, Some t, Some u) \<Rightarrow> Some (r, fr, t, u)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   784
                   | _                                  \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   785
dcde836219bc add thy files
chunhan
parents:
diff changeset
   786
fun ci2sipc:: "t_state \<Rightarrow> t_ipc \<Rightarrow> t_sipc option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   787
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   788
  "ci2sipc s i = (type_of_ipc s i)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   789
dcde836219bc add thy files
chunhan
parents:
diff changeset
   790
(*** in statical view, clone event is process to try different runs(different sprocess:role/type...),
dcde836219bc add thy files
chunhan
parents:
diff changeset
   791
so statically these sprocesses should have the same source: the process in the initial state *********)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   792
fun source_proc :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   793
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   794
  "source_proc [] p = (if (p \<in> init_processes) then Some p else None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   795
| "source_proc (Clone p p' # s) p'' = (if (p'' = p') then source_proc s p else source_proc s p'')"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   796
| "source_proc (e # s) p = source_proc s p"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   797
dcde836219bc add thy files
chunhan
parents:
diff changeset
   798
fun obj2sobj :: "t_state \<Rightarrow> t_object \<Rightarrow> t_sobject"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   799
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   800
  "obj2sobj s (File f) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   801
     case (cf2sfile s f) of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   802
       Some sf \<Rightarrow> (if (f \<in> init_files \<and> (\<not> deleted (File f) s)) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   803
                   then SFile sf (Some f)  
dcde836219bc add thy files
chunhan
parents:
diff changeset
   804
                   else SFile sf None)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   805
     | _       \<Rightarrow> Unknown )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   806
| "obj2sobj s (Proc p) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   807
     case (cp2sproc s p) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   808
       Some sp \<Rightarrow> SProc sp (source_proc s p)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   809
     | _       \<Rightarrow> Unknown )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   810
| "obj2sobj s (IPC i) = (
dcde836219bc add thy files
chunhan
parents:
diff changeset
   811
     case (ci2sipc s i) of 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   812
       Some si \<Rightarrow> (if (i \<in> init_ipcs \<and> (\<not> deleted (IPC i) s)) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   813
                   then SIPC si (Some i) 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   814
                   else SIPC si None)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   815
     | _       \<Rightarrow> Unknown )"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   816
dcde836219bc add thy files
chunhan
parents:
diff changeset
   817
fun role_of_sproc :: "t_sprocess \<Rightarrow> t_normal_role"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   818
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   819
  "role_of_sproc (r, fr, pt, u) = r"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   820
dcde836219bc add thy files
chunhan
parents:
diff changeset
   821
fun source_of_sobj :: "t_sobject \<Rightarrow> t_object option"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   822
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   823
  "source_of_sobj (SFile sf tag) = (case tag of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   824
                                        Some f \<Rightarrow> Some (File f)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   825
                                      | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   826
| "source_of_sobj (SProc sp tag) = (case tag of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   827
                                        Some p \<Rightarrow> Some (Proc p)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   828
                                      | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   829
| "source_of_sobj (SIPC  si tag) = (case tag of
dcde836219bc add thy files
chunhan
parents:
diff changeset
   830
                                        Some i \<Rightarrow> Some (IPC i)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   831
                                      | _      \<Rightarrow> None)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   832
| "source_of_sobj Unknown        = None"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   833
dcde836219bc add thy files
chunhan
parents:
diff changeset
   834
definition taintable_s :: "t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   835
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   836
  "taintable_s obj \<equiv> \<exists>sobj. sobj \<in> tainted_s \<and> source_of_sobj sobj = Some obj"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   837
dcde836219bc add thy files
chunhan
parents:
diff changeset
   838
(*
dcde836219bc add thy files
chunhan
parents:
diff changeset
   839
definition file_deletable_s:: "t_file \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   840
where 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   841
  "file_deletable_s f \<equiv> \<forall> t sd srf. (SFile (t,sd) srf \<in> all_sobjs \<and> f \<preceq> sd \<longrightarrow> (\<exists> sp srp. SProc sp srp \<in> all_sobjs \<and> (role_of_sproc sp, File_type t, DELETE) \<in> compatible))"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   842
*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   843
(*
dcde836219bc add thy files
chunhan
parents:
diff changeset
   844
definition file_deletable_s:: "t_file \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   845
where 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   846
  "file_deletable_s sd \<equiv> \<forall> f. (f \<in> init_files \<and> sd \<preceq> f \<longrightarrow> (\<exists> t sp srp. SProc sp srp \<in> all_sobjs \<and> etype_of_file [] f = Some t \<and> (role_of_sproc sp, File_type t, DELETE) \<in> compatible))"*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   847
dcde836219bc add thy files
chunhan
parents:
diff changeset
   848
definition file_deletable_s:: "t_file \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   849
where 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   850
  "file_deletable_s f \<equiv> \<exists> t sp srp. SProc sp srp \<in> all_sobjs \<and> etype_of_file [] f = Some t \<and> (role_of_sproc sp, File_type t, DELETE) \<in> compatible"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   851
dcde836219bc add thy files
chunhan
parents:
diff changeset
   852
definition proc_deletable_s:: "t_process \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   853
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   854
  "proc_deletable_s p \<equiv> \<exists> r fr pt u sp' srp'. SProc (r,fr,pt,u) (Some p) \<in> all_sobjs \<and> SProc sp' srp' \<in> all_sobjs \<and> (role_of_sproc sp', Proc_type pt, DELETE) \<in> compatible"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   855
dcde836219bc add thy files
chunhan
parents:
diff changeset
   856
definition ipc_deletable_s:: "t_ipc \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   857
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   858
  "ipc_deletable_s i \<equiv> \<exists> t sp srp. SProc sp srp \<in> all_sobjs \<and> type_of_ipc [] i = Some t \<and> (role_of_sproc sp, IPC_type t, DELETE) \<in> compatible"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   859
dcde836219bc add thy files
chunhan
parents:
diff changeset
   860
fun deletable_s :: "t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   861
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   862
  "deletable_s (Proc p) = (p \<in> init_processes \<and> proc_deletable_s p)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   863
| "deletable_s (File f) = (f \<in> init_files     \<and> file_deletable_s f)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   864
| "deletable_s (IPC  i) = (i \<in> init_ipcs      \<and> ipc_deletable_s  i)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   865
dcde836219bc add thy files
chunhan
parents:
diff changeset
   866
definition undeletable_s:: "t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   867
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   868
  "undeletable_s obj \<equiv> exists [] obj \<and> \<not> deletable_s obj"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   869
dcde836219bc add thy files
chunhan
parents:
diff changeset
   870
end
dcde836219bc add thy files
chunhan
parents:
diff changeset
   871
dcde836219bc add thy files
chunhan
parents:
diff changeset
   872
locale tainting_s_sound = tainting_s_complete +
dcde836219bc add thy files
chunhan
parents:
diff changeset
   873
dcde836219bc add thy files
chunhan
parents:
diff changeset
   874
assumes
dcde836219bc add thy files
chunhan
parents:
diff changeset
   875
  clone_type_unchange: "\<And> r. default_process_create_type r = InheritParent_proc_type"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   876
(* this is for statically clone do not change anything ! ! so that, there're no rule for 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   877
clone in all_sobjs and tainted_s *)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   878
and clone_no_limit: "\<And> r t. (r, Proc_type t, CREATE) \<in> compatible"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   879
dcde836219bc add thy files
chunhan
parents:
diff changeset
   880
begin
dcde836219bc add thy files
chunhan
parents:
diff changeset
   881
dcde836219bc add thy files
chunhan
parents:
diff changeset
   882
(* the all_sobjs': the soundness view of all_sobjs, just remove the clone case, cause
dcde836219bc add thy files
chunhan
parents:
diff changeset
   883
in this locale, clone doesn't change any information of such a sprocess*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   884
inductive_set all_sobjs' :: "t_sobject set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   885
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   886
  af'_init:  "\<lbrakk>f \<in> init_files; etype_aux init_file_type_aux f = Some t\<rbrakk> \<Longrightarrow> SFile (t, f) (Some f) \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   887
| af'_cfd:   "\<lbrakk>SFile (t, sd) sf \<in> all_sobjs'; SProc (r, fr, pt, u) sp \<in> all_sobjs'; default_fd_create_type r = NormalFile_type t'; (r, File_type t, WRITE) \<in> compatible; (r, File_type t', CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t', sd) None \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   888
| af'_cfd':  "\<lbrakk>SFile (t, sd) sf \<in> all_sobjs'; SProc (r, fr, pt, u) sp \<in> all_sobjs'; default_fd_create_type r = InheritParent_file_type; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) None \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   889
dcde836219bc add thy files
chunhan
parents:
diff changeset
   890
| ai'_init:  "init_ipc_type i = Some t \<Longrightarrow> SIPC t (Some i) \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   891
| ai'_cipc:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> all_sobjs'; (r, IPC_type (default_ipc_create_type r), CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC (default_ipc_create_type r) None \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   892
dcde836219bc add thy files
chunhan
parents:
diff changeset
   893
| ap'_init:  "\<lbrakk>init_currentrole p = Some r; init_proc_forcedrole p = Some fr; init_process_type p = Some t; init_owner p = Some u\<rbrakk> \<Longrightarrow> SProc (r, fr, t, u) (Some p) \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   894
| ap'_crole: "\<lbrakk>SProc (r, fr, t, u) sp \<in> all_sobjs'; r' \<in> comproles r\<rbrakk> \<Longrightarrow> SProc (r', fr, t, u) sp \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   895
| ap'_chown: "\<lbrakk>SProc (r, fr, t, u') sp \<in> all_sobjs'; u \<in> init_users; chown_role_aux r fr u = Some nr; (r, Proc_type t, CHANGE_OWNER) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (nr, fr, chown_type_aux r nr t, u) sp \<in> all_sobjs'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   896
| ap'_exec:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> all_sobjs'; SFile (t, sd) sf \<in> all_sobjs'; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> all_sobjs'" 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   897
dcde836219bc add thy files
chunhan
parents:
diff changeset
   898
(* the tainted_s': the soundness view of all_sobjs, just remove the clone case, cause
dcde836219bc add thy files
chunhan
parents:
diff changeset
   899
in this locale, clone doesn't change any information of such a sprocess*)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   900
inductive_set tainted_s' :: "t_sobject set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   901
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   902
  ts'_init: "obj \<in> seeds \<Longrightarrow> init_obj2sobj obj \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   903
| ts'_exec1: "\<lbrakk>SFile (t, sd) sf \<in> tainted_s'; SProc (r, fr, pt, u) sp \<in> all_sobjs'; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   904
| ts'_exec2: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; SFile (t, sd) sf \<in> all_sobjs'; (r, File_type t, EXECUTE) \<in> compatible; exec_role_aux r sd u = Some r'; erole_functor init_file_forcedrole InheritUpMixed sd = Some fr'\<rbrakk> \<Longrightarrow> SProc (r', fr', exec_type_aux r pt, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   905
| ts'_cfd:  "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; SFile (t, sd) sf \<in> all_sobjs'; default_fd_create_type r = NormalFile_type t'; (r, File_type t, WRITE) \<in> compatible; (r, File_type t', CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t', sd) None \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   906
| ts'_cfd': "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; SFile (t, sd) sf \<in> all_sobjs'; default_fd_create_type r = InheritParent_file_type; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) None \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   907
| ts'_cipc: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; (r, IPC_type (default_ipc_create_type r), CREATE) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC (default_ipc_create_type r) None \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   908
| ts'_read: "\<lbrakk>SFile (t, sd) sf \<in> tainted_s'; SProc (r, fr, pt, u) sp \<in> all_sobjs'; (r, File_type t, READ) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (r, fr, pt, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   909
| ts'_write: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; SFile (t, sd) sf \<in> all_sobjs'; (r, File_type t, WRITE) \<in> compatible\<rbrakk> \<Longrightarrow> SFile (t, sd) sf \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   910
| ts'_recv: "\<lbrakk>SIPC t si \<in> tainted_s'; SProc (r, fr, pt, u) sp \<in> all_sobjs'; (r, IPC_type t, RECEIVE) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (r, fr, pt, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   911
| ts'_send: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; SIPC t si \<in> all_sobjs'; (r, IPC_type t, SEND) \<in> compatible\<rbrakk> \<Longrightarrow> SIPC t si \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   912
| ts'_crole: "\<lbrakk>SProc (r, fr, pt, u) sp \<in> tainted_s'; r' \<in> comproles r\<rbrakk> \<Longrightarrow> SProc (r', fr, pt, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   913
| ts'_chown: "\<lbrakk>SProc (r, fr, t, u') sp \<in> tainted_s'; u \<in> init_users; chown_role_aux r fr u = Some nr; (r, Proc_type t, CHANGE_OWNER) \<in> compatible\<rbrakk> \<Longrightarrow> SProc (nr, fr, chown_type_aux r nr t, u) sp \<in> tainted_s'"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   914
dcde836219bc add thy files
chunhan
parents:
diff changeset
   915
fun sobj_source_eq_obj :: "t_sobject \<Rightarrow> t_object \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   916
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   917
  "sobj_source_eq_obj (SFile sf None)      (File f) = True"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   918
| "sobj_source_eq_obj (SFile sf (Some f')) (File f) = (f' = f)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   919
| "sobj_source_eq_obj (SProc sp None)      (Proc p) = True"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   920
| "sobj_source_eq_obj (SProc sp (Some p')) (Proc p) = (p' = p)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   921
| "sobj_source_eq_obj (SIPC  si None)      (IPC  i) = True"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   922
| "sobj_source_eq_obj (SIPC  si (Some i')) (IPC  i) = (i' = i)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   923
| "sobj_source_eq_obj _                    _        = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   924
dcde836219bc add thy files
chunhan
parents:
diff changeset
   925
fun not_both_sproc:: "t_sobject \<Rightarrow> t_sobject \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   926
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   927
  "not_both_sproc (SProc sp srp) (SProc sp' srp') = False"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   928
| "not_both_sproc _              _                = True"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   929
dcde836219bc add thy files
chunhan
parents:
diff changeset
   930
(*** definitions for init processes statical informations reservation ***)
dcde836219bc add thy files
chunhan
parents:
diff changeset
   931
dcde836219bc add thy files
chunhan
parents:
diff changeset
   932
definition initp_intact :: "t_state => bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   933
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   934
  "initp_intact s \<equiv> \<forall> p. p \<in> init_processes --> p \<in> current_procs s \<and> obj2sobj s (Proc p) = init_obj2sobj (Proc p)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   935
dcde836219bc add thy files
chunhan
parents:
diff changeset
   936
definition initp_alter :: "t_state \<Rightarrow> t_process \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   937
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   938
 "initp_alter s p \<equiv> \<exists> p'. p' \<in> current_procs s \<and> obj2sobj s (Proc p') = init_obj2sobj (Proc p)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   939
dcde836219bc add thy files
chunhan
parents:
diff changeset
   940
definition initp_intact_butp :: "t_state \<Rightarrow> t_process \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   941
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   942
  "initp_intact_butp s proc \<equiv>  (\<forall> p. p \<in> init_processes \<and> p \<noteq> proc \<longrightarrow> p \<in> current_procs s \<and> obj2sobj s (Proc p) = init_obj2sobj (Proc p)) \<and> initp_alter s proc"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   943
dcde836219bc add thy files
chunhan
parents:
diff changeset
   944
fun initp_intact_but :: "t_state \<Rightarrow> t_sobject \<Rightarrow> bool"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   945
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   946
  "initp_intact_but s (SProc sp (Some p)) = initp_intact_butp s p"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   947
| "initp_intact_but s _                   = initp_intact s"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   948
6
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   949
(*** how to generating new valid pathname for examples of new_proc, new_ipc and new_file as CreateFile ***)
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   950
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   951
definition next_nat :: "nat set \<Rightarrow> nat"
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   952
where
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   953
  "next_nat ps = (Max ps) + 1"
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   954
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   955
definition new_proc :: "t_state \<Rightarrow> t_process"
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   956
where 
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   957
  "new_proc \<tau> = next_nat (current_procs \<tau>)"
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   958
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   959
definition new_ipc :: "t_state \<Rightarrow> t_ipc"
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   960
where
4294abb1f38c update scripts with no new_* in admissable-check
chunhan
parents: 1
diff changeset
   961
  "new_ipc \<tau> = next_nat (current_ipcs \<tau>)"
1
dcde836219bc add thy files
chunhan
parents:
diff changeset
   962
dcde836219bc add thy files
chunhan
parents:
diff changeset
   963
definition all_fname_under_dir:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   964
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   965
  "all_fname_under_dir d \<tau> = {fn. \<exists> f. fn # d = f \<and> f \<in> current_files \<tau>}"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   966
dcde836219bc add thy files
chunhan
parents:
diff changeset
   967
fun fname_all_a:: "nat \<Rightarrow> t_fname"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   968
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   969
  "fname_all_a 0 = []" |
dcde836219bc add thy files
chunhan
parents:
diff changeset
   970
  "fname_all_a (Suc n) = ''a''@(fname_all_a n)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   971
dcde836219bc add thy files
chunhan
parents:
diff changeset
   972
definition fname_length_set :: "t_fname set \<Rightarrow> nat set"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   973
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   974
  "fname_length_set fns = length`fns"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   975
dcde836219bc add thy files
chunhan
parents:
diff changeset
   976
definition next_fname:: "t_file \<Rightarrow> t_state \<Rightarrow> t_fname"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   977
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   978
  "next_fname pf \<tau> = fname_all_a ((Max (fname_length_set (all_fname_under_dir pf \<tau>))) + 1)"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   979
dcde836219bc add thy files
chunhan
parents:
diff changeset
   980
definition new_childf:: "t_file \<Rightarrow> t_state \<Rightarrow> t_file"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   981
where
dcde836219bc add thy files
chunhan
parents:
diff changeset
   982
  "new_childf pf \<tau> = next_fname pf \<tau> # pf"
dcde836219bc add thy files
chunhan
parents:
diff changeset
   983
dcde836219bc add thy files
chunhan
parents:
diff changeset
   984
end 
dcde836219bc add thy files
chunhan
parents:
diff changeset
   985
dcde836219bc add thy files
chunhan
parents:
diff changeset
   986
end
dcde836219bc add thy files
chunhan
parents:
diff changeset
   987