no_shm_selinux/Enrich2.thy
author chunhan
Mon, 23 Dec 2013 19:47:17 +0800
changeset 82 0a68c605ae79
child 83 e79e3a8a4ceb
permissions -rw-r--r--
update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
82
chunhan
parents:
diff changeset
     1
theory Enrich
chunhan
parents:
diff changeset
     2
imports Main Flask Static Init_prop Valid_prop Tainted_prop Delete_prop Co2sobj_prop S2ss_prop S2ss_prop2
chunhan
parents:
diff changeset
     3
 Temp Enrich
chunhan
parents:
diff changeset
     4
begin
chunhan
parents:
diff changeset
     5
chunhan
parents:
diff changeset
     6
context tainting_s begin
chunhan
parents:
diff changeset
     7
chunhan
parents:
diff changeset
     8
lemma get_parentfs_ctxts_prop:
chunhan
parents:
diff changeset
     9
  "\<lbrakk>get_parentfs_ctxts s (a # f) = Some ctxts; sectxt_of_obj s (O_dir f) = Some ctxt; valid s\<rbrakk>
chunhan
parents:
diff changeset
    10
   \<Longrightarrow> ctxt \<in> set (ctxts)"
chunhan
parents:
diff changeset
    11
apply (induct f)
chunhan
parents:
diff changeset
    12
apply (auto split:option.splits)
chunhan
parents:
diff changeset
    13
done
chunhan
parents:
diff changeset
    14
chunhan
parents:
diff changeset
    15
lemma search_check_allp_intro:
chunhan
parents:
diff changeset
    16
  "\<lbrakk>search_check s sp pf; get_parentfs_ctxts s pf = Some ctxts; valid s; is_dir s pf\<rbrakk>
chunhan
parents:
diff changeset
    17
   \<Longrightarrow> search_check_allp sp (set ctxts)"
chunhan
parents:
diff changeset
    18
apply (case_tac pf)
chunhan
parents:
diff changeset
    19
apply (simp split:option.splits if_splits add:search_check_allp_def)
chunhan
parents:
diff changeset
    20
apply (rule ballI)
chunhan
parents:
diff changeset
    21
apply (auto simp:search_check_ctxt_def search_check_dir_def split:if_splits option.splits)
chunhan
parents:
diff changeset
    22
apply (auto simp:search_check_allp_def search_check_file_def)
chunhan
parents:
diff changeset
    23
apply (frule is_dir_not_file, simp)
chunhan
parents:
diff changeset
    24
done
chunhan
parents:
diff changeset
    25
chunhan
parents:
diff changeset
    26
lemma search_check_leveling_f:
chunhan
parents:
diff changeset
    27
  "\<lbrakk>search_check s sp pf; parent f = Some pf; is_file s f; valid s;
chunhan
parents:
diff changeset
    28
    sectxt_of_obj s (O_file f) = Some fctxt; search_check_file sp fctxt\<rbrakk>
chunhan
parents:
diff changeset
    29
   \<Longrightarrow> search_check s sp f"
chunhan
parents:
diff changeset
    30
apply (case_tac f, simp+)
chunhan
parents:
diff changeset
    31
apply (auto split:option.splits simp:search_check_ctxt_def)
chunhan
parents:
diff changeset
    32
apply (frule parentf_is_dir_prop2, simp)
chunhan
parents:
diff changeset
    33
apply (erule get_pfs_secs_prop, simp)
chunhan
parents:
diff changeset
    34
apply (erule_tac search_check_allp_intro, simp_all)
chunhan
parents:
diff changeset
    35
apply (simp add:parentf_is_dir_prop2)
chunhan
parents:
diff changeset
    36
done
chunhan
parents:
diff changeset
    37
chunhan
parents:
diff changeset
    38
