no_shm_selinux/Temp.thy
author chunhan
Thu, 16 Jan 2014 11:04:04 +0800
changeset 95 b7fd75d104bf
parent 93 dfde07c7cd6b
permissions -rw-r--r--
update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
chunhan
parents:
diff changeset
     1
theory Temp
chunhan
parents:
diff changeset
     2
imports Static_type OS_type_def Flask_type Flask Static
chunhan
parents:
diff changeset
     3
begin
chunhan
parents:
diff changeset
     4
chunhan
parents:
diff changeset
     5
context tainting_s
chunhan
parents:
diff changeset
     6
chunhan
parents:
diff changeset
     7
begin
chunhan
parents:
diff changeset
     8
chunhan
parents:
diff changeset
     9
definition update_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
chunhan
parents:
diff changeset
    10
where
chunhan
parents:
diff changeset
    11
  "update_ss ss so so' \<equiv> if (is_many so) then ss \<union> {so'} else (ss - {so}) \<union> {so'}"
chunhan
parents:
diff changeset
    12
chunhan
parents:
diff changeset
    13
definition add_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
chunhan
parents:
diff changeset
    14
where
chunhan
parents:
diff changeset
    15
  "add_ss ss so \<equiv> ss \<union> {so}"
chunhan
parents:
diff changeset
    16
92
d9dc04c3ea90 modify co2sobj/s2ss from object to dobject
chunhan
parents: 87
diff changeset
    17
(*
77
chunhan
parents:
diff changeset
    18
definition del_ss :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> t_static_state"
chunhan
parents:
diff changeset
    19
where
chunhan
parents:
diff changeset
    20
  "del_ss ss so \<equiv> if (is_many so) then ss else ss - {so}"
92
d9dc04c3ea90 modify co2sobj/s2ss from object to dobject
chunhan
parents: 87
diff changeset
    21
*)
d9dc04c3ea90 modify co2sobj/s2ss from object to dobject
chunhan
parents: 87
diff changeset
    22
77
chunhan
parents:
diff changeset
    23
chunhan
parents:
diff changeset
    24
(* all reachable static states(sobjects set) *)
chunhan
parents:
diff changeset
    25
inductive_set static :: "t_static_state set"
chunhan
parents:
diff changeset
    26
where
chunhan
parents:
diff changeset
    27
  s_init:    "init_static_state \<in> static"
chunhan
parents:
diff changeset
    28
| s_execve:  "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds) tagp \<in> ss; S_file sfs tagf \<in> ss;
chunhan
parents:
diff changeset
    29
               (fi,fsec,pfsec,asecs) \<in> sfs; npctxt_execve pctxt fsec = Some pctxt';
chunhan
parents:
diff changeset
    30
               grant_execve pctxt fsec pctxt'; search_check_s pctxt (fi,fsec,pfsec,asecs) True; 
chunhan
parents:
diff changeset
    31
               inherit_fds_check_s pctxt' fds'; fds' \<subseteq> fds\<rbrakk>
chunhan
parents:
diff changeset
    32
  \<Longrightarrow> (update_ss ss (S_proc (pi, pctxt, fds) tagp) 
chunhan
parents:
diff changeset
    33
                    (S_proc (pi, pctxt', fds') (tagp \<or> tagf))) \<in> static"
chunhan
parents:
diff changeset
    34
| s_clone:   "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds) tagp \<in> ss; 
chunhan
parents:
diff changeset
    35
               permission_check pctxt pctxt C_process P_fork;
chunhan
parents:
diff changeset
    36
               inherit_fds_check_s pctxt fds'; fds' \<subseteq> fds\<rbrakk>
