no_shm_selinux/Tainted_prop.thy
author chunhan
Mon, 30 Dec 2013 23:41:58 +0800
changeset 86 690636b7b6f1
parent 77 6f7b9039715f
permissions -rw-r--r--
find bug: a created proc can be tainted by a message, which cannot remain and maynot be duplicated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
chunhan
parents:
diff changeset
     1
theory Tainted_prop 
chunhan
parents:
diff changeset
     2
imports Main Flask Flask_type Init_prop Current_files_prop Current_sockets_prop Delete_prop Proc_fd_of_file_prop Current_prop Alive_prop
chunhan
parents:
diff changeset
     3
begin
chunhan
parents:
diff changeset
     4
chunhan
parents:
diff changeset
     5
ML {*quick_and_dirty := true*}
chunhan
parents:
diff changeset
     6
chunhan
parents:
diff changeset
     7
context tainting begin
chunhan
parents:
diff changeset
     8
chunhan
parents:
diff changeset
     9
lemma valid_tainted_obj:
chunhan
parents:
diff changeset
    10
  "\<lbrakk>obj \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> (\<forall> f. obj \<noteq> O_dir f) \<and> (\<forall> q. obj \<noteq> O_msgq q) \<and> (\<forall> p fd. obj \<noteq> O_fd p fd) \<and> (\<forall> s. obj \<noteq> O_tcp_sock s) \<and> (\<forall> s. obj \<noteq> O_udp_sock s)" (*(\<forall> h. obj \<noteq> O_shm h) \<and>*)
chunhan
parents:
diff changeset
    11
apply (induct s, simp)
chunhan
parents:
diff changeset
    12
apply (drule seeds_appropriate, case_tac obj, simp+)
chunhan
parents:
diff changeset
    13
apply (frule vd_cons, frule vt_grant_os, case_tac a)
chunhan
parents:
diff changeset
    14
apply (auto split:if_splits option.splits)
chunhan
parents:
diff changeset
    15
done
chunhan
parents:
diff changeset
    16
chunhan
parents:
diff changeset
    17
lemma dir_not_tainted: "\<lbrakk>O_dir f \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> False"
chunhan
parents:
diff changeset
    18
by (auto dest!:valid_tainted_obj)
chunhan
parents:
diff changeset
    19
chunhan
parents:
diff changeset
    20
lemma msgq_not_tainted: "\<lbrakk>O_msgq q \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> False"
chunhan
parents:
diff changeset
    21
by (auto dest:valid_tainted_obj)
chunhan
parents:
diff changeset
    22
chunhan
parents:
diff changeset
    23
lemma tainted_in_current:
chunhan
parents:
diff changeset
    24
  "\<lbrakk>obj \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> alive s obj"
chunhan
parents:
diff changeset
    25
apply (induct s, simp)
chunhan
parents:
diff changeset
    26
apply (drule seeds_appropriate, case_tac obj, simp_all add:is_file_nil)
chunhan
parents:
diff changeset
    27
apply (frule vd_cons, frule valid_tainted_obj, simp, frule vt_grant_os, case_tac a)
chunhan
parents:
diff changeset
    28
apply (auto simp:alive_simps split:if_splits option.splits t_object.splits
chunhan
parents:
diff changeset
    29
           intro:same_inode_files_prop1 (*procs_of_shm_prop2 
chunhan
parents:
diff changeset
    30
            dest:info_shm_flow_in_procs *))
chunhan
parents:
diff changeset
    31
apply (auto simp:same_inode_files_def is_file_def split:if_splits)
chunhan
parents:
diff changeset
    32
done 
chunhan
parents:
diff changeset
    33
chunhan
parents:
diff changeset
    34
lemma tainted_proc_in_current:
chunhan
parents:
diff changeset
    35
  "\<lbrakk>O_proc p \<in> tainted s; valid s\<rbrakk> \<Longrightarrow> p \<in> current_procs s"
chunhan
parents:
diff changeset
    36
by (drule tainted_in_current, simp+)
chunhan
parents:
diff changeset
    37
chunhan
parents:
diff changeset
    38