lemma enrich_proc_prop:
chunhan
parents:
diff changeset
    39
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
    40
   \<Longrightarrow> valid (enrich_proc s p p') \<and> 
chunhan
parents:
diff changeset
    41
       (\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj) \<and> 
chunhan
parents:
diff changeset
    42
       (\<forall> obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive (enrich_proc s p p') obj) \<and>
chunhan
parents:
diff changeset
    43
       (files_hung_by_del (enrich_proc s p p') = files_hung_by_del s) \<and> 
chunhan
parents:
diff changeset
    44
       (\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp) \<and>
chunhan
parents:
diff changeset
    45
       (\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and> 
chunhan
parents:
diff changeset
    46
       (\<forall> q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq (enrich_proc s p p') q = cq2smsgq s q) \<and> 
chunhan
parents:
diff changeset
    47
       (\<forall> tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> file_of_proc_fd (enrich_proc s p p') tp fd = Some f) \<and>
chunhan
parents:
diff changeset
    48
       (\<forall> tp fd flags. flags_of_proc_fd s tp fd = Some flags \<longrightarrow> 
chunhan
parents:
diff changeset
    49
                      flags_of_proc_fd (enrich_proc s p p') tp fd = Some flags) \<and>
chunhan
parents:
diff changeset
    50
       (\<forall> q. msgs_of_queue (enrich_proc s p p') q = msgs_of_queue s q) \<and>
chunhan
parents:
diff changeset
    51
       (\<forall> tp fd. fd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp fd = cfd2sfd s tp fd) \<and>
chunhan
parents:
diff changeset
    52
       (cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
chunhan
parents:
diff changeset
    53
       (\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd)"
chunhan
parents:
diff changeset
    54
proof (induct s)
chunhan
parents:
diff changeset
    55
  case Nil
chunhan
parents:
diff changeset
    56
  thus ?case by (auto simp:is_created_proc_def)
chunhan
parents:
diff changeset
    57
next
chunhan
parents:
diff changeset
    58
  case (Cons e s)
chunhan
parents:
diff changeset
    59
  hence vd_cons: "valid (e # s)" and created_cons: "is_created_proc (e # s) p"
chunhan
parents:
diff changeset
    60
    and all_procs_cons: "p' \<notin> all_procs (e # s)" and vd: "valid s" 
chunhan
parents:
diff changeset
    61
    and os: "os_grant s e" and grant: "grant s e"
chunhan
parents:
diff changeset
    62
    by (auto dest:vd_cons vt_grant_os vt_grant)
chunhan
parents:
diff changeset
    63
  from all_procs_cons have all_procs: "p' \<notin> all_procs s" by (case_tac e, auto)
chunhan
parents:
diff changeset
    64
  from Cons have pre: "is_created_proc s p \<Longrightarrow> valid (enrich_proc s p p') \<and>
chunhan
parents:
diff changeset
    65
     (\<forall>obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj) \<and>
chunhan
parents:
diff changeset
    66
     (\<forall>obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive (enrich_proc s p p') obj) \<and>
chunhan
parents:
diff changeset
    67
     files_hung_by_del (enrich_proc s p p') = files_hung_by_del s \<and>
chunhan
parents:
diff changeset
    68
     (\<forall>tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp) \<and>
chunhan
parents:
diff changeset
    69
     (\<forall>f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and>
chunhan
parents:
diff changeset
    70
     (\<forall>q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq (enrich_proc s p p') q = cq2smsgq s q) \<and>
chunhan
parents:
diff changeset
    71
     (\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> file_of_proc_fd (enrich_proc s p p') tp fd = Some f) \<and>
chunhan
parents:
diff changeset
    72
     (\<forall>tp fd flags.
chunhan
parents:
diff changeset
    73
         flags_of_proc_fd s tp fd = Some flags \<longrightarrow> flags_of_proc_fd (enrich_proc s p p') tp fd = Some flags) \<and>
chunhan
parents:
diff changeset
    74
     (\<forall>q. msgs_of_queue (enrich_proc s p p') q = msgs_of_queue s q) \<and>
chunhan
parents:
diff changeset
    75
     (\<forall>tp fd. fd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp fd = cfd2sfd s tp fd) \<and>     
chunhan
parents:
diff changeset
    76
     (cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
chunhan
parents:
diff changeset
    77
     (\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd)"
chunhan
parents:
diff changeset
    78
    using vd all_procs by auto
chunhan
parents:
diff changeset
    79
  have alive_pre: "is_created_proc s p \<Longrightarrow> (\<forall>obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj)"
chunhan
parents:
diff changeset
    80
    using pre by simp
chunhan
parents:
diff changeset
    81
  hence curf_pre: "is_created_proc s p \<Longrightarrow> (\<forall>f. f \<in> current_files s \<longrightarrow> f \<in> current_files (enrich_proc s p p'))"
chunhan
parents:
diff changeset
    82
    using vd apply auto
chunhan
parents:
diff changeset
    83
    apply (drule is_file_or_dir, simp)
chunhan
parents:
diff changeset
    84
    apply (erule disjE)
chunhan
parents:
diff changeset
    85
    apply (erule_tac x = "O_file f" in allE, simp add:is_file_in_current)
chunhan
parents:
diff changeset
    86
    apply (erule_tac x = "O_dir f" in allE, simp add:is_dir_in_current)
chunhan
parents:
diff changeset
    87
    done
chunhan
parents:
diff changeset
    88
  have vd_enrich_cons: "valid (enrich_proc (e # s) p p')"
chunhan
parents:
diff changeset
    89
  proof-
chunhan
parents:
diff changeset
    90
    from pre have pre': "is_created_proc s p \<Longrightarrow> valid (enrich_proc s p p')" by simp
chunhan
parents:
diff changeset
    91
    have "is_created_proc s p \<Longrightarrow> valid (e # enrich_proc s p p')" 
chunhan
parents:
diff changeset
    92
      apply (frule pre')
chunhan
parents:
diff changeset
    93
      apply (erule_tac s = s in enrich_valid_intro_cons)
chunhan
parents:
diff changeset
    94
      apply (simp_all add:os grant vd pre)
chunhan
parents:
diff changeset
    95
      done  
chunhan
parents:
diff changeset
    96
    moreover have "\<And>f fds. \<lbrakk>valid (Execve p f fds # enrich_proc s p p'); is_created_proc s p; 
chunhan
parents:
diff changeset
    97
      valid (Execve p f fds # s); p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
    98
      \<Longrightarrow> valid (Execve p' f (fds \<inter> proc_file_fds s p) # Execve p f fds # enrich_proc s p p')"
chunhan
parents:
diff changeset
    99
    proof-
chunhan
parents:
diff changeset
   100
      fix f fds
chunhan
parents:
diff changeset
   101
      assume a1: "valid (Execve p f fds # enrich_proc s p p')" and a2: "is_created_proc s p"
chunhan
parents:
diff changeset
   102
        and a3: "valid (Execve p f fds # s)" and a0: "p' \<notin> all_procs s"
chunhan
parents:
diff changeset
   103
      have cp2sp: "\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp"
chunhan
parents:
diff changeset
   104
        and cf2sf: "\<forall> tf. tf \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') tf = cf2sfile s tf"
chunhan
parents:
diff changeset
   105
        and cfd2sfd: "\<forall> tp tfd. tfd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp tfd = cfd2sfd s tp tfd"
chunhan
parents:
diff changeset
   106
        and ffd_remain: "\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> 
chunhan
parents:
diff changeset
   107
                                   file_of_proc_fd (enrich_proc s p p') tp fd = Some f"
chunhan
parents:
diff changeset
   108
        and dup_sp: "cp2sproc (enrich_proc s p p') p' = cp2sproc s p"
chunhan
parents:
diff changeset
   109
        and dup_sfd: "\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   110
        using pre a2 by auto
chunhan
parents:
diff changeset
   111
      show "valid (Execve p' f (fds \<inter> proc_file_fds s p) # Execve p f fds # enrich_proc s p p')"
chunhan
parents:
diff changeset
   112
      proof-
chunhan
parents:
diff changeset
   113
        from a0 a3 have a0': "p' \<noteq> p" by (auto dest!:vt_grant_os not_all_procs_prop3)
chunhan
parents:
diff changeset
   114
        from a3 have grant: "grant s (Execve p f fds)" and os: "os_grant s (Execve p f fds)"
chunhan
parents:
diff changeset
   115
          by (auto dest:vt_grant_os vt_grant simp del:os_grant.simps)
chunhan
parents:
diff changeset
   116
        have f_in: "is_file (enrich_proc s p p') f" 
chunhan
parents:
diff changeset
   117
        proof-
chunhan
parents:
diff changeset
   118
          from pre a2
chunhan
parents:
diff changeset
   119
          have a4: "\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj"
chunhan
parents:
diff changeset
   120
            by (auto)
chunhan
parents:
diff changeset
   121
          show ?thesis using a3 a4
chunhan
parents:
diff changeset
   122
            apply (erule_tac x = "O_file f" in allE)
chunhan
parents:
diff changeset
   123
            by (auto dest:vt_grant_os)
chunhan
parents:
diff changeset
   124
        qed
chunhan
parents:
diff changeset
   125
        moreover have a5: "proc_file_fds s p \<subseteq> proc_file_fds (Execve p f fds # enrich_proc s p p') p'" 
chunhan
parents:
diff changeset
   126
          using a3 a0'
chunhan
parents:
diff changeset
   127
          apply (frule_tac vt_grant_os)
chunhan
parents:
diff changeset
   128
          apply (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   129
          apply (rule_tac x = fa in exI)
chunhan
parents:
diff changeset
   130
          apply (erule enrich_proc_dup_ffd)
chunhan
parents:
diff changeset
   131
          apply (simp_all add:vd all_procs a2)
chunhan
parents:
diff changeset
   132
          done
chunhan
parents:
diff changeset
   133
        ultimately have "os_grant (Execve p f fds # enrich_proc s p p') (Execve p' f (fds \<inter> proc_file_fds s p))"
chunhan
parents:
diff changeset
   134
          apply (auto simp:is_file_simps enrich_proc_dup_in a2 vd all_procs a1 enrich_proc_dup_ffds)
chunhan
parents:
diff changeset
   135
          done
chunhan
parents:
diff changeset
   136
        moreover have "grant (Execve p f fds # enrich_proc s p p') (Execve p' f (fds \<inter> proc_file_fds s p))"
chunhan
parents:
diff changeset
   137
        proof-
chunhan
parents:
diff changeset
   138
          from grant obtain up rp tp uf rf tf 
chunhan
parents:
diff changeset
   139
            where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   140
            and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   141
            by (simp split:option.splits, blast)
chunhan
parents:
diff changeset
   142
          with grant obtain pu nr nt where p3: "npctxt_execve (up, rp, tp) (uf, rf, tf) = Some (pu, nr, nt)"
chunhan
parents:
diff changeset
   143
            by (simp split:option.splits del:npctxt_execve.simps, blast)
chunhan
parents:
diff changeset
   144
          have p1': "sectxt_of_obj (Execve p f fds # enrich_proc s p p') (O_proc p') = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   145
            using p1 dup_sp a1 a0'
chunhan
parents:
diff changeset
   146
            apply (simp add:sectxt_of_obj_simps)
chunhan
parents:
diff changeset
   147
            by (simp add:cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   148
          from os have f_in': "is_file s f"  by simp 
chunhan
parents:
diff changeset
   149
          from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
   150
            by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents:
diff changeset
   151
          hence p2': "sectxt_of_obj (Execve p f fds # enrich_proc s p p') (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   152
            using f_in p2 cf2sf os a1
chunhan
parents:
diff changeset
   153
            apply (erule_tac x = f in allE)
chunhan
parents:
diff changeset
   154
            apply (auto dest:is_file_in_current simp:cf2sfile_def sectxt_of_obj_simps split:option.splits)
chunhan
parents:
diff changeset
   155
            apply (case_tac f, simp)
chunhan
parents:
diff changeset
   156
            apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents:
diff changeset
   157
            done 
chunhan
parents:
diff changeset
   158
          from dup_sfd a5 have "\<forall>fd. fd \<in> proc_file_fds s p \<longrightarrow> 
chunhan
parents:
diff changeset
   159
            cfd2sfd (Execve p f fds # enrich_proc s p p') p' fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   160
            apply (rule_tac allI)
chunhan
parents:
diff changeset
   161
            apply (erule_tac x = fd in allE, clarsimp)
chunhan
parents:
diff changeset
   162
            apply (drule set_mp, simp)
chunhan
parents:
diff changeset
   163
            apply (auto simp:cfd2sfd_execve proc_file_fds_def a1)
chunhan
parents:
diff changeset
   164
            done
chunhan
parents:
diff changeset
   165
          hence "inherit_fds_check (Execve p f fds # enrich_proc s p p') (up, nr, nt) p' (fds \<inter> proc_file_fds s p)"
chunhan
parents:
diff changeset
   166
            using grant os p1 p2 p3 vd
chunhan
parents:
diff changeset
   167
            apply (clarsimp)
chunhan
parents:
diff changeset
   168
            apply (rule_tac s = s and p = p and fds = fds in enrich_inherit_fds_check_dup)
chunhan
parents:
diff changeset
   169
            apply simp_all
chunhan
parents:
diff changeset
   170
            done
chunhan
parents:
diff changeset
   171
          moreover have "search_check (Execve p f fds # enrich_proc s p p') (up, rp, tp) f"
chunhan
parents:
diff changeset
   172
            using p1 p2 p2' vd cf2sf f_in f_in' grant p3 f_in a1
chunhan
parents:
diff changeset
   173
            apply (rule_tac s = s in enrich_search_check)
chunhan
parents:
diff changeset
   174
            apply (simp_all add:is_file_simps)
chunhan
parents:
diff changeset
   175
            apply (rule allI, rule impI, erule_tac x = fa in allE, simp)
chunhan
parents:
diff changeset
   176
            apply (drule_tac ff = fa in cf2sfile_other')
chunhan
parents:
diff changeset
   177
            by (auto simp:a2 curf_pre)
chunhan
parents:
diff changeset
   178
          ultimately show ?thesis 
chunhan
parents:
diff changeset
   179
            using p1' p2' p3
chunhan
parents:
diff changeset
   180
            apply (simp split:option.splits)
chunhan
parents:
diff changeset
   181
            using grant p1 p2
chunhan
parents:
diff changeset
   182
            apply simp
chunhan
parents:
diff changeset
   183
            done
chunhan
parents:
diff changeset
   184
        qed
chunhan
parents:
diff changeset
   185
        ultimately show ?thesis using a1
chunhan
parents:
diff changeset
   186
          by (erule_tac valid.intros(2), auto)
chunhan
parents:
diff changeset
   187
      qed
chunhan
parents:
diff changeset
   188
    qed
chunhan
parents:
diff changeset
   189
    moreover have "\<And>tp fds. \<lbrakk>valid (Clone tp p fds # s); p' \<noteq> p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> 
chunhan
parents:
diff changeset
   190
      valid (Clone tp p' (fds \<inter> proc_file_fds s tp) # Clone tp p fds # s)"
chunhan
parents:
diff changeset
   191
      apply (frule vt_grant_os, frule vt_grant, drule not_all_procs_prop3)
chunhan
parents:
diff changeset
   192
      apply (rule valid.intros(2))
chunhan
parents:
diff changeset
   193
      apply (simp_all split:option.splits add:sectxt_of_obj_simps)
chunhan
parents:
diff changeset
   194
      apply (auto simp add:proc_file_fds_def)[1]
chunhan
parents:
diff changeset
   195
      apply (auto simp:inherit_fds_check_def sectxt_of_obj_simps sectxts_of_fds_def inherit_fds_check_ctxt_def)
chunhan
parents:
diff changeset
   196
      done
chunhan
parents:
diff changeset
   197
    moreover have "\<And>f flags fd opt. \<lbrakk>valid (Open p f flags fd opt # enrich_proc s p p'); 
chunhan
parents:
diff changeset
   198
      is_created_proc s p; valid (Open p f flags fd opt # s); p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
   199
       \<Longrightarrow> valid (Open p' f (remove_create_flag flags) fd None # Open p f flags fd opt # enrich_proc s p p')"
chunhan
parents:
diff changeset
   200
    proof-
chunhan
parents:
diff changeset
   201
      fix f flags fd opt
chunhan
parents:
diff changeset
   202
      assume a1: "valid (Open p f flags fd opt # enrich_proc s p p')" and a2: "is_created_proc s p"
chunhan
parents:
diff changeset
   203
        and a3: "valid (Open p f flags fd opt # s)" and a4: "p' \<notin> all_procs s"
chunhan
parents:
diff changeset
   204
      have cp2sp: "\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp"
chunhan
parents:
diff changeset
   205
        and cf2sf: "\<forall> tf. tf \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') tf = cf2sfile s tf"
chunhan
parents:
diff changeset
   206
        and cfd2sfd: "\<forall> tp tfd. tfd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp tfd = cfd2sfd s tp tfd"
chunhan
parents:
diff changeset
   207
        and ffd_remain: "\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> 
chunhan
parents:
diff changeset
   208
                                   file_of_proc_fd (enrich_proc s p p') tp fd = Some f"
chunhan
parents:
diff changeset
   209
        and dup_sp: "cp2sproc (enrich_proc s p p') p' = cp2sproc s p"
chunhan
parents:
diff changeset
   210
        and dup_sfd: "\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   211
        using pre a2 by auto
chunhan
parents:
diff changeset
   212
      from a4 a3 have a0: "p' \<noteq> p" by (auto dest!:vt_grant_os not_all_procs_prop3 split:option.splits)
chunhan
parents:
diff changeset
   213
      have a5: "p' \<in> current_procs (enrich_proc s p p')" 
chunhan
parents:
diff changeset
   214
        using a2 a3 vd
chunhan
parents:
diff changeset
   215
        apply (erule_tac enrich_proc_dup_in)
chunhan
parents:
diff changeset
   216
        by (simp_all add:vd a4)
chunhan
parents:
diff changeset
   217
      have a6: "is_file (Open p f flags fd opt # enrich_proc s p p') f"
chunhan
parents:
diff changeset
   218
        using a1 a3
chunhan
parents:
diff changeset
   219
        by (auto simp:is_file_open dest:vt_grant_os)
chunhan
parents:
diff changeset
   220
      have a7: "fd \<notin> current_proc_fds (enrich_proc s p p') p'"
chunhan
parents:
diff changeset
   221
        using a2 a4 vd
chunhan
parents:
diff changeset
   222
        apply (simp add:enrich_proc_dup_ffds_eq_fds)
chunhan
parents:
diff changeset
   223
        apply (rule notI)
chunhan
parents:
diff changeset
   224
        apply (drule_tac p = p in file_fds_subset_pfds)
chunhan
parents:
diff changeset
   225
        apply (drule set_mp, simp)
chunhan
parents:
diff changeset
   226
        using a3
chunhan
parents:
diff changeset
   227
        apply (drule_tac vt_grant_os)
chunhan
parents:
diff changeset
   228
        apply (auto split:option.splits)
chunhan
parents:
diff changeset
   229
        done
chunhan
parents:
diff changeset
   230
      from a1 have a8: "valid (enrich_proc s p p')" by (erule_tac valid.cases, auto)
chunhan
parents:
diff changeset
   231
      from a3 have grant: "grant s (Open p f flags fd opt)" and os: "os_grant s (Open p f flags fd opt)"
chunhan
parents:
diff changeset
   232
        by (auto dest:vt_grant_os vt_grant)
chunhan
parents:
diff changeset
   233
      show "valid (Open p' f (remove_create_flag flags) fd None # Open p f flags fd opt # enrich_proc s p p')"
chunhan
parents:
diff changeset
   234
      proof (cases opt)
chunhan
parents:
diff changeset
   235
        case None
chunhan
parents:
diff changeset
   236
        have f_in: "is_file (enrich_proc s p p') f" 
chunhan
parents:
diff changeset
   237
        proof-
chunhan
parents:
diff changeset
   238
          from pre a2
chunhan
parents:
diff changeset
   239
          have a4: "\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj"
chunhan
parents:
diff changeset
   240
            by (auto)
chunhan
parents:
diff changeset
   241
          show ?thesis using a3 a4 None
chunhan
parents:
diff changeset
   242
            apply (erule_tac x = "O_file f" in allE)
chunhan
parents:
diff changeset
   243
            by (auto dest:vt_grant_os)
chunhan
parents:
diff changeset
   244
        qed
chunhan
parents:
diff changeset
   245
        from grant None obtain up rp tp uf rf tf 
chunhan
parents:
diff changeset
   246
          where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   247
          and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   248
          apply (simp split:option.splits)
chunhan
parents:
diff changeset
   249
          by (case_tac a, case_tac aa, blast)
chunhan
parents:
diff changeset
   250
        have p1': "sectxt_of_obj (Open p f flags fd opt # enrich_proc s p p') (O_proc p') = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   251
          using p1 dup_sp a1
chunhan
parents:
diff changeset
   252
          apply (simp add:sectxt_of_obj_simps)
chunhan
parents:
diff changeset
   253
          by (simp add:cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   254
        from os None have f_in': "is_file s f" by simp 
chunhan
parents:
diff changeset
   255
        from vd os None have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
   256
          by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents:
diff changeset
   257
        hence p2': "sectxt_of_obj (Open p f flags fd opt # enrich_proc s p p') (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   258
          using p2 cf2sf os a1 None f_in' vd f_in
chunhan
parents:
diff changeset
   259
          apply (erule_tac x = f in allE)
chunhan
parents:
diff changeset
   260
          apply (auto dest:is_file_in_current simp:cf2sfile_def sectxt_of_obj_simps split:option.splits)
chunhan
parents:
diff changeset
   261
          apply (case_tac f, simp)
chunhan
parents:
diff changeset
   262
          apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents:
diff changeset
   263
          done 
chunhan
parents:
diff changeset
   264
        have "search_check (Open p f flags fd opt # enrich_proc s p p') (up, rp, tp) f"
chunhan
parents:
diff changeset
   265
          using p1 p2 p2' vd cf2sf f_in f_in' grant f_in a1 None
chunhan
parents:
diff changeset
   266
          apply (rule_tac s = s in enrich_search_check)
chunhan
parents:
diff changeset
   267
          apply (simp_all add:is_file_simps)
chunhan
parents:
diff changeset
   268
          apply (rule allI, rule impI, erule_tac x = fa in allE, simp)
chunhan
parents:
diff changeset
   269
          apply (simp add:cf2sfile_open_none)
chunhan
parents:
diff changeset
   270
          done
chunhan
parents:
diff changeset
   271
        thus ?thesis using a0 a5 a6 a7 None a1
chunhan
parents:
diff changeset
   272
          apply (rule_tac valid.intros(2))
chunhan
parents:
diff changeset
   273
          apply (simp_all add:a1)
chunhan
parents:
diff changeset
   274
          apply (case_tac flags, simp add:is_creat_excl_flag_def)
chunhan
parents:
diff changeset
   275
          using p1' p2'
chunhan
parents:
diff changeset
   276
          apply simp
chunhan
parents:
diff changeset
   277
          using grant p1 p2
chunhan
parents:
diff changeset
   278
          apply (simp add:oflags_check_remove_create)
chunhan
parents:
diff changeset
   279
          done
chunhan
parents:
diff changeset
   280
      next
chunhan
parents:
diff changeset
   281
        case (Some inum)
chunhan
parents:
diff changeset
   282
        with os obtain pf where parent: "parent f = Some pf" by auto
chunhan
parents:
diff changeset
   283
        with grant Some obtain pu rp pt pfu pfr pft where
chunhan
parents:
diff changeset
   284
          p1: "sectxt_of_obj s (O_proc p) = Some (pu, rp, pt)" 
chunhan
parents:
diff changeset
   285
          and p2: "sectxt_of_obj s (O_dir pf) = Some (pfu, pfr, pft)"
chunhan
parents:
diff changeset
   286
          apply (simp split:option.splits)
chunhan
parents:
diff changeset
   287
          apply (case_tac a, case_tac aa, blast)
chunhan
parents:
diff changeset
   288
          done
chunhan
parents:
diff changeset
   289
        from p1 have p1': "sectxt_of_obj (enrich_proc s p p') (O_proc p) = Some (pu, rp, pt)"
chunhan
parents:
diff changeset
   290
          using cp2sp os
chunhan
parents:
diff changeset
   291
          apply (erule_tac x = p in allE)
chunhan
parents:
diff changeset
   292
          apply (auto split:option.splits simp:cp2sproc_def)
chunhan
parents:
diff changeset
   293
          done
chunhan
parents:
diff changeset
   294
        from os parent Some
chunhan
parents:
diff changeset
   295
        have pf_in: "is_dir s pf" by auto
chunhan
parents:
diff changeset
   296
        hence "\<exists> sf. cf2sfile s pf = Some sf" using vd
chunhan
parents:
diff changeset
   297
          by (auto dest!:is_dir_in_current current_file_has_sfile)
chunhan
parents:
diff changeset
   298
        from a1 parent Some have pf_in': "is_dir (enrich_proc s p p') pf" 
chunhan
parents:
diff changeset
   299
          apply (frule_tac vt_grant_os)
chunhan
parents:
diff changeset
   300
          by (clarsimp)
chunhan
parents:
diff changeset
   301
        have p2': "sectxt_of_obj (enrich_proc s p p') (O_dir pf) = Some (pfu, pfr, pft)"
chunhan
parents:
diff changeset
   302
        proof-
chunhan
parents:
diff changeset
   303
          have "cf2sfile (enrich_proc s p p') pf = cf2sfile s pf"
chunhan
parents:
diff changeset
   304
            using cf2sf pf_in
chunhan
parents:
diff changeset
   305
            apply (drule_tac is_dir_in_current)
chunhan
parents:
diff changeset
   306
            apply (erule_tac x = pf in allE)
chunhan
parents:
diff changeset
   307
            by simp
chunhan
parents:
diff changeset
   308
          with pf_in pf_in' p2 vd Some a8
chunhan
parents:
diff changeset
   309
          show ?thesis            
chunhan
parents:
diff changeset
   310
            apply (frule_tac is_dir_not_file)
chunhan
parents:
diff changeset
   311
            apply (frule_tac s = "enrich_proc s p p'" in is_dir_not_file)
chunhan
parents:
diff changeset
   312
            apply (simp add:cf2sfile_def)
chunhan
parents:
diff changeset
   313
            apply (case_tac pf, simp) 
chunhan
parents:
diff changeset
   314
            apply (simp add:sroot_def root_sec_remains)            
chunhan
parents:
diff changeset
   315
            by (auto split:option.splits dest!:current_has_sec' get_pfs_secs_prop' dest:parentf_is_dir_prop1)        
chunhan
parents:
diff changeset
   316
        qed
chunhan
parents:
diff changeset
   317
        from p1 have dup: "sectxt_of_obj (Open p f flags fd (Some inum) # enrich_proc s p p') (O_proc p') 
chunhan
parents:
diff changeset
   318
          = Some (pu, rp, pt)"
chunhan
parents:
diff changeset
   319
          using a1 Some
chunhan
parents:
diff changeset
   320
          apply (simp add:sec_open)
chunhan
parents:
diff changeset
   321
          using dup_sp
chunhan
parents:
diff changeset
   322
          apply (auto split:option.splits if_splits simp:cp2sproc_def)
chunhan
parents:
diff changeset
   323
          done        
chunhan
parents:
diff changeset
   324
        have nsf: "sectxt_of_obj (Open p f flags fd (Some inum) # enrich_proc s p p') (O_file f) 
chunhan
parents:
diff changeset
   325
          = Some (pu, R_object, type_transition pt pft C_file True)"
chunhan
parents:
diff changeset
   326
          using a1 Some p1 p2 parent p2' p1'
chunhan
parents:
diff changeset
   327
          by (simp add:sec_open)
chunhan
parents:
diff changeset
   328
        have "search_check (Open p f flags fd (Some inum) # enrich_proc s p p') (pu, rp, pt) f"
chunhan
parents:
diff changeset
   329
        proof-
chunhan
parents:
diff changeset
   330
          have "search_check (Open p f flags fd (Some inum) # enrich_proc s p p') (pu, rp, pt) pf"
chunhan
parents:
diff changeset
   331
            using grant Some parent p1 p2 vd a1 pf_in pf_in' p2'
chunhan
parents:
diff changeset
   332
            apply simp 
chunhan
parents:
diff changeset
   333
            apply (rule_tac s = s in enrich_search_check') 
chunhan
parents:
diff changeset
   334
            apply (simp_all add:is_dir_simps sectxt_of_obj_simps)
chunhan
parents:
diff changeset
   335
            apply (rule allI, rule impI)
chunhan
parents:
diff changeset
   336
            apply (case_tac "fa = f")
chunhan
parents:
diff changeset
   337
            using os Some
chunhan
parents:
diff changeset
   338
            apply simp
chunhan
parents:
diff changeset
   339
            apply (drule_tac f' = fa in cf2sfile_open)
chunhan
parents:
diff changeset
   340
            apply (simp add:current_files_simps)
chunhan
parents:
diff changeset
   341
            using curf_pre a2
chunhan
parents:
diff changeset
   342
            apply simp
chunhan
parents:
diff changeset
   343
            apply simp
chunhan
parents:
diff changeset
   344
            using cf2sf
chunhan
parents:
diff changeset
   345
            apply simp
chunhan
parents:
diff changeset
   346
            done
chunhan
parents:
diff changeset
   347
          moreover have "is_file (Open p f flags fd (Some inum) # enrich_proc s p p') f"
chunhan
parents:
diff changeset
   348
            using a1 Some
chunhan
parents:
diff changeset
   349
            by (simp add:is_file_open)
chunhan
parents:
diff changeset
   350
          ultimately 
chunhan
parents:
diff changeset
   351
          show ?thesis
chunhan
parents:
diff changeset
   352
            using parent a1 Some nsf
chunhan
parents:
diff changeset
   353
            apply (erule_tac search_check_leveling_f)
chunhan
parents:
diff changeset
   354
            apply (simp_all)
chunhan
parents:
diff changeset
   355
            apply (simp add:search_check_file_def)
chunhan
parents:
diff changeset
   356
            apply (simp add:permission_check.simps)
chunhan
parents:
diff changeset
   357
            sorry
chunhan
parents:
diff changeset
   358
        qed
chunhan
parents:
diff changeset
   359
        thus ?thesis using a0 a5 a6 a7 a1 Some
chunhan
parents:
diff changeset
   360
          apply (rule_tac valid.intros(2))
chunhan
parents:
diff changeset
   361
          apply (simp add:a1)
chunhan
parents:
diff changeset
   362
          apply simp
chunhan
parents:
diff changeset
   363
          apply (case_tac flags, simp add:is_creat_excl_flag_def)
chunhan
parents:
diff changeset
   364
          using grant p1 p2 parent dup nsf
chunhan
parents:
diff changeset
   365
          apply (simp add:oflags_check_remove_create)
chunhan
parents:
diff changeset
   366
          done
chunhan
parents:
diff changeset
   367
      qed
chunhan
parents:
diff changeset
   368
    qed
chunhan
parents:
diff changeset
   369
    moreover have "\<And>fd. \<lbrakk>valid (CloseFd p fd # enrich_proc s p p'); is_created_proc s p; 
chunhan
parents:
diff changeset
   370
      valid (CloseFd p fd # s); p' \<notin> all_procs s; fd \<in> proc_file_fds s p\<rbrakk>
chunhan
parents:
diff changeset
   371
      \<Longrightarrow> valid (CloseFd p' fd # CloseFd p fd # enrich_proc s p p')"
chunhan
parents:
diff changeset
   372
    proof-
chunhan
parents:
diff changeset
   373
      fix fd
chunhan
parents:
diff changeset
   374
      assume a1: "valid (CloseFd p fd # enrich_proc s p p')" and a2: "is_created_proc s p" 
chunhan
parents:
diff changeset
   375
        and a3: "p' \<notin> all_procs s" and a4: "valid (CloseFd p fd # s)"
chunhan
parents:
diff changeset
   376
        and a5: "fd \<in> proc_file_fds s p"
chunhan
parents:
diff changeset
   377
      from a4 a3 have a0: "p' \<noteq> p" by (auto dest!:vt_grant_os not_all_procs_prop3)
chunhan
parents:
diff changeset
   378
      have "p' \<in> current_procs (enrich_proc s p p')" 
chunhan
parents:
diff changeset
   379
        using a2 a3 vd
chunhan
parents:
diff changeset
   380
        by (auto intro:enrich_proc_dup_in)
chunhan
parents:
diff changeset
   381
      moreover have "fd \<in> current_proc_fds (enrich_proc s p p') p'"      
chunhan
parents:
diff changeset
   382
        using a5 a2 a3 vd pre'
chunhan
parents:
diff changeset
   383
        apply (simp)
chunhan
parents:
diff changeset
   384
        apply (drule_tac s = "enrich_proc s p p'" and p = p' in file_fds_subset_pfds)
chunhan
parents:
diff changeset
   385
        apply (erule set_mp)
chunhan
parents:
diff changeset
   386
        apply (simp add:enrich_proc_dup_ffds)
chunhan
parents:
diff changeset
   387
        done
chunhan
parents:
diff changeset
   388
      ultimately show "valid (CloseFd p' fd # CloseFd p fd # enrich_proc s p p')"
chunhan
parents:
diff changeset
   389
        apply (rule_tac valid.intros(2))
chunhan
parents:
diff changeset
   390
        apply (simp_all add:a1 a0 a2 pre')
chunhan
parents:
diff changeset
   391
        done
chunhan
parents:
diff changeset
   392
    qed
chunhan
parents:
diff changeset
   393
    moreover have "\<And> fd. \<lbrakk>valid (ReadFile p fd # enrich_proc s p p');
chunhan
parents:
diff changeset
   394
            is_created_proc s p; valid (ReadFile p fd # s); p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
   395
           \<Longrightarrow> valid (ReadFile p' fd # ReadFile p fd # enrich_proc s p p')"
chunhan
parents:
diff changeset
   396
    proof-
chunhan
parents:
diff changeset
   397
      fix fd
chunhan
parents:
diff changeset
   398
      assume a1: "valid (ReadFile p fd # enrich_proc s p p')" and a2: "is_created_proc s p"
chunhan
parents:
diff changeset
   399
        and a3: "valid (ReadFile p fd # s)" and a4: "p' \<notin> all_procs s"
chunhan
parents:
diff changeset
   400
      from a3 have os: "os_grant s (ReadFile p fd)" and grant: "grant s (ReadFile p fd)"
chunhan
parents:
diff changeset
   401
        by (auto dest:vt_grant_os vt_grant)
chunhan
parents:
diff changeset
   402
      have cp2sp: "\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp"
chunhan
parents:
diff changeset
   403
        and cf2sf: "\<forall> tf. tf \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') tf = cf2sfile s tf"
chunhan
parents:
diff changeset
   404
        and cfd2sfd: "\<forall> tp tfd. tfd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp tfd = cfd2sfd s tp tfd"
chunhan
parents:
diff changeset
   405
        and ffd_remain: "\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> 
chunhan
parents:
diff changeset
   406
                                   file_of_proc_fd (enrich_proc s p p') tp fd = Some f"
chunhan
parents:
diff changeset
   407
        and dup_sp: "cp2sproc (enrich_proc s p p') p' = cp2sproc s p"
chunhan
parents:
diff changeset
   408
        and dup_sfd: "\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   409
        using pre a2 by auto
chunhan
parents:
diff changeset
   410
      have vd_enrich: "valid (enrich_proc s p p')" using a1 by (auto dest:valid.cases)
chunhan
parents:
diff changeset
   411
      show "valid (ReadFile p' fd # ReadFile p fd # enrich_proc s p p')"
chunhan
parents:
diff changeset
   412
      proof-
chunhan
parents:
diff changeset
   413
        have "os_grant (ReadFile p fd # enrich_proc s p p') (ReadFile p' fd)"
chunhan
parents:
diff changeset
   414
          using a1 a2 a4 vd os
chunhan
parents:
diff changeset
   415
          apply (clarsimp simp:current_files_simps enrich_proc_dup_in enrich_proc_dup_ffds_eq_fds)
chunhan
parents:
diff changeset
   416
          apply (simp add:proc_file_fds_def)
chunhan
parents:
diff changeset
   417
          apply (rule conjI)
chunhan
parents:
diff changeset
   418
          apply (rule_tac x = f in exI, simp add:enrich_proc_dup_ffd)
chunhan
parents:
diff changeset
   419
          using curf_pre
chunhan
parents:
diff changeset
   420
          apply (simp)
chunhan
parents:
diff changeset
   421
          apply (drule enrich_proc_dup_fflags)
chunhan
parents:
diff changeset
   422
          apply simp_all
chunhan
parents:
diff changeset
   423
          apply (erule disjE)
chunhan
parents:
diff changeset
   424
          apply auto
chunhan
parents:
diff changeset
   425
          apply (simp add:is_read_flag_def)
chunhan
parents:
diff changeset
   426
          done
chunhan
parents:
diff changeset
   427
        moreover have "grant (ReadFile p fd # enrich_proc s p p') (ReadFile p' fd)"
chunhan
parents:
diff changeset
   428
        proof-
chunhan
parents:
diff changeset
   429
          from grant obtain f sp sfd sf where p1: "file_of_proc_fd s p fd = Some f"
chunhan
parents:
diff changeset
   430
            and p2: "sectxt_of_obj s (O_proc p) = Some sp" 
chunhan
parents:
diff changeset
   431
            and p3: "sectxt_of_obj s (O_fd p fd) = Some sfd"
chunhan
parents:
diff changeset
   432
            and p4: "sectxt_of_obj s (O_file f) = Some sf"
chunhan
parents:
diff changeset
   433
            by (auto split:option.splits) 
chunhan
parents:
diff changeset
   434
          from os obtain flag where p0: "flags_of_proc_fd s p fd = Some flag"
chunhan
parents:
diff changeset
   435
            by auto
chunhan
parents:
diff changeset
   436
          from os have f_in_s: "f \<in> current_files s" using p1 by simp
chunhan
parents:
diff changeset
   437
          from p1 vd have isfile_s: "is_file s f" by (erule_tac file_of_pfd_is_file, simp)
chunhan
parents:
diff changeset
   438
          with alive_pre a2 have isfile_s': "is_file (enrich_proc s p p') f"
chunhan
parents:
diff changeset
   439
            apply simp
chunhan
parents:
diff changeset
   440
            apply (erule_tac x = "O_file f" in allE, simp)
chunhan
parents:
diff changeset
   441
            done          
chunhan
parents:
diff changeset
   442
          from p0 obtain flag' where p0': "flags_of_proc_fd (enrich_proc s p p') p' fd = Some flag'"
chunhan
parents:
diff changeset
   443
            and p0'': "(flag' = flag) \<or> (flag' = remove_create_flag flag)"
chunhan
parents:
diff changeset
   444
            using a2 a4 vd
chunhan
parents:
diff changeset
   445
            apply (drule_tac enrich_proc_dup_fflags)
chunhan
parents:
diff changeset
   446
            apply auto
chunhan
parents:
diff changeset
   447
            apply (case_tac flag, auto)
chunhan
parents:
diff changeset
   448
            apply (case_tac flag, auto)
chunhan
parents:
diff changeset
   449
            done            
chunhan
parents:
diff changeset
   450
          from p1 have p1': "file_of_proc_fd (enrich_proc s p p') p' fd = Some f"
chunhan
parents:
diff changeset
   451
            using a2 a4 vd
chunhan
parents:
diff changeset
   452
            by (simp add:enrich_proc_dup_ffd)
chunhan
parents:
diff changeset
   453
          from p2 have p2': "sectxt_of_obj (enrich_proc s p p') (O_proc p') = Some sp"
chunhan
parents:
diff changeset
   454
            using dup_sp
chunhan
parents:
diff changeset
   455
            by (auto simp:cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   456
          from p3 p1 p1' p0 p0' os have p3': "sectxt_of_obj (enrich_proc s p p') (O_fd p' fd) = Some sfd"
chunhan
parents:
diff changeset
   457
            using dup_sfd
chunhan
parents:
diff changeset
   458
            apply (erule_tac x = fd in allE)
chunhan
parents:
diff changeset
   459
            apply (auto simp:proc_file_fds_def cfd2sfd_def split:option.splits)
chunhan
parents:
diff changeset
   460
            apply (drule current_file_has_sfile')
chunhan
parents:
diff changeset
   461
            apply (simp add:vd, simp)
chunhan
parents:
diff changeset
   462
            apply (drule current_file_has_sfile')
chunhan
parents:
diff changeset
   463
            apply (simp add:vd, simp)
chunhan
parents:
diff changeset
   464
            done
chunhan
parents:
diff changeset
   465
          from p4 have p4': "sectxt_of_obj (enrich_proc s p p') (O_file f) = Some sf" 
chunhan
parents:
diff changeset
   466
            using f_in_s cf2sf isfile_s isfile_s' a1 vd_enrich vd
chunhan
parents:
diff changeset
   467
            apply (erule_tac x = f in allE)
chunhan
parents:
diff changeset
   468
            apply (simp)
chunhan
parents:
diff changeset
   469
            apply (auto simp:cf2sfile_def split:option.splits 
chunhan
parents:
diff changeset
   470
              dest!:current_has_sec' get_pfs_secs_prop' dest:parentf_is_dir is_file_in_current)
chunhan
parents:
diff changeset
   471
            apply (case_tac f, simp, drule root_is_dir', simp, simp, simp)
chunhan
parents:
diff changeset
   472
            done
chunhan
parents:
diff changeset
   473
          show ?thesis using p1' p2' p3' p4' a1
chunhan
parents:
diff changeset
   474
            apply (simp add:sectxt_of_obj_simps)
chunhan
parents:
diff changeset
   475
            using grant p1 p2 p3 p4 
chunhan
parents:
diff changeset
   476
            apply simp
chunhan
parents:
diff changeset
   477
            done
chunhan
parents:
diff changeset
   478
        qed
chunhan
parents:
diff changeset
   479
        ultimately show ?thesis
chunhan
parents:
diff changeset
   480
          using a1
chunhan
parents:
diff changeset
   481
          by (erule_tac valid.intros(2), simp+)
chunhan
parents:
diff changeset
   482
      qed
chunhan
parents:
diff changeset
   483
    qed
chunhan
parents:
diff changeset
   484
    ultimately show ?thesis 
chunhan
parents:
diff changeset
   485
      using created_cons vd_cons all_procs_cons
chunhan
parents:
diff changeset
   486
      apply (case_tac e)
chunhan
parents:
diff changeset
   487
      apply (auto simp:is_created_proc_simps split:if_splits)
chunhan
parents:
diff changeset
   488
      done
chunhan
parents:
diff changeset
   489
  qed
chunhan
parents:
diff changeset
   490
  moreover have "\<forall>obj. alive (e # s) obj \<longrightarrow> alive (enrich_proc (e # s) p p') obj"
chunhan
parents:
diff changeset
   491
    sorry
chunhan
parents:
diff changeset
   492
  moreover have "\<forall>obj. enrich_not_alive (e # s) obj \<longrightarrow> enrich_not_alive (enrich_proc (e # s) p p') obj"
chunhan
parents:
diff changeset
   493
    sorry
chunhan
parents:
diff changeset
   494
  moreover have "files_hung_by_del (enrich_proc (e # s) p p') = files_hung_by_del (e # s)"
chunhan
parents:
diff changeset
   495
    sorry
chunhan
parents:
diff changeset
   496
  moreover have "\<forall>tp. tp \<in> current_procs (e # s) \<longrightarrow> cp2sproc (enrich_proc (e # s) p p') tp = cp2sproc (e # s) tp"
chunhan
parents:
diff changeset
   497
    sorry
chunhan
parents:
diff changeset
   498
  moreover have "\<forall>f. f \<in> current_files (e # s) \<longrightarrow> cf2sfile (enrich_proc (e # s) p p') f = cf2sfile (e # s) f"
chunhan
parents:
diff changeset
   499
    sorry
chunhan
parents:
diff changeset
   500
  moreover have "\<forall>q. q \<in> current_msgqs (e # s) \<longrightarrow> cq2smsgq (enrich_proc (e # s) p p') q = cq2smsgq (e # s) q"
chunhan
parents:
diff changeset
   501
    sorry
chunhan
parents:
diff changeset
   502
  moreover have "\<forall>tp fd f. file_of_proc_fd (e # s) tp fd = Some f \<longrightarrow> 
chunhan
parents:
diff changeset
   503
    file_of_proc_fd (enrich_proc (e # s) p p') tp fd = Some f"
chunhan
parents:
diff changeset
   504
    sorry
chunhan
parents:
diff changeset
   505
  moreover have "\<forall>tp fd flags. flags_of_proc_fd (e # s) tp fd = Some flags \<longrightarrow>
chunhan
parents:
diff changeset
   506
        flags_of_proc_fd (enrich_proc (e # s) p p') tp fd = Some flags"
chunhan
parents:
diff changeset
   507
    sorry
chunhan
parents:
diff changeset
   508
  moreover have "\<forall>q. msgs_of_queue (enrich_proc (e # s) p p') q = msgs_of_queue (e # s) q"
chunhan
parents:
diff changeset
   509
    sorry 
chunhan
parents:
diff changeset
   510
  moreover have "\<forall>tp fd. fd \<in> proc_file_fds (e # s) tp \<longrightarrow> 
chunhan
parents:
diff changeset
   511
    cfd2sfd (enrich_proc (e # s) p p') tp fd = cfd2sfd (e # s) tp fd"
chunhan
parents:
diff changeset
   512
    sorry 
chunhan
parents:
diff changeset
   513
  moreover have "cp2sproc (enrich_proc (e # s) p p') p' = cp2sproc (e # s) p"
chunhan
parents:
diff changeset
   514
  proof-
chunhan
parents:
diff changeset
   515
    from pre have b0: "is_created_proc s p \<Longrightarrow> cp2sproc (enrich_proc s p p') p' = cp2sproc s p" by simp
chunhan
parents:
diff changeset
   516
    have b1: "\<And> tp f fds. \<lbrakk>valid (enrich_proc (Execve tp f fds # s) p p'); valid (Execve tp f fds # s);
chunhan
parents:
diff changeset
   517
      is_created_proc (Execve tp f fds # s) p; p' \<notin> all_procs (Execve tp f fds # s)\<rbrakk>
chunhan
parents:
diff changeset
   518
      \<Longrightarrow> cp2sproc (enrich_proc (Execve tp f fds # s) p p') p' = cp2sproc (Execve tp f fds # s) p"
chunhan
parents:
diff changeset
   519
    proof-
chunhan
parents:
diff changeset
   520
      fix tp f fds
chunhan
parents:
diff changeset
   521
      assume a1: "valid (enrich_proc (Execve tp f fds # s) p p')"
chunhan
parents:
diff changeset
   522
      and a2: "valid (Execve tp f fds # s)" and a3: "is_created_proc (Execve tp f fds # s) p"
chunhan
parents:
diff changeset
   523
      and a4: "p' \<notin> all_procs (Execve tp f fds # s)"
chunhan
parents:
diff changeset
   524
      show "cp2sproc (enrich_proc (Execve tp f fds # s) p p') p' = cp2sproc (Execve tp f fds # s) p"
chunhan
parents:
diff changeset
   525
      proof (cases "tp = p")
chunhan
parents:
diff changeset
   526
        case True
chunhan
parents:
diff changeset
   527
        show ?thesis using True a1 a2 a3 a4
chunhan
parents:
diff changeset
   528
          thm not_all_procs_prop3
chunhan
parents:
diff changeset
   529
          apply (auto simp add:cp2sproc_execve is_created_proc_def split:option.splits dest!:current_has_sec' 
chunhan
parents:
diff changeset
   530
            dest:vt_grant_os not_all_procs_prop2 not_all_procs_prop3)
chunhan
parents:
diff changeset
   531
          
chunhan
parents:
diff changeset
   532
          sorry
chunhan
parents:
diff changeset
   533
      next
chunhan
parents:
diff changeset
   534
        case False
chunhan
parents:
diff changeset
   535
        show ?thesis sorry
chunhan
parents:
diff changeset
   536
      qed
chunhan
parents:
diff changeset
   537
    qed
chunhan
parents:
diff changeset
   538
    have b2: "\<And> tp fd. cp2sproc (enrich_proc (ReadFile tp fd # s) p p') p' = cp2sproc (ReadFile tp fd # s) p"
chunhan
parents:
diff changeset
   539
      sorry
chunhan
parents:
diff changeset
   540
    have b3: "\<And> tp. cp2sproc (enrich_proc (Exit tp # s) p p') p' = cp2sproc (Exit tp # s) p"
chunhan
parents:
diff changeset
   541
      sorry
chunhan
parents:
diff changeset
   542
    have b4: "\<And> tp tp'. cp2sproc (enrich_proc (Kill tp tp' # s) p p') p' = cp2sproc (Kill tp tp' # s) p"
chunhan
parents:
diff changeset
   543
      sorry
chunhan
parents:
diff changeset
   544
    have b5: "\<And> tp tp' fds. cp2sproc (enrich_proc (Clone tp tp' fds # s) p p') p' = 
chunhan
parents:
diff changeset
   545
      cp2sproc (Clone tp tp' fds # s) p"
chunhan
parents:
diff changeset
   546
      sorry
chunhan
parents:
diff changeset
   547
    have b6: "\<And> tp f flags fd opt. cp2sproc (enrich_proc (Open tp f flags fd opt # s) p p') p' =
chunhan
parents:
diff changeset
   548
      cp2sproc (Open tp f flags fd opt # s) p"
chunhan
parents:
diff changeset
   549
      sorry
chunhan
parents:
diff changeset
   550
    have b7: "\<And> tp fd. cp2sproc (enrich_proc (CloseFd tp fd # s) p p') p' = cp2sproc (CloseFd tp fd # s) p"
chunhan
parents:
diff changeset
   551
      sorry
chunhan
parents:
diff changeset
   552
    show ?thesis using vd_enrich_cons
chunhan
parents:
diff changeset
   553
      apply (case_tac e)
chunhan
parents:
diff changeset
   554
      apply (simp_all only:b1 b2 b3 b4 b5 b6 b7)
chunhan
parents:
diff changeset
   555
      using created_cons vd_enrich_cons vd_cons b0
chunhan
parents:
diff changeset
   556
      apply (auto simp:cp2sproc_other is_created_proc_def)
chunhan
parents:
diff changeset
   557
      done
chunhan
parents:
diff changeset
   558
  qed
chunhan
parents:
diff changeset
   559
  moreover have "\<forall> fd. fd \<in> proc_file_fds (e # s) p \<longrightarrow> 
chunhan
parents:
diff changeset
   560
    cfd2sfd (enrich_proc (e # s) p p') p' fd = cfd2sfd (e # s) p fd"
chunhan
parents:
diff changeset
   561
    sorry
chunhan
parents:
diff changeset
   562
  ultimately show ?case
chunhan
parents:
diff changeset
   563
    by simp
chunhan
parents:
diff changeset
   564
qed
chunhan
parents:
diff changeset
   565
  
chunhan
parents:
diff changeset
   566
chunhan
parents:
diff changeset
   567
lemma enrich_proc_valid:
chunhan
parents:
diff changeset
   568
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> valid (enrich_proc s p p')"
chunhan
parents:
diff changeset
   569
by (auto dest:enrich_proc_prop)
chunhan
parents:
diff changeset
   570
chunhan
parents:
diff changeset
   571
lemma enrich_proc_valid:
chunhan
parents:
diff changeset
   572
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> " 
chunhan
parents:
diff changeset
   573
chunhan
parents:
diff changeset
   574
 
chunhan
parents:
diff changeset
   575
chunhan
parents:
diff changeset
   576
lemma enrich_proc_tainted: 
chunhan
parents:
diff changeset
   577
  "\<lbrakk>is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
chunhan
parents:
diff changeset
   578
   \<Longrightarrow> tainted (enrich_proc s p p') = (if (O_proc p \<in> tainted s) 
chunhan
parents:
diff changeset
   579
         then tainted s \<union> {O_proc p'} else tainted s)"
chunhan
parents:
diff changeset
   580
apply (induct s)
chunhan
parents:
diff changeset
   581
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   582
apply (frule vt_grant_os, frule vd_cons, simp)
chunhan
parents:
diff changeset
   583
apply (frule enrich_proc_dup_in, simp+)
chunhan
parents:
diff changeset
   584
apply (frule not_all_procs_prop3)
chunhan
parents:
diff changeset
   585
apply (case_tac a)
chunhan
parents:
diff changeset
   586
prefer 3
chunhan
parents:
diff changeset
   587
apply (simp split:if_splits)
chunhan
parents:
diff changeset
   588
apply (rule impI|rule conjI)+
chunhan
parents:
diff changeset
   589
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   590
apply (auto simp:is_created_proc_def split:if_splits dest:tainted_in_current)[1]
chunhan
parents:
diff changeset
   591
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   592
chunhan
parents:
diff changeset
   593
prefer 4
chunhan
parents:
diff changeset
   594
apply (simp split:if_splits)
chunhan
parents:
diff changeset
   595
apply (rule impI|rule conjI)+
chunhan
parents:
diff changeset
   596
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   597
apply (auto simp:is_created_proc_def split:if_splits dest:tainted_in_current)[1]
chunhan
parents:
diff changeset
   598
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   599
chunhan
parents:
diff changeset
   600
prefer 4
chunhan
parents:
diff changeset
   601
apply (auto simp:is_created_proc_def split:if_splits option.splits dest:tainted_in_current)[1]
chunhan
parents:
diff changeset
   602
chunhan
parents:
diff changeset
   603
prefer 4
chunhan
parents:
diff changeset
   604
apply (auto simp:is_created_proc_def split:if_splits option.splits dest:tainted_in_current enrich_proc_dup_ffd enrich_proc_dup_ffd')[1]
chunhan
parents:
diff changeset
   605
chunhan
parents:
diff changeset
   606
chunhan
parents:
diff changeset
   607
chunhan
parents:
diff changeset
   608
lemma enrich_proc_dup_tainted:
chunhan
parents:
diff changeset
   609
  "\<lbrakk>is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
chunhan
parents:
diff changeset
   610
   \<Longrightarrow> (O_proc p' \<in> tainted (enrich_proc s p p')) = (O_proc p \<in> tainted s)"
chunhan
parents:
diff changeset
   611
apply (induct s)
chunhan
parents:
diff changeset
   612
apply (simp add:is_created_proc_def)
chunhan
parents:
diff changeset
   613
apply (frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   614
apply (case_tac a)
chunhan
parents:
diff changeset
   615
apply (auto simp:is_created_proc_def)[1]
chunhan
parents:
diff changeset
   616
chunhan
parents:
diff changeset
   617
chunhan
parents:
diff changeset
   618
lemma enrich_proc_tainted:
chunhan
parents:
diff changeset
   619
  ""
chunhan
parents:
diff changeset
   620
chunhan
parents:
diff changeset
   621
chunhan
parents:
diff changeset
   622
end
chunhan
parents:
diff changeset
   623
chunhan
parents:
diff changeset
   624
end