chunhan
parents:
diff changeset
    37
  \<Longrightarrow> (add_ss ss (S_proc (Created, pctxt, fds') tagp)) \<in> static"
chunhan
parents:
diff changeset
    38
(*
chunhan
parents:
diff changeset
    39
| s_kill:    "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds) tagp \<in> ss; 
chunhan
parents:
diff changeset
    40
               S_proc (pi', pctxt', fds') tagp' \<in> ss; 
chunhan
parents:
diff changeset
    41
               permission_check pctxt pctxt' C_process P_sigkill\<rbrakk>
chunhan
parents:
diff changeset
    42
  \<Longrightarrow> (del_ss ss (S_proc (pi', pctxt', fds', shms') tagp')) \<in> static"
chunhan
parents:
diff changeset
    43
*)
chunhan
parents:
diff changeset
    44
| s_ptrace:  "\<lbrakk>ss \<in> static; S_proc sp False \<in> ss; S_proc sp' True \<in> ss; 
chunhan
parents:
diff changeset
    45
               permission_check (sextxt_of_sproc sp) (sectxt_of_sproc sp') C_process P_ptrace\<rbrakk>
chunhan
parents:
diff changeset
    46
  \<Longrightarrow> (update_ss ss (S_proc sp False) (S_proc sp True)) \<in> static"
chunhan
parents:
diff changeset
    47
| s_ptrace': "\<lbrakk>ss \<in> static; S_proc sp True \<in> ss; S_proc sp' False \<in> ss; 
chunhan
parents:
diff changeset
    48
               permission_check (sextxt_of_sproc sp) (sectxt_of_sproc sp') C_process P_ptrace\<rbrakk>
chunhan
parents:
diff changeset
    49
  \<Longrightarrow> (update_ss ss (S_proc sp' False) (S_proc sp' True)) \<in> static"
chunhan
parents:
diff changeset
    50
(*
chunhan
parents:
diff changeset
    51
| s_exit:    "\<lbrakk>ss \<in> static; S_proc sp tagp \<in> ss\<rbrakk> \<Longrightarrow> (del_ss ss (S_proc sp tagp)) \<in> static"
chunhan
parents:
diff changeset
    52
*)
chunhan
parents:
diff changeset
    53
| s_open:    "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds) tagp \<in> ss; S_file sfs tagf \<in> ss; sf \<in> sfs;
chunhan
parents:
diff changeset
    54
              search_check_s pctxt sf True; \<not> is_creat_excl_flag flags; 
chunhan
parents:
diff changeset
    55
              oflags_check flags pctxt (sectxt_of_sfile sf); permission_check pctxt pctxt C_fd P_setattr\<rbrakk>
chunhan
parents:
diff changeset
    56
  \<Longrightarrow> (update_ss ss (S_proc (pi, pctxt, fds) tagp)
chunhan
parents:
diff changeset
    57
                    (S_proc (pi, pctxt, fds \<union> {(pctxt,flags,sf)}) tagp)) \<in> static"
chunhan
parents:
diff changeset
    58
| s_open':   "\<lbrakk>ss \<in> static; S_proc (pi, pctxt, fds) tagp \<in> ss; is_creat_excl_flag flags;
chunhan
parents:
diff changeset
    59
               S_dir (pfi,fsec,pfsec,asecs) \<in> ss; search_check_s pctxt (pfi,fsec,pfsec,asecs) False; 
chunhan
parents:
diff changeset
    60
               nfsec = nfctxt_create pctxt fsec C_file; oflags_check flags pctxt nfsec;
chunhan
parents:
diff changeset
    61
               permission_check pctxt fsec C_dir P_add_rename; permission_check pctxt pctxt C_fd P_setattr\<rbrakk>
chunhan
parents:
diff changeset
    62
  \<Longrightarrow> (update_ss (add_ss ss (S_file {(Created, nfsec, Some fsec, asecs \<union> {fsec})} tagp))
chunhan
parents:
diff changeset
    63
         (S_proc (pi, pctxt, fds) tagp)
chunhan
parents:
diff changeset
    64
         (S_proc (pi, pctxt, fds \<union> {(pctxt, flags, (Created, nfsec, Some fsec, asecs \<union> {fsec}))}) tagp)
chunhan
parents:
diff changeset
    65
      ) \<in> static"
chunhan
parents:
diff changeset
    66
| S_readf:   "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) False \<in> ss; (fdctxt,flags,sf) \<in> fds; 
chunhan
parents:
diff changeset
    67
               permission_check pctxt fdctxt C_fd P_setattr; S_file sfs True \<in> ss; sf \<in> sfs;
chunhan
parents:
diff changeset
    68
               permission_check pctxt (sectxt_of_sfile sf) C_file P_read; is_read_flag flags\<rbrakk>
chunhan
parents:
diff changeset
    69
  \<Longrightarrow> (update_ss ss (S_proc (pi, pctxt,fds) False) (S_proc (pi, pctxt, fds) True)) \<in> static"
chunhan
parents:
diff changeset
    70
| S_writef:  "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) True \<in> ss; (fdctxt,flags,sf) \<in> fds; 
chunhan
parents:
diff changeset
    71
               permission_check pctxt fdctxt C_fd P_setattr; sf \<in> sfs; S_file sfs False \<in> ss; 
chunhan
parents:
diff changeset
    72
               permission_check pctxt (sectxt_of_sfile sf) C_file P_write; is_write_flag flags\<rbrakk>
chunhan
parents:
diff changeset
    73
  \<Longrightarrow> (update_ss ss (S_file sfs False) (S_file sfs True)) \<in> static"
chunhan
parents:
diff changeset
    74
(*
chunhan
parents:
diff changeset
    75
| S_unlink:  "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; S_file sfs tagf \<in> ss;  
chunhan
parents:
diff changeset
    76
               (Init f,fsec,Some pfsec,asecs) \<in> sfs; 
chunhan
parents:
diff changeset
    77
               search_check_s pctxt (Init f,fsec,Some pfsec,asecs) True; 
chunhan
parents:
diff changeset
    78
               permission_check pctxt fsec C_file P_unlink; 
chunhan
parents:
diff changeset
    79
               permission_check pctxt pfsec C_dir P_remove_name\<rbrakk>
chunhan
parents:
diff changeset
    80
  \<Longrightarrow> ((ss - {S_file sfs tagf}) \<union> {S_file (sfs - {(Init f,fsec,Some pfsec,asecs)}) tagf}) \<in> static"
chunhan
parents:
diff changeset
    81
| S_rmdir:   "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds,shms) tagp \<in> ss; 
chunhan
parents:
diff changeset
    82
               S_dir (fi,fsec,Some pfsec,asecs) \<in> ss;  
chunhan
parents:
diff changeset
    83
               search_check_s pctxt (fi,fsec,Some pfsec,asecs) False; 
chunhan
parents:
diff changeset
    84
               permission_check pctxt fsec C_dir P_rmdir;
chunhan
parents:
diff changeset
    85
               permission_check pctxt pfsec C_dir P_remove_name\<rbrakk>
chunhan
parents:
diff changeset
    86
  \<Longrightarrow> (del_ss ss (S_dir (fi,fsec,Some pfsec,asecs))) \<in> static"
chunhan
parents:
diff changeset
    87
*)
chunhan
parents:
diff changeset
    88
| S_mkdir:   "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_dir (fi,fsec,pfsec,asecs) \<in> ss;  
chunhan
parents:
diff changeset
    89
               search_check_s pctxt (fi,fsec,pfsec,asecs) False; 
chunhan
parents:
diff changeset
    90
               permission_check pctxt (nfctxt_create pctxt fsec C_dir) C_dir P_create;
chunhan
parents:
diff changeset
    91
               permission_check pctxt fsec C_dir P_add_name\<rbrakk>
chunhan
parents:
diff changeset
    92
  \<Longrightarrow> (add_ss ss (S_dir (Created,nfctxt_create pctxt fsec C_dir,Some fsec,asecs \<union> {fsec}))) \<in> static"
chunhan
parents:
diff changeset
    93
| s_link:    "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_dir (pfi,pfsec,ppfsec,asecs) \<in> ss;
chunhan
parents:
diff changeset
    94
               S_file sfs tagf \<in> ss; sf \<in> sfs; nfsec = nfctxt_create pctxt pfsec C_file;  
chunhan
parents:
diff changeset
    95
               search_check_s pctxt (pfi,pfsec,ppfsec,asecs) False; search_check_s pctxt sf True;
chunhan
parents:
diff changeset
    96
               permission_check pctxt (sectxt_of_sfile sf) C_file P_link; 
chunhan
parents:
diff changeset
    97
               permission_check pctxt pfsec C_dir P_add_name\<rbrakk>
chunhan
parents:
diff changeset
    98
  \<Longrightarrow> (update_ss ss (S_file sfs tagf) 
chunhan
parents:
diff changeset
    99
                  (S_file (sfs \<union> {(Created,nfsec,Some pfsec, asecs \<union> {pfsec})}) tagf)) \<in> static"
chunhan
parents:
diff changeset
   100
| s_trunc:   "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) True \<in> ss; S_file sfs False \<in> ss; sf \<in> sfs; 
chunhan
parents:
diff changeset
   101
               search_check_s pctxt sf True; permission_check pctxt (sectxt_of_sfile sf) C_file P_setattr\<rbrakk>
chunhan
parents:
diff changeset
   102
  \<Longrightarrow> (update_ss ss (S_file sfs False) (S_file sfs True)) \<in> static"
chunhan
parents:
diff changeset
   103
(*
chunhan
parents:
diff changeset
   104
| s_rename:  "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_file sfs tagf \<in> ss;
chunhan
parents:
diff changeset
   105
               (sf#spf') \<in> sfs; S_dir spf tagpf \<in> ss; \<not>((sf#spf') \<preceq> (sf#spf)); 
chunhan
parents:
diff changeset
   106
               search_check_s pctxt spf False; search_check_s pctxt (sf#spf') True; 
chunhan
parents:
diff changeset
   107
               sectxt_of_sfile (sf#spf') = Some fctxt; sectxt_of_sfile spf = Some pfctxt;  
chunhan
parents:
diff changeset
   108
               permission_check pctxt fctxt C_file P_rename;
chunhan
parents:
diff changeset
   109
               permission_check pctxt pfctxt C_dir P_add_name;
chunhan
parents:
diff changeset
   110
               ss_rename ss (sf#spf') (sf#spf) ss'; 
chunhan
parents:
diff changeset
   111
               ss_rename_no_same_fname ss (sf#spf') (sf#spf)\<rbrakk>
chunhan
parents:
diff changeset
   112
              \<Longrightarrow> ss' \<in> static"
chunhan
parents:
diff changeset
   113
| s_rename': "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_dir (sf#spf') tagf \<in> ss;
chunhan
parents:
diff changeset
   114
               S_dir spf tagpf \<in> ss; \<not>((sf#spf') \<preceq> (sf#spf)); 
chunhan
parents:
diff changeset
   115
               search_check_s pctxt spf False; search_check_s pctxt (sf#spf') True; 
chunhan
parents:
diff changeset
   116
               sectxt_of_sfile (sf#spf') = Some fctxt; sectxt_of_sfile spf = Some pfctxt;  
chunhan
parents:
diff changeset
   117
               permission_check pctxt fctxt C_dir P_reparent;
chunhan
parents:
diff changeset
   118
               permission_check pctxt pfctxt C_dir P_add_name;
chunhan
parents:
diff changeset
   119
               ss_rename ss (sf#spf') (sf#spf) ss'; 
chunhan
parents:
diff changeset
   120
               ss_rename_no_same_fname ss (sf#spf') (sf#spf)\<rbrakk>
chunhan
parents:
diff changeset
   121
              \<Longrightarrow> ss' \<in> static"
chunhan
parents:
diff changeset
   122
*)
chunhan
parents:
diff changeset
   123
| s_createq: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; 
chunhan
parents:
diff changeset
   124
               permission_check pctxt pctxt C_msgq P_associate;
chunhan
parents:
diff changeset
   125
               permission_check pctxt pctxt C_msgq P_create\<rbrakk>
chunhan
parents:
diff changeset
   126
  \<Longrightarrow> (add_ss ss (S_msgq (Created,pctxt,[]))) \<in> static" 
chunhan
parents:
diff changeset
   127
| s_sendmsg: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_msgq (qi,qctxt,sms) \<in> ss;
chunhan
parents:
diff changeset
   128
               permission_check pctxt qctxt C_msgq P_enqueue;
chunhan
parents:
diff changeset
   129
               permission_check pctxt qctxt C_msgq P_write; 
87
8d18cfc845dd remove init message queue
chunhan
parents: 77
diff changeset
   130
               permission_check pctxt pctxt C_msg  P_create; length sms < max_queue\<rbrakk>
77
chunhan
parents:
diff changeset
   131
  \<Longrightarrow> (update_ss ss (S_msgq (qi,qctxt,sms)) 
chunhan
parents:
diff changeset
   132
                    (S_msgq (qi,qctxt,sms @ [(Created, pctxt, tagp)]))) \<in> static"
chunhan
parents:
diff changeset
   133
| s_recvmsg: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; 
chunhan
parents:
diff changeset
   134
               S_msgq (qi,qctxt,(mi,mctxt,tagm)#sms) \<in> ss;
chunhan
parents:
diff changeset
   135
               permission_check pctxt qctxt C_msgq P_read; 
chunhan
parents:
diff changeset
   136
               permission_check pctxt mctxt C_msg  P_receive\<rbrakk>
chunhan
parents:
diff changeset
   137
  \<Longrightarrow> (update_ss (update_ss ss (S_proc (pi,pctxt,fds) tagp) (S_proc (pi, pctxt, fds) (tagp \<or> tagm))) 
chunhan
parents:
diff changeset
   138
                 (S_msgq (qi, qctxt, (mi, mctxt, tagm)#sms))
chunhan
parents:
diff changeset
   139
                 (S_msgq (qi, qctxt, sms))) \<in> static"
chunhan
parents:
diff changeset
   140
(*
chunhan
parents:
diff changeset
   141
| s_removeq: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_msgq (qi,qctxt,sms) \<in> ss;
chunhan
parents:
diff changeset
   142
               permission_check pctxt qctxt C_msgq P_destroy\<rbrakk>
chunhan
parents:
diff changeset
   143
  \<Longrightarrow> (del_ss ss (S_msgq (qi,qctxt,sms))) \<in> static"
chunhan
parents:
diff changeset
   144
| s_createh: "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss;
chunhan
parents:
diff changeset
   145
               permission_check pctxt pctxt C_shm P_associate; 
chunhan
parents:
diff changeset
   146
               permission_check pctxt pctxt C_shm P_create\<rbrakk>
chunhan
parents:
diff changeset
   147
   \<Longrightarrow> (add_ss ss (S_shm (Created, pctxt))) \<in> static"
chunhan
parents:
diff changeset
   148
| s_attach:  "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_shm (hi,hctxt) \<in> ss;
chunhan
parents:
diff changeset
   149
               if flag = SHM_RDONLY then permission_check pctxt hctxt C_shm P_read
chunhan
parents:
diff changeset
   150
               else (permission_check pctxt hctxt C_shm P_read \<and>
chunhan
parents:
diff changeset
   151
                     permission_check pctxt hctxt C_shm P_write)\<rbrakk>
chunhan
parents:
diff changeset
   152
   \<Longrightarrow> (update_ss ss (S_proc (pi,pctxt,fds) tagp)
chunhan
parents:
diff changeset
   153
                    (S_proc (pi,pctxt,fds,shms \<union> {((hi,hctxt),flag)}) tagp)) \<in> static"
chunhan
parents:
diff changeset
   154
| s_detach:  "\<lbrakk>ss \<in> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_shm sh \<in> ss;
chunhan
parents:
diff changeset
   155
               (sh,flag) \<in> shms; \<not> is_many_sshm sh\<rbrakk>
chunhan
parents:
diff changeset
   156
   \<Longrightarrow> (update_ss ss (S_proc (pi,pctxt,fds) tagp)
chunhan
parents:
diff changeset
   157
                    (S_proc (pi,pctxt,fds,shms - {(sh,flag)}) tagp)) \<in> static"
chunhan
parents:
diff changeset
   158
| s_deleteh: "\<lbrakk>ss \<notin> static; S_proc (pi,pctxt,fds) tagp \<in> ss; S_shm (hi,hctxt) \<in> ss;
chunhan
parents:
diff changeset
   159
               permission_check pctxt hctxt C_shm P_destroy; \<not> is_many_sshm sh\<rbrakk>
chunhan
parents:
diff changeset
   160
   \<Longrightarrow> (remove_sproc_sshm (del_ss ss (S_shm (hi,hctxt))) (hi,hctxt)) \<in> static"
chunhan
parents:
diff changeset
   161
*)
chunhan
parents:
diff changeset
   162
chunhan
parents:
diff changeset
   163
fun tainted_s :: "t_static_state \<Rightarrow> t_sobject \<Rightarrow> bool"
chunhan
parents:
diff changeset
   164
where
chunhan
parents:
diff changeset
   165
  "tainted_s ss (S_proc sp  tag) = (S_proc sp tag  \<in> ss \<and> tag = True)"
chunhan
parents:
diff changeset
   166
| "tainted_s ss (S_file sfs tag) = (S_file sfs tag \<in> ss \<and> tag = True)"
chunhan
parents:
diff changeset
   167
(*
chunhan
parents:
diff changeset
   168
| "tainted_s ss (S_msg  (qi, sec, sms)  (mi, secm, tag)) = 
chunhan
parents:
diff changeset
   169
     (S_msgq (qi, sec, sms) \<in> ss \<and> (mi,secm,tag) \<in> set sms \<and> tag = True)"
chunhan
parents:
diff changeset
   170
*)
chunhan
parents:
diff changeset
   171
| "tainted_s ss _ = False"
chunhan
parents:
diff changeset
   172
chunhan
parents:
diff changeset
   173
(*
chunhan
parents:
diff changeset
   174
fun tainted_s :: "t_object \<Rightarrow> t_static_state \<Rightarrow> bool"
chunhan
parents:
diff changeset
   175
where 
chunhan
parents:
diff changeset
   176
  "tainted_s (O_proc p)  ss = (\<exists> sp. S_proc sp True \<in> ss \<and> sproc_related p sp)"
chunhan
parents:
diff changeset
   177
| "tainted_s (O_file f)  ss = (\<exists> sfs sf. S_file sfs True \<in> ss \<and> sf \<in> sfs \<and> sfile_related f sf)"
chunhan
parents:
diff changeset
   178
| "tainted_s (O_msg q m) ss = (\<exists> sq. S_msgq sq \<in> ss \<and> smsgq_smsg_relatainted q m sq)"
chunhan
parents:
diff changeset
   179
| "tainted_s _           ss = False"
chunhan
parents:
diff changeset
   180
*)
chunhan
parents:
diff changeset
   181
chunhan
parents:
diff changeset
   182
definition taintable_s :: "t_object \<Rightarrow> bool"
chunhan
parents:
diff changeset
   183
where
chunhan
parents:
diff changeset
   184
  "taintable_s obj \<equiv> \<exists> ss \<in> static. \<exists> sobj. tainted_s ss sobj \<and> init_obj_related sobj obj"
chunhan
parents:
diff changeset
   185
chunhan
parents:
diff changeset
   186
(* this definition is wrong, cause process can exited from static-world 
chunhan
parents:
diff changeset
   187
definition deletable_s :: "t_object \<Rightarrow> bool"
chunhan
parents:
diff changeset
   188
where
chunhan
parents:
diff changeset
   189
  "deletable_s obj \<equiv> init_alive obj \<and> (\<exists> ss \<in> static. \<forall> sobj \<in> ss. \<not> init_obj_related sobj obj)"
chunhan
parents:
diff changeset
   190
*)
chunhan
parents:
diff changeset
   191
chunhan
parents:
diff changeset
   192
lemma ss_init_sp_unique_initstate:
chunhan
parents:
diff changeset
   193
  "\<lbrakk>S_proc (Init p, pctxt, fds) tagp \<in> init_static_state;
chunhan
parents:
diff changeset
   194
    S_proc (Init p, pctxt', fds') tagp' \<in> init_static_state\<rbrakk>
chunhan
parents:
diff changeset
   195
   \<Longrightarrow> pctxt' = pctxt \<and> fds' = fds \<and> tagp' = tagp"
chunhan
parents:
diff changeset
   196
apply (simp add:init_static_state_def)
chunhan
parents:
diff changeset
   197
apply (erule exE|erule conjE)+
chunhan
parents:
diff changeset
   198
apply (case_tac obj, case_tac [!] obja)
chunhan
parents:
diff changeset
   199
apply (auto simp:init_cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   200
done
chunhan
parents:
diff changeset
   201
chunhan
parents:
diff changeset
   202
(*
chunhan
parents:
diff changeset
   203
lemma ss_init_sp_unique:
chunhan
parents:
diff changeset
   204
  "ss \<in> static \<Longrightarrow> \<forall> p pctxt fds tagp pctxt' fds' tagp'. S_proc (Init p, pctxt, fds) tagp \<in> ss 
chunhan
parents:
diff changeset
   205
      \<and> S_proc (Init p, pctxt', fds') tagp' \<in> ss \<longrightarrow> pctxt' = pctxt \<and> fds' = fds \<and> tagp' = tagp"
chunhan
parents:
diff changeset
   206
apply (erule static.induct)
chunhan
parents:
diff changeset
   207
apply (rule allI|rule impI|erule conjE)+
chunhan
parents:
diff changeset
   208
apply (erule ss_init_sp_unique_initstate, simp)
chunhan
parents:
diff changeset
   209
sorry
chunhan
parents:
diff changeset
   210
chunhan
parents:
diff changeset
   211
lemma taintable_s_imp_init_alive_aux[rule_format]:
chunhan
parents:
diff changeset
   212
  "ss \<in> static \<Longrightarrow> \<forall> sobj obj. sobj \<in> ss \<and> init_obj_related sobj obj \<longrightarrow> init_alive obj"
chunhan
parents:
diff changeset
   213
apply (erule static.induct)
chunhan
parents:
diff changeset
   214
apply (clarsimp simp:init_static_state_def)
chunhan
parents:
diff changeset
   215
apply (case_tac obj, simp)
chunhan
parents:
diff changeset
   216
sorry
chunhan
parents:
diff changeset
   217
chunhan
parents:
diff changeset
   218
lemma taintable_s_imp_init_alive:
chunhan
parents:
diff changeset
   219
  "taintable_s obj \<Longrightarrow> init_alive obj"
chunhan
parents:
diff changeset
   220
apply (clarsimp simp add:taintable_s_def)
chunhan
parents:
diff changeset
   221
thm taintable_s_imp_init_alive_aux
chunhan
parents:
diff changeset
   222
apply (erule_tac sobj = sobj in taintable_s_imp_init_alive_aux)
chunhan
parents:
diff changeset
   223
apply (case_tac sobj)
chunhan
parents:
diff changeset
   224
apply simp_all
chunhan
parents:
diff changeset
   225
apply (case_tac [!] obj)
chunhan
parents:
diff changeset
   226
apply ( simp_all)
chunhan
parents:
diff changeset
   227
apply (case_tac bool, simp, simp)
chunhan
parents:
diff changeset
   228
apply (case_tac bool, simp+)
chunhan
parents:
diff changeset
   229
done
chunhan
parents:
diff changeset
   230
*)
chunhan
parents:
diff changeset
   231
chunhan
parents:
diff changeset
   232
fun deleted_s :: "t_static_state \<Rightarrow> t_object \<Rightarrow> bool"
chunhan
parents:
diff changeset
   233
where
chunhan
parents:
diff changeset
   234
  "deleted_s ss (O_proc p) = (\<exists> pi pctxt fds tagp pctxt' fds' tagp'. S_proc (pi, pctxt, fds) tagp \<in> ss \<and>
chunhan
parents:
diff changeset
   235
     S_proc (Init p, pctxt', fds') tagp' \<in> ss \<and> pi \<noteq> Init p \<and> permission_check pctxt pctxt' C_process P_sigkill)"
chunhan
parents:
diff changeset
   236
| "deleted_s ss (O_file f) = (\<exists> pi pctxt fds tagp sfs tagf fsec pfsec asecs. S_proc (pi, pctxt, fds) tagp \<in> ss \<and>
chunhan
parents:
diff changeset
   237
     S_file sfs tagf \<in> ss \<and> (Init f, fsec, Some pfsec, asecs) \<in> sfs \<and> 
chunhan
parents:
diff changeset
   238
     search_check_s pctxt (Init f, fsec, Some pfsec, asecs) True \<and>
chunhan
parents:
diff changeset
   239
     permission_check pctxt fsec C_file P_unlink \<and>
chunhan
parents:
diff changeset
   240
     permission_check pctxt pfsec C_dir P_remove_name)"
chunhan
parents:
diff changeset
   241
| "deleted_s ss (O_dir f) = (\<exists> pi pctxt fds tagp fsec pfsec asecs. S_proc (pi, pctxt, fds) tagp \<in> ss \<and>
chunhan
parents:
diff changeset
   242
     S_dir (Init f, fsec, Some pfsec, asecs) \<in> ss \<and> search_check_s pctxt (Init f, fsec, Some pfsec, asecs) False \<and>
chunhan
parents:
diff changeset
   243
     permission_check pctxt fsec C_dir P_rmdir \<and> permission_check pctxt pfsec C_dir P_remove_name)"
chunhan
parents:
diff changeset
   244
| "deleted_s ss (O_msgq q) = (\<exists> pi pctxt fds tagp qctxt sms. S_proc (pi, pctxt, fds) tagp \<in> ss \<and>
chunhan
parents:
diff changeset
   245
     S_msgq (Init q, qctxt, sms) \<in> ss \<and> permission_check pctxt qctxt C_msgq P_destroy)"
chunhan
parents:
diff changeset
   246
chunhan
parents:
diff changeset
   247
definition deletable_s :: "t_object \<Rightarrow> bool"
chunhan
parents:
diff changeset
   248
where
chunhan
parents:
diff changeset
   249
  "deletable_s obj \<equiv> init_alive obj \<and> (\<exists> ss \<in> static. deleted_s ss obj)"
chunhan
parents:
diff changeset
   250
chunhan
parents:
diff changeset
   251
definition undeletable_s :: "t_object \<Rightarrow> bool"
chunhan
parents:
diff changeset
   252
where
chunhan
parents:
diff changeset
   253
  "undeletable_s obj \<equiv> init_alive obj \<and> (\<forall> ss \<in> static. \<not> deleted_s ss obj)"
chunhan
parents:
diff changeset
   254
chunhan
parents:
diff changeset
   255
definition init_ss_eq:: "t_static_state \<Rightarrow> t_static_state \<Rightarrow> bool" (infix "\<doteq>" 100)
chunhan
parents:
diff changeset
   256
where
chunhan
parents:
diff changeset
   257
  "ss \<doteq> ss' \<equiv> ss \<subseteq> ss' \<and> {sobj. is_init_sobj sobj \<and> sobj \<in> ss'} \<subseteq> ss"
chunhan
parents:
diff changeset
   258
chunhan
parents:
diff changeset
   259
lemma [simp]: "ss \<doteq> ss"
chunhan
parents:
diff changeset
   260
by (auto simp:init_ss_eq_def)
chunhan
parents:
diff changeset
   261
chunhan
parents:
diff changeset
   262
definition init_ss_in:: "t_static_state \<Rightarrow> t_static_state set \<Rightarrow> bool" (infix "\<propto>" 101)
chunhan
parents:
diff changeset
   263
where
chunhan
parents:
diff changeset
   264
  "ss \<propto> sss \<equiv> \<exists> ss' \<in> sss. ss \<doteq> ss'"
chunhan
parents:
diff changeset
   265
chunhan
parents:
diff changeset
   266
lemma s2ss_included_sobj:
93
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   267
  "\<lbrakk>dalive s obj; co2sobj s obj= Some sobj\<rbrakk> \<Longrightarrow> sobj \<in> (s2ss s)"
77
chunhan
parents:
diff changeset
   268
by (simp add:s2ss_def, rule_tac x = obj in exI, simp)
chunhan
parents:
diff changeset
   269
93
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   270
fun init_dobj_related :: "t_sobject \<Rightarrow> t_dobject \<Rightarrow> bool"
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   271
where
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   272
  "init_dobj_related (S_proc (pi, sec, fds) tag) (D_proc p') = (pi = Init p')"
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   273
| "init_dobj_related (S_file sfs tag) (D_file f) = (\<exists> sf \<in> sfs. sfile_related sf f)"
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   274
| "init_dobj_related (S_dir sf) (D_dir f) = (sfile_related sf f)"
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   275
| "init_dobj_related _ _ = False"
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   276
77
chunhan
parents:
diff changeset
   277
lemma init_ss_in_prop:
93
dfde07c7cd6b new_childf generalized
chunhan
parents: 92
diff changeset
   278
  "\<lbrakk>s2ss s \<propto> static; co2sobj s obj = Some sobj; dalive s obj; init_dobj_related sobj obj\<rbrakk>
77
chunhan
parents:
diff changeset
   279
   \<Longrightarrow> \<exists> ss \<in> static. sobj \<in> ss"
chunhan
parents:
diff changeset
   280
apply (simp add:init_ss_in_def init_ss_eq_def)
chunhan
parents:
diff changeset
   281
apply (erule bexE, erule conjE)
chunhan
parents:
diff changeset
   282
apply (rule_tac x = ss' in bexI, auto dest!:s2ss_included_sobj)
chunhan
parents:
diff changeset
   283
done
chunhan
parents:
diff changeset
   284
chunhan
parents:
diff changeset
   285
chunhan
parents:
diff changeset
   286
end
chunhan
parents:
diff changeset
   287
chunhan
parents:
diff changeset
   288
end