(*
chunhan
parents:
diff changeset
    39
lemma info_flow_shm_tainted:
chunhan
parents:
diff changeset
    40
  "\<lbrakk>O_proc p \<in> tainted s; info_flow_shm s p p'; valid s\<rbrakk> \<Longrightarrow> O_proc p' \<in> tainted s"
chunhan
parents:
diff changeset
    41
proof (induct s arbitrary:p p')
chunhan
parents:
diff changeset
    42
  case Nil
chunhan
parents:
diff changeset
    43
  thus ?case by (simp add:flow_shm_in_seeds)
chunhan
parents:
diff changeset
    44
next
chunhan
parents:
diff changeset
    45
  case (Cons e s)
chunhan
parents:
diff changeset
    46
  hence p1: "O_proc p \<in> tainted (e # s)" and p2: "info_flow_shm (e # s) p p'" and p3: "valid (e # s)"  
chunhan
parents:
diff changeset
    47
    and p4: "\<And> p p'. \<lbrakk>O_proc p \<in> tainted s; info_flow_shm s p p'\<rbrakk> \<Longrightarrow> O_proc p' \<in> tainted s" 
chunhan
parents:
diff changeset
    48
    and p5: "valid s" and p6: "os_grant s e"
chunhan
parents:
diff changeset
    49
    by (auto dest:vd_cons intro:vd_cons vt_grant_os)
chunhan
parents:
diff changeset
    50
  have p4': 
chunhan
parents:
diff changeset
    51
    "\<And> p p' h flag. \<lbrakk>O_proc p \<in> tainted s; (p, SHM_RDWR) \<in> procs_of_shm s h; (p', flag) \<in> procs_of_shm s h\<rbrakk> 
chunhan
parents:
diff changeset
    52
                \<Longrightarrow> O_proc p' \<in> tainted s"
chunhan
parents:
diff changeset
    53
    by (rule p4, auto simp:info_flow_shm_def one_flow_shm_def procs_of_shm_prop2 p5)    
chunhan
parents:
diff changeset
    54
  from p2 p3 have p7: "p \<in> current_procs (e # s)" and p8: "p' \<in> current_procs (e # s)" 
chunhan
parents:
diff changeset
    55
    by (auto dest:info_shm_flow_in_procs) 
chunhan
parents:
diff changeset
    56
  show ?case
chunhan
parents:
diff changeset
    57
  proof (cases "self_shm s p p'")
chunhan
parents:
diff changeset
    58
    case True with p1 show ?thesis by simp
chunhan
parents:
diff changeset
    59
  next
chunhan
parents:
diff changeset
    60
    case False
chunhan
parents:
diff changeset
    61
    with p1 p2 p5 p6 p7 p8 p3 show ?thesis
chunhan
parents:
diff changeset
    62
    apply (case_tac e)(*
chunhan
parents:
diff changeset
    63
    prefer 7
chunhan
parents:
diff changeset
    64
    apply (simp add:info_flow_shm_simps split:if_splits option.splits)
chunhan
parents:
diff changeset
    65
    apply (rule allI|rule impI|rule conjI)+
chunhan
parents:
diff changeset
    66
    apply simp
chunhan
parents:
diff changeset
    67
    apply (case_tac "O_proc p \<in> tainted s", drule_tac p'=p' in p4, simp+)
chunhan
parents:
diff changeset
    68
    apply simp
chunhan
parents:
diff changeset
    69
chunhan
parents:
diff changeset
    70
chunhan
parents:
diff changeset
    71
chunhan
parents:
diff changeset
    72
chunhan
parents:
diff changeset
    73
    apply (auto simp:info_flow_shm_simps one_flow_shm_def dest:tainted_in_current 
chunhan
parents:
diff changeset
    74
  intro:p4 p4' split:if_splits option.splits)
chunhan
parents:
diff changeset
    75
    apply (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
    76
chunhan
parents:
diff changeset
    77
chunhan
parents:
diff changeset
    78
chunhan
parents:
diff changeset
    79
    apply (auto simp:one_flow_shm_def intro:p4 p4' split:if_splits option.splits)
chunhan
parents:
diff changeset
    80
chunhan
parents:
diff changeset
    81
chunhan
parents:
diff changeset
    82
chunhan
parents:
diff changeset
    83
    prefer 7
chunhan
parents:
diff changeset
    84
    apply (simp split:if_splits option.splits)
chunhan
parents:
diff changeset
    85
    apply (rule allI|rule impI|rule conjI)+
chunhan
parents:
diff changeset
    86
chunhan
parents:
diff changeset
    87
chunhan
parents:
diff changeset
    88
    apply (auto dest:p4'   procs_of_shm_prop2 tainted_in_current split:if_splits option.splits)[1]
chunhan
parents:
diff changeset
    89
chunhan
parents:
diff changeset
    90
    apply (erule disjE, drule_tac p = p and p' = p' in p4', simp+)
chunhan
parents:
diff changeset
    91
    apply (erule disjE, rule disjI2, rule disjI2, rule_tac x = h in exI, simp, rule_tac x= toflag in exI, simp)
chunhan
parents:
diff changeset
    92
    apply ((erule exE|erule conjE)+)
chunhan
parents:
diff changeset
    93
    
chunhan
parents:
diff changeset
    94
chunhan
parents:
diff changeset
    95
    apply (auto simp:info_flow_shm_def dest:p4'
chunhan
parents:
diff changeset
    96
           procs_of_shm_prop2 tainted_in_current split:if_splits option.splits)[1]
chunhan
parents:
diff changeset
    97
    apply (drule_tac p = p and p' = p' in p4')
chunhan
parents:
diff changeset
    98
    apply (erule_tac x = ha in allE, simp)
chunhan
parents:
diff changeset
    99
    apply (drule_tac p = "nat1" and p' = p' in p4')
chunhan
parents:
diff changeset
   100
    apply (auto dest:p4'[where p = nat1 and p' = p'])
chunhan
parents:
diff changeset
   101
    
chunhan
parents:
diff changeset
   102
apply (induct s) 
chunhan
parents:
diff changeset
   103
apply simp defer
chunhan
parents:
diff changeset
   104
apply (frule vd_cons, frule vt_grant_os, case_tac a)
chunhan
parents:
diff changeset
   105
apply (auto simp:info_flow_shm_def elim!:disjE)
chunhan
parents:
diff changeset
   106
sorry *)
chunhan
parents:
diff changeset
   107
  sorry
chunhan
parents:
diff changeset
   108
qed
chunhan
parents:
diff changeset
   109
qed
chunhan
parents:
diff changeset
   110
*)
chunhan
parents:
diff changeset
   111
chunhan
parents:
diff changeset
   112
lemma has_same_inode_comm:
chunhan
parents:
diff changeset
   113
  "has_same_inode s f f' = has_same_inode s f' f"
chunhan
parents:
diff changeset
   114
by (auto simp add:has_same_inode_def same_inode_files_def is_file_def)
chunhan
parents:
diff changeset
   115
chunhan
parents:
diff changeset
   116
(*
chunhan
parents:
diff changeset
   117
lemma info_flow_shm_tainted:
chunhan
parents:
diff changeset
   118
  "\<lbrakk>O_proc p \<in> tainted s; info_flow_shm s p p'; valid s\<rbrakk> \<Longrightarrow> O_proc p' \<in> tainted s"
chunhan
parents:
diff changeset
   119
by (simp only:tainted_eq_tainted info_flow_shm_tainted)
chunhan
parents:
diff changeset
   120
*)
chunhan
parents:
diff changeset
   121
chunhan
parents:
diff changeset
   122
lemma same_inode_files_tainted:
chunhan
parents:
diff changeset
   123
  "\<lbrakk>O_file f \<in> tainted s; f' \<in> same_inode_files s f; valid s\<rbrakk> \<Longrightarrow> O_file f' \<in> tainted s"
chunhan
parents:
diff changeset
   124
apply (induct s arbitrary:f f', simp add:same_inode_in_seeds has_same_inode_def)
chunhan
parents:
diff changeset
   125
apply (frule vt_grant_os, frule vd_cons, case_tac a)
chunhan
parents:
diff changeset
   126
prefer 6
chunhan
parents:
diff changeset
   127
apply (simp split:if_splits option.splits add:same_inode_files_open current_files_simps)
chunhan
parents:
diff changeset
   128
prefer 8
chunhan
parents:
diff changeset
   129
apply (frule tainted_in_current, simp, simp add:alive.simps, drule is_file_in_current)
chunhan
parents:
diff changeset
   130
apply (auto simp add:same_inode_files_closefd split:option.splits if_splits)[1]
chunhan
parents:
diff changeset
   131
prefer 8
chunhan
parents:
diff changeset
   132
apply (frule tainted_in_current, simp, simp add:alive.simps, drule is_file_in_current)
chunhan
parents:
diff changeset
   133
apply (auto simp add:same_inode_files_unlink split:option.splits if_splits)[1]
chunhan
parents:
diff changeset
   134
prefer 10
chunhan
parents:
diff changeset
   135
apply (auto split:if_splits option.splits simp:same_inode_files_linkhard current_files_simps)[1]
chunhan
parents:
diff changeset
   136
apply (drule tainted_in_current, simp, simp add:alive.simps is_file_in_current)
chunhan
parents:
diff changeset
   137
apply (drule same_inode_files_prop5, simp)
chunhan
parents:
diff changeset
   138
apply (drule same_inode_files_prop5, drule_tac f' = list1 and f'' = f' in same_inode_files_prop4, simp, simp)
chunhan
parents:
diff changeset
   139
chunhan
parents:
diff changeset
   140
apply (auto simp:same_inode_files_other split:if_splits)
chunhan
parents:
diff changeset
   141
apply (drule_tac f'' = f' and f' = f and f = fa in same_inode_files_prop4, simp+)
chunhan
parents:
diff changeset
   142
apply (drule_tac f'' = f' and f' = f and f = list in same_inode_files_prop4, simp+)
chunhan
parents:
diff changeset
   143
done
chunhan
parents:
diff changeset
   144
chunhan
parents:
diff changeset
   145
lemma has_same_inode_tainted:
chunhan
parents:
diff changeset
   146
  "\<lbrakk>O_file f \<in> tainted s; has_same_inode s f f'; valid s\<rbrakk> \<Longrightarrow> O_file f' \<in> tainted s"
chunhan
parents:
diff changeset
   147
by (simp add:has_same_inode_def same_inode_files_tainted)
chunhan
parents:
diff changeset
   148
chunhan
parents:
diff changeset
   149
lemma same_inodes_tainted:
chunhan
parents:
diff changeset
   150
  "\<lbrakk>f \<in> same_inode_files s f'; valid s\<rbrakk> \<Longrightarrow> (O_file f \<in> tainted s) = (O_file f' \<in> tainted s)"
chunhan
parents:
diff changeset
   151
apply (frule same_inode_files_prop8, frule same_inode_files_prop7)
chunhan
parents:
diff changeset
   152
apply (auto intro:has_same_inode_tainted)
chunhan
parents:
diff changeset
   153
done
chunhan
parents:
diff changeset
   154
chunhan
parents:
diff changeset
   155
lemma t_remain: "\<lbrakk>obj \<in> tainted s; valid (e # s); alive (e # s) obj\<rbrakk> 
chunhan
parents:
diff changeset
   156
             \<Longrightarrow> obj \<in> tainted (e # s)"
chunhan
parents:
diff changeset
   157
apply (frule vd_cons, frule vt_grant_os, case_tac e)
chunhan
parents:
diff changeset
   158
apply (auto simp:alive_simps split:option.splits if_splits)
chunhan
parents:
diff changeset
   159
done
chunhan
parents:
diff changeset
   160
chunhan
parents:
diff changeset
   161
lemma not_exited_cons:
chunhan
parents:
diff changeset
   162
  "\<not> exited obj (e # s) \<Longrightarrow> \<not> exited obj s"
chunhan
parents:
diff changeset
   163
apply (case_tac e, case_tac [!] obj)
chunhan
parents:
diff changeset
   164
by (auto)
chunhan
parents:
diff changeset
   165
chunhan
parents:
diff changeset
   166
lemma t_remain_app:
chunhan
parents:
diff changeset
   167
  "\<lbrakk>obj \<in> tainted s; \<not> died obj (s' @ s); valid (s' @ s)\<rbrakk> 
chunhan
parents:
diff changeset
   168
  \<Longrightarrow> obj \<in> tainted (s' @ s)"
chunhan
parents:
diff changeset
   169
apply (induct s', simp)
chunhan
parents:
diff changeset
   170
apply (simp (no_asm) only:cons_app_simp_aux, rule t_remain)
chunhan
parents:
diff changeset
   171
apply (simp_all add:not_died_cons_D vd_cons) 
chunhan
parents:
diff changeset
   172
apply (frule tainted_in_current)
chunhan
parents:
diff changeset
   173
apply (simp add:vd_cons)
chunhan
parents:
diff changeset
   174
apply (drule valid_tainted_obj, simp add:vd_cons) 
chunhan
parents:
diff changeset
   175
apply (case_tac a, auto simp:alive_simps split:t_object.splits option.splits)
chunhan
parents:
diff changeset
   176
done
chunhan
parents:
diff changeset
   177
chunhan
parents:
diff changeset
   178
lemma t_remain_app_deleted:
chunhan
parents:
diff changeset
   179
  "\<lbrakk>obj \<in> tainted s; \<not> deleted obj (s' @ s); appropriate obj; \<not> exited obj (s' @ s); valid (s' @ s)\<rbrakk>
chunhan
parents:
diff changeset
   180
   \<Longrightarrow> obj \<in> tainted (s' @ s)"
chunhan
parents:
diff changeset
   181
apply (rule t_remain_app, simp_all add:deleted_died)
chunhan
parents:
diff changeset
   182
done
chunhan
parents:
diff changeset
   183
chunhan
parents:
diff changeset
   184
end
chunhan
parents:
diff changeset
   185
chunhan
parents:
diff changeset
   186
end