Tainted_prop.thy
author chunhan
Sat, 08 Jun 2013 09:59:33 +0800
changeset 22 f20a798cdf7d
parent 19 ced0fcfbcf8e
child 23 25e55731ed01
permissions -rw-r--r--
info_flow_shm bug & update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
     1
theory Tainted_prop 
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
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
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
     3
begin
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
     4
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
     5
context tainting begin
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
     6
22
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
     7
fun Tainted :: "t_state \<Rightarrow> t_object set"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
     8
where
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
     9
  "Tainted [] = seeds"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    10
| "Tainted (Clone p p' fds shms # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    11
     (if (O_proc p) \<in> Tainted s then Tainted s \<union> {O_proc p'} else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    12
| "Tainted (Execve p f fds # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    13
     (if (O_file f) \<in> Tainted s then Tainted s \<union> {O_proc p} else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    14
| "Tainted (Kill p p' # s) = Tainted s - {O_proc p'}"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    15
| "Tainted (Ptrace p p' # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    16
     (if (O_proc p) \<in> Tainted s 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    17
      then Tainted s \<union> {O_proc p'' | p''. info_flow_shm s p' p''}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    18
      else if (O_proc p') \<in> Tainted s 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    19
           then Tainted s \<union> {O_proc p'' | p''. info_flow_shm s p p''}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    20
                else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    21
| "Tainted (Exit p # s) = Tainted s - {O_proc p}"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    22
| "Tainted (Open p f flags fd opt # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    23
     (case opt of
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    24
        Some inum \<Rightarrow> (if (O_proc p) \<in> Tainted s
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    25
                      then Tainted s \<union> {O_file f}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    26
                      else Tainted s)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    27
      | _         \<Rightarrow> Tainted s)" 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    28
| "Tainted (ReadFile p fd # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    29
     (case (file_of_proc_fd s p fd) of
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    30
        Some f \<Rightarrow> if (O_file f) \<in> Tainted s
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    31
                  then Tainted s \<union> {O_proc p' | p'. info_flow_shm s p p'}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    32
                  else Tainted s
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    33
      | None   \<Rightarrow> Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    34
| "Tainted (WriteFile p fd # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    35
     (case (file_of_proc_fd s p fd) of 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    36
        Some f \<Rightarrow> if (O_proc p) \<in> Tainted s
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    37
                  then Tainted s \<union> {O_file f' | f'. has_same_inode s f f'}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    38
                  else Tainted s
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    39
      | None   \<Rightarrow> Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    40
| "Tainted (CloseFd p fd # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    41
     (case (file_of_proc_fd s p fd) of
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    42
        Some f \<Rightarrow> ( if ((proc_fd_of_file s f = {(p,fd)}) \<and> (f \<in> files_hung_by_del s))
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    43
                    then Tainted s - {O_file f} else Tainted s )
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    44
      | _      \<Rightarrow> Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    45
| "Tainted (UnLink p f # s) = Tainted s - {O_file f}"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    46
| "Tainted (LinkHard p f f' # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    47
     (if (O_file f \<in> Tainted s) then Tainted s \<union> {O_file f'} else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    48
| "Tainted (Truncate p f len # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    49
     (if (len > 0 \<and> O_proc p \<in> Tainted s)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    50
      then Tainted s \<union> {O_file f' | f'. has_same_inode s f f'}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    51
      else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    52
| "Tainted (SendMsg p q m # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    53
     (if (O_proc p \<in> Tainted s) then Tainted s \<union> {O_msg q m} else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    54
| "Tainted (RecvMsg p q m # s) = 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    55
     (if (O_msg q m \<in> Tainted s) 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    56
      then Tainted s \<union> {O_proc p' | p'. info_flow_shm s p p'} - {O_msg q m}
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    57
      else Tainted s)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    58
| "Tainted (RemoveMsgq p q # s) = Tainted s - {O_msg q m| m. O_msg q m \<in> Tainted s}"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    59
| "Tainted (e # s) = Tainted s"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    60
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    61
lemma valid_Tainted_obj:
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    62
  "\<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> h. obj \<noteq> O_shm h) \<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)"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    63
apply (induct s, simp, drule seeds_in_init, case_tac obj, simp+)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    64
apply (frule vd_cons, frule vt_grant_os, case_tac a)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    65
apply (auto split:if_splits option.splits)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    66
done
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    67
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    68
lemma Tainted_in_current:
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    69
  "\<lbrakk>obj \<in> Tainted s; valid s\<rbrakk> \<Longrightarrow> alive s obj"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    70
apply (induct s, simp)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    71
apply (drule seeds_in_init, case_tac obj, simp_all add:is_file_nil)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    72
apply (frule vd_cons, frule valid_Tainted_obj, simp, frule vt_grant_os, case_tac a)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    73
apply (auto simp:alive_simps split:if_splits option.splits t_object.splits)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    74
apply (auto intro:has_same_inode_prop2 has_same_inode_prop1)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    75
apply 
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    76
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    77
lemma Tainted_imp_tainted:
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    78
  "\<lbrakk>obj \<in> Tainted s; valid s\<rbrakk> \<Longrightarrow> obj \<in> tainted s"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    79
apply (induct s arbitrary:obj, rule t_init, simp)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    80
apply (frule vd_cons, frule vt_grant_os)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    81
apply (case_tac a)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    82
apply (auto intro!:t_init t_clone t_execve t_cfile t_read t_write t_link t_trunc t_sendmsg t_recvmsg
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    83
             split:if_splits option.splits)
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    84
pr 25
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    85
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    86
lemma tainted_imp_Tainted:
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    87
  "obj \<in> tainted s \<Longrightarrow> obj \<in> Tainted s"
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    88
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    89
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    90
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    91
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    92
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
    93
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
    94
lemma tainted_in_current:
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
    95
  "obj \<in> tainted s \<Longrightarrow> alive s obj"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
    96
apply (erule tainted.induct, auto dest:vt_grant_os vd_cons simp:is_file_simps)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
    97
apply (drule seeds_in_init, simp add:tobj_in_alive)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
    98
apply (erule has_same_inode_prop2, simp, simp add:vd_cons)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
    99
apply (frule vt_grant_os, simp)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   100
apply (erule has_same_inode_prop1, simp, simp add:vd_cons)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   101
done
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   102
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   103
lemma tainted_is_valid:
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   104
  "obj \<in> tainted s \<Longrightarrow> valid s"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   105
by (erule tainted.induct, auto intro:valid.intros)
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   106
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   107
lemma t_remain_app:
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   108
  "\<lbrakk>obj \<in> tainted s; \<not> deleted obj (s' @ s); valid (s' @ s)\<rbrakk> 
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   109
  \<Longrightarrow> obj \<in> tainted (s' @ s)"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   110
apply (induct s', simp)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   111
apply (simp (no_asm) only:cons_app_simp_aux, rule t_remain)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   112
apply (simp_all add:not_deleted_cons_D vd_cons)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   113
apply (drule tainted_in_current, simp add:not_deleted_imp_alive_cons)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   114
done
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   115
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   116
lemma valid_tainted_obj:
22
f20a798cdf7d info_flow_shm bug & update
chunhan
parents: 19
diff changeset
   117
  "obj \<in> tainted s \<Longrightarrow> (\<forall> f. obj \<noteq> O_dir f) \<and> (\<forall> q. obj \<noteq> O_msgq q) \<and> (\<forall> h. obj \<noteq> O_shm h) \<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)"
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   118
apply (erule tainted.induct)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   119
apply (drule seeds_in_init)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   120
by auto
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   121
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   122
lemma dir_not_tainted: "O_dir f \<in> tainted s \<Longrightarrow> False"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   123
by (auto dest:valid_tainted_obj)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   124
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   125
lemma msgq_not_tainted: "O_msgq q \<in> tainted s \<Longrightarrow> False"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   126
by (auto dest:valid_tainted_obj)
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   127
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   128
lemma shm_not_tainted: "O_shm h \<in> tainted s \<Longrightarrow> False"
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   129
by (auto dest:valid_tainted_obj)
18
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   130
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   131
end
9b42765ce554 info_flow did NOT guarantee in current_procs
chunhan
parents:
diff changeset
   132
19
ced0fcfbcf8e reprove the top-level dynamic2static
chunhan
parents: 18
diff changeset
   133
end