diff -r f27ba31b7e96 -r 6f7b9039715f no_shm_selinux/Info_flow_shm_prop.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/no_shm_selinux/Info_flow_shm_prop.thy Tue Dec 17 13:30:21 2013 +0800 @@ -0,0 +1,831 @@ +theory Info_flow_shm_prop +imports Main Flask_type Flask My_list_prefix Init_prop Valid_prop Delete_prop Current_prop +begin + +context flask begin + +(*********** simpset for one_flow_shm **************) + +lemma one_flow_not_self: + "one_flow_shm s h p p \ False" +by (simp add:one_flow_shm_def) + +lemma one_flow_shm_attach: + "valid (Attach p h flag # s) \ one_flow_shm (Attach p h flag # s) = (\ h' pa pb. + if (h' = h) + then (pa = p \ pb \ p \ flag = SHM_RDWR \ (\ flagb. (pb, flagb) \ procs_of_shm s h)) \ + (pb = p \ pa \ p \ (pa, SHM_RDWR) \ procs_of_shm s h) \ + (one_flow_shm s h pa pb) + else one_flow_shm s h' pa pb )" +apply (rule ext, rule ext, rule ext, frule vd_cons, frule vt_grant_os) +by (auto simp add: one_flow_shm_def) + +lemma one_flow_shm_detach: + "valid (Detach p h # s) \ one_flow_shm (Detach p h # s) = (\ h' pa pb. + if (h' = h) + then (pa \ p \ pb \ p \ one_flow_shm s h' pa pb) + else one_flow_shm s h' pa pb)" +apply (rule ext, rule ext, rule ext, frule vt_grant_os) +by (auto simp:one_flow_shm_def) + +lemma one_flow_shm_deleteshm: + "valid (DeleteShM p h # s) \ one_flow_shm (DeleteShM p h # s) = (\ h' pa pb. + if (h' = h) + then False + else one_flow_shm s h' pa pb)" +apply (rule ext, rule ext, rule ext, frule vt_grant_os) +by (auto simp: one_flow_shm_def) + +lemma one_flow_shm_clone: + "valid (Clone p p' fds shms # s) \ one_flow_shm (Clone p p' fds shms # s) = (\ h pa pb. + if (pa = p' \ pb \ p' \ h \ shms) + then (if (pb = p) then (flag_of_proc_shm s p h = Some SHM_RDWR) else one_flow_shm s h p pb) + else if (pb = p' \ pa \ p' \ h \ shms) + then (if (pa = p) then (flag_of_proc_shm s p h = Some SHM_RDWR) else one_flow_shm s h pa p) + else one_flow_shm s h pa pb)" +apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons, clarsimp) +apply (frule_tac p = p' in procs_of_shm_prop2', simp) +apply (auto simp:one_flow_shm_def intro:procs_of_shm_prop4 flag_of_proc_shm_prop1) +done + +lemma one_flow_shm_execve: + "valid (Execve p f fds # s) \ one_flow_shm (Execve p f fds # s) = (\ h pa pb. + pa \ p \ pb \ p \ one_flow_shm s h pa pb )" +apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:one_flow_shm_def) + +lemma one_flow_shm_kill: + "valid (Kill p p' # s) \ one_flow_shm (Kill p p' # s) = (\ h pa pb. + pa \ p' \ pb \ p' \ one_flow_shm s h pa pb )" +apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:one_flow_shm_def) + +lemma one_flow_shm_exit: + "valid (Exit p # s) \ one_flow_shm (Exit p # s) = (\ h pa pb. + pa \ p \ pb \ p \ one_flow_shm s h pa pb )" +apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:one_flow_shm_def) + +lemma one_flow_shm_other: + "\valid (e # s); + \ p h flag. e \ Attach p h flag; + \ p h. e \ Detach p h; + \ p h. e \ DeleteShM p h; + \ p p' fds shms. e \ Clone p p' fds shms; + \ p f fds. e \ Execve p f fds; + \ p p'. e \ Kill p p'; + \ p. e \ Exit p + \ \ one_flow_shm (e # s) = one_flow_shm s" +apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons) +apply (case_tac e, auto simp:one_flow_shm_def dest:procs_of_shm_prop2) +apply (drule procs_of_shm_prop1, auto) +done + +lemmas one_flow_shm_simps = one_flow_shm_other one_flow_shm_attach one_flow_shm_detach one_flow_shm_deleteshm + one_flow_shm_clone one_flow_shm_execve one_flow_shm_kill one_flow_shm_exit + +type_synonym t_edge_shm = "t_process \ t_shm \ t_process" +fun Fst:: "t_edge_shm \ t_process" where "Fst (a, b, c) = a" +fun Snd:: "t_edge_shm \ t_shm" where "Snd (a, b, c) = b" +fun Trd:: "t_edge_shm \ t_process" where "Trd (a, b, c) = c" + +fun edge_related:: "t_edge_shm list \ t_process \ t_shm \ bool" +where + "edge_related [] p h = False" +| "edge_related ((from, shm, to) # path) p h = + (if (((p = from) \ (p = to)) \ (h = shm)) then True + else edge_related path p h)" + +inductive path_by_shm :: "t_state \ t_process \ t_edge_shm list \ t_process \ bool" +where + pbs1: "p \ current_procs s \ path_by_shm s p [] p" +| pbs2: "\path_by_shm s p path p'; one_flow_shm s h p' p''; p'' \ set (map Fst path)\ + \ path_by_shm s p ((p', h, p'')# path) p''" + + +lemma one_step_path: "\one_flow_shm s h p p'; valid s\ \ path_by_shm s p [(p, h, p')] p'" +apply (rule_tac path = "[]" and p = p in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1)) +apply (auto intro:procs_of_shm_prop2 simp:one_flow_shm_def) +done + +lemma pbs_prop1: + "path_by_shm s p path p' \ ((path = []) = (p = p')) \ (path \ [] \ p \ set (map Fst path))" +apply (erule path_by_shm.induct, simp) +apply (auto simp:one_flow_shm_def) +done + +lemma pbs_prop2: + "path_by_shm s p path p' \ (path = []) = (p = p')" +by (simp add:pbs_prop1) + +lemma pbs_prop2': + "path_by_shm s p path p \ path = []" +by (simp add:pbs_prop2) + +lemma pbs_prop3: + "\path_by_shm s p path p'; path \ []\ \ p \ set (map Fst path)" +by (drule pbs_prop1, auto) + +lemma pbs_prop4[rule_format]: + "path_by_shm s p path p'\ path \ [] \ p' \ set (map Trd path)" +by (erule path_by_shm.induct, auto) + +lemma pbs_prop5[rule_format]: + "path_by_shm s p path p' \ path \ [] \ p' \ set (map Fst path)" +by (erule path_by_shm.induct, auto simp:one_flow_shm_def) + +lemma pbs_prop6_aux: + "path_by_shm s pa pathac pc \ valid s \ (\ pb \ set (map Fst pathac). \ pathab pathbc. path_by_shm s pa pathab pb \ path_by_shm s pb pathbc pc \ pathac = pathbc @ pathab)" +apply (erule path_by_shm.induct) +apply simp +apply clarify +apply (case_tac "pb = p'", simp) +apply (rule_tac x = path in exI, simp) +apply (erule one_step_path, simp) +apply (erule_tac x = pb in ballE, simp_all, clarsimp) +apply (rule_tac x = pathab in exI, simp) +apply (erule pbs2, auto) +done + +lemma pbs_prop6: + "\path_by_shm s pa pathac pc; pb \ set (map Fst pathac); valid s\ + \ \ pathab pathbc. path_by_shm s pa pathab pb \ path_by_shm s pb pathbc pc \ pathac = pathbc @ pathab" +by (drule pbs_prop6_aux, auto) + +lemma pbs_prop7_aux: + "path_by_shm s pa pathac pc \ valid s \ (\ pb \ set (map Trd pathac). \ pathab pathbc. path_by_shm s pa pathab pb \ path_by_shm s pb pathbc pc \ pathac = pathbc @ pathab)" +apply (erule path_by_shm.induct) +apply simp +apply clarify +apply (case_tac "pb = p''", simp) +apply (rule_tac x = "(p',h,p'') # path" in exI, simp) +apply (rule conjI, erule pbs2, simp+) +apply (rule pbs1, clarsimp simp:one_flow_shm_def procs_of_shm_prop2) +apply (erule_tac x = pb in ballE, simp_all, clarsimp) +apply (rule_tac x = pathab in exI, simp) +apply (erule pbs2, auto) +done + +lemma pbs_prop7: + "\path_by_shm s pa pathac pc; pb \ set (map Trd pathac); valid s\ + \ \ pathab pathbc. path_by_shm s pa pathab pb \ path_by_shm s pb pathbc pc \ pathac = pathbc @ pathab" +by (drule pbs_prop7_aux, drule mp, simp, erule_tac x = pb in ballE, auto) + +lemma pbs_prop8: + "path_by_shm s p path p' \ (set (map Fst path) - {p}) = (set (map Trd path) - {p'})" +proof (induct rule:path_by_shm.induct) + case (pbs1 p s) + thus ?case by simp +next + case (pbs2 s p path p' h p'') + assume p1:"path_by_shm s p path p'" and p2: "set (map Fst path) - {p} = set (map Trd path) - {p'}" + and p3: "one_flow_shm s h p' p''" and p4: "p'' \ set (map Fst path)" + show "set (map Fst ((p', h, p'') # path)) - {p} = set (map Trd ((p', h, p'') # path)) - {p''}" + (is "?left = ?right") + proof (cases "path = []") + case True + with p1 have "p = p'" by (drule_tac pbs_prop2, simp) + thus ?thesis using True + using p2 by (simp) + next + case False + with p1 have a1: "p \ p'" by (drule_tac pbs_prop2, simp) + from p3 have a2: "p' \ p''" by (simp add:one_flow_shm_def) + from p1 False have a3: "p' \ set (map Trd path)" by (drule_tac pbs_prop4, simp+) + from p4 p1 False have a4: "p \ p''" by (drule_tac pbs_prop3, auto) + with p2 a2 p4 have a5: "p'' \ set (map Trd path)" by auto + + have "?left = (set (map Fst path) - {p}) \ {p'}" using a1 by auto + moreover have "... = (set (map Trd path) - {p'}) \ {p'}" + using p2 by auto + moreover have "... = set (map Trd path)" using a3 by auto + moreover have "... = set (map Trd path) - {p''}" using a5 by simp + moreover have "... = ?right" by simp + ultimately show ?thesis by simp + qed +qed + +lemma pbs_prop9_aux[rule_format]: + "path_by_shm s p path p' \ h \ set (map Snd path) \ valid s \ (\ pa pb patha pathb. path_by_shm s p patha pa \ path_by_shm s pb pathb p' \ one_flow_shm s h pa pb \ path = pathb @ [(pa, h, pb)] @ patha \ h \ set (map Snd patha))" +apply (erule path_by_shm.induct, simp) +apply (rule impI, case_tac "h \ set (map Snd path)", simp_all) +apply (erule exE|erule conjE)+ +apply (rule_tac x = pa in exI, rule_tac x = pb in exI, rule_tac x = patha in exI, simp) +apply (rule pbs2, auto) +apply (rule_tac x = p' in exI, rule_tac x = p'' in exI, rule_tac x = path in exI, simp) +apply (rule pbs1, clarsimp simp:one_flow_shm_def procs_of_shm_prop2) +done + +lemma pbs_prop9: + "\h \ set (map Snd path); path_by_shm s p path p'; valid s\ + \ \ pa pb patha pathb. path_by_shm s p patha pa \ path_by_shm s pb pathb p' \ + one_flow_shm s h pa pb \ path = pathb @ [(pa, h, pb)] @ patha \ h \ set (map Snd patha)" +by (rule pbs_prop9_aux, auto) + +lemma path_by_shm_trans_aux[rule_format]: + "path_by_shm s p' path' p'' \ valid s \ (\ p path. path_by_shm s p path p' \ (\ path''. path_by_shm s p path'' p''))" +proof (induct rule:path_by_shm.induct) + case (pbs1 p s) + thus ?case + by (clarify, rule_tac x = path in exI, simp) +next + case (pbs2 s p path p' h p'') + hence p1: "path_by_shm s p path p'" and p2: "one_flow_shm s h p' p''" + and p3: "valid s \ (\pa path. path_by_shm s pa path p \ (\path''. path_by_shm s pa path'' p'))" + and p4: "p'' \ set (map Fst path)" by auto + show ?case + proof clarify + fix pa path' + assume p5: "path_by_shm s pa path' p" and p6: "valid s" + with p3 obtain path'' where a1: "path_by_shm s pa path'' p'" by auto + have p3': "\pa path. path_by_shm s pa path p \ (\path''. path_by_shm s pa path'' p')" + using p3 p6 by simp + show "\path''. path_by_shm s pa path'' p''" + proof (cases "p'' \ set (map Fst path'')") + case True + then obtain res where "path_by_shm s pa res p''" using a1 pbs_prop6 p6 by blast + thus ?thesis by auto + next + case False + with p2 a1 show ?thesis + apply (rule_tac x = "(p', h, p'') # path''" in exI) + apply (rule path_by_shm.intros(2), auto) + done + qed + qed +qed + +lemma path_by_shm_trans: + "\path_by_shm s p path p'; path_by_shm s p' path' p''; valid s\ \ \ path''. path_by_shm s p path'' p''" +by (drule_tac p' = p' and p'' = p'' in path_by_shm_trans_aux, auto) + +lemma path_by_shm_intro1_prop: + "\ path_by_shm s p [] p \ p \ current_procs s" +by (auto dest:path_by_shm.intros(1)) + +lemma path_by_shm_intro3: + "\path_by_shm s p path from; (from, SHM_RDWR) \ procs_of_shm s h; (to, flag) \ procs_of_shm s h; + to \ set (map Fst path); from \ to\ + \ path_by_shm s p ((from, h, to)#path) to" +apply (rule path_by_shm.intros(2), simp_all) +by (auto simp:one_flow_shm_def) + +lemma path_by_shm_intro4: + "\(p, flag) \ procs_of_shm s h; valid s\ \ path_by_shm s p [] p" +by (drule procs_of_shm_prop2, simp, simp add:path_by_shm.intros(1)) + +lemma path_by_shm_intro5: + "\(from, SHM_RDWR) \ procs_of_shm s h; (to,flag) \ procs_of_shm s h; valid s; from \ to\ + \ path_by_shm s from [(from, h, to)] to" +apply (rule_tac p' = "from" and h = h in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2) +apply (simp add:one_flow_shm_def, rule_tac x = flag in exI, auto) +done + +(* p'' \ set (map Fst path): not duplicated target process; + * p1 - ha \ p2; p2 - hb \ p3; p3 - ha \ p4; so path_by_shm p1 [(p3,ha,p4), (p2,hb,p3),(p1,ha,p2)] p4, + * but this could be also path_by_shm p1 [(p1,ha,p4)] p4, so the former one is redundant! *) + +inductive path_by_shm':: "t_state \ t_process \ t_edge_shm list \ t_process \ bool" +where + pbs1': "p \ current_procs s \ path_by_shm' s p [] p" +| pbs2': "\path_by_shm' s p path p'; one_flow_shm s h p' p''; p'' \ set (map Fst path); + h \ set (map Snd path)\ + \ path_by_shm' s p ((p', h, p'')# path) p''" + +lemma pbs_prop10: + "\path_by_shm s p path p'; one_flow_shm s h p' p''; valid s\ \ \path'. path_by_shm s p path' p''" +apply (case_tac "p'' \ set (map Fst path)") +apply (drule_tac pb = p'' in pbs_prop6, simp+) +apply ((erule exE|erule conjE)+, rule_tac x = pathab in exI, simp) +apply (rule_tac x = "(p', h, p'') # path" in exI) +apply (erule pbs2, simp+) +done + +lemma pbs'_imp_pbs[rule_format]: + "path_by_shm' s p path p' \ valid s \ (\ path'. path_by_shm s p path' p')" +apply (erule path_by_shm'.induct) +apply (rule impI, rule_tac x = "[]" in exI, simp add:pbs1) +apply (rule impI, clarsimp) +apply (erule pbs_prop10, simp+) +done + +lemma pbs_imp_pbs'[rule_format]: + "path_by_shm s p path p' \ valid s \ (\ path'. path_by_shm' s p path' p')" +apply (erule path_by_shm.induct) +apply (rule impI, rule_tac x = "[]" in exI, erule pbs1') +apply (rule impI, simp, erule exE) (* +apply ( erule exE, case_tac "h \ set (map Snd path)") +apply (drule_tac s = s and p = p and p' = p' in pbs_prop9, simp+) defer +apply (rule_tac x = "(p', h, p'') # path'" in exI) +apply (erule pbs2', simp+) +apply ((erule exE|erule conjE)+) +apply (rule_tac x = "(pa, h, p'') # patha" in exI) +apply (erule pbs2', auto simp:one_flow_shm_def) +done*) +sorry + + +lemma pbs'_eq_pbs: + "valid s \ (\ path'. path_by_shm' s p path' p') = (\ path. path_by_shm s p path p')" +by (rule iffI, auto intro:pbs_imp_pbs' pbs'_imp_pbs) + +definition flow_by_shm :: "t_state \ t_process \ t_process \ bool" +where + "flow_by_shm s p p' \ \ path. path_by_shm s p path p'" + +lemma flow_by_shm_intro': + "valid s \ flow_by_shm s p p' = (\ path. path_by_shm' s p path p')" +by (auto simp:flow_by_shm_def pbs'_eq_pbs) + +lemma one_step_flows: "\one_flow_shm s h p p'; valid s\ \ flow_by_shm s p p'" +by (drule one_step_path, auto simp:flow_by_shm_def) + +lemma flow_by_shm_trans: + "\flow_by_shm s p p'; flow_by_shm s p' p''; valid s\ \ flow_by_shm s p p''" +by (auto simp:flow_by_shm_def intro!:path_by_shm_trans) + +lemma flow_by_shm_intro1_prop: + "\ flow_by_shm s p p \ p \ current_procs s" +by (auto dest:path_by_shm.intros(1) simp:flow_by_shm_def) + +lemma flow_by_shm_intro1: + "p \ current_procs s \ flow_by_shm s p p" +by (auto dest:path_by_shm.intros(1) simp:flow_by_shm_def) + +lemma flow_by_shm_intro2: + "\flow_by_shm s p p'; one_flow_shm s h p' p''; valid s\ \ flow_by_shm s p p''" +by (auto intro:flow_by_shm_trans dest:one_step_flows) + +lemma flow_by_shm_intro3: + "\flow_by_shm s p from; (from, SHM_RDWR) \ procs_of_shm s h; (to, flag) \ procs_of_shm s h; from \ to; valid s\ + \ flow_by_shm s p to" +apply (rule flow_by_shm_intro2) +by (auto simp:one_flow_shm_def) + +lemma flow_by_shm_intro4: + "\(p, flag) \ procs_of_shm s h; valid s\ \ flow_by_shm s p p" +by (drule procs_of_shm_prop2, simp, simp add:flow_by_shm_intro1) + +lemma flow_by_shm_intro5: + "\(from, SHM_RDWR) \ procs_of_shm s h; (to,flag) \ procs_of_shm s h; valid s; from \ to\ + \ flow_by_shm s from to" +apply (rule_tac p' = "from" and h = h in flow_by_shm_intro2) +apply (rule flow_by_shm_intro1, simp add:procs_of_shm_prop2) +apply (simp add:one_flow_shm_def, rule_tac x = flag in exI, auto) +done + +lemma flow_by_shm_intro6: + "path_by_shm s p path p' \ flow_by_shm s p p'" +by (auto simp:flow_by_shm_def) + +(********* simpset for inductive Info_flow_shm **********) +lemma path_by_shm_detach1_aux: + "path_by_shm s' pa path pb \ valid (Detach p h # s) \ (s' = Detach p h # s) + \ \ edge_related path p h \ path_by_shm s pa path pb" +apply (erule path_by_shm.induct, simp) +apply (rule impI, rule path_by_shm.intros(1), simp+) +by (auto simp:one_flow_shm_def split:if_splits intro:path_by_shm_intro3) + +lemma path_by_shm_detach1: + "\path_by_shm (Detach p h # s) pa path pb; valid (Detach p h # s)\ + \ \ edge_related path p h \ path_by_shm s pa path pb" +by (auto dest:path_by_shm_detach1_aux) + +lemma path_by_shm_detach2_aux[rule_format]: + "path_by_shm s pa path pb \ valid (Detach p h # s) \ \ edge_related path p h + \ path_by_shm (Detach p h # s) pa path pb" +apply (induct rule:path_by_shm.induct) +apply (rule impI, rule path_by_shm.intros(1), simp) +apply (rule impI, erule conjE, simp split:if_splits) +apply (rule path_by_shm.intros(2), simp) +apply (simp add:one_flow_shm_detach) +apply (rule impI, simp+) +done + +lemma path_by_shm_detach2: + "\valid (Detach p h # s); \ edge_related path p h; path_by_shm s pa path pb\ + \ path_by_shm (Detach p h # s) pa path pb" +by (auto intro!:path_by_shm_detach2_aux) + +lemma path_by_shm_detach: + "valid (Detach p h # s) \ + path_by_shm (Detach p h # s) pa path pb = (\ edge_related path p h \ path_by_shm s pa path pb)" +by (auto dest:path_by_shm_detach1 path_by_shm_detach2) + +lemma flow_by_shm_detach: + "valid (Detach p h # s) \ + flow_by_shm (Detach p h # s) pa pb = (\ path. \ edge_related path p h \ path_by_shm s pa path pb)" +by (auto dest:path_by_shm_detach simp:flow_by_shm_def) + +lemma path_by_shm'_attach1_aux: + "path_by_shm' s' pa path pb \ valid s' \ (s' = Attach p h flag # s) \ + (path_by_shm' s pa path pb) \ + (\ path1 path2 p'. path_by_shm' s pa path1 p' \ path_by_shm' s p path2 pb \ + (p', SHM_RDWR) \ procs_of_shm s h \ path = path2 @ [(p', h, p)] @ path1 ) \ + (\ path1 path2 p' flag'. path_by_shm' s pa path1 p \ path_by_shm' s p' path2 pb \ + (p', flag') \ procs_of_shm s h \ path = path2 @ [(p, h, p')] @ path1 \ flag = SHM_RDWR)" +apply (erule path_by_shm'.induct) +apply (simp, rule impI, rule pbs1', simp) +apply (rule impI, erule impE, clarsimp) +apply (erule disjE) +apply (clarsimp simp:one_flow_shm_attach split:if_splits) +apply (erule disjE, clarsimp) +apply (erule_tac x = path in allE, clarsimp) +apply (erule impE, rule pbs1', erule procs_of_shm_prop2, erule vd_cons, simp) +apply (erule disjE, clarsimp) +apply (rule_tac x = path in exI, rule_tac x = "[]" in exI, rule_tac x = p' in exI, simp) +apply (rule pbs1', drule vt_grant_os, clarsimp) +apply (drule_tac p = pa and p' = p' and p'' = p'' in pbs2', simp+) +apply (drule_tac p = pa and p' = p' and p'' = p'' in pbs2', simp+) + +apply (erule disjE) +apply ((erule exE|erule conjE)+, clarsimp split:if_splits simp:one_flow_shm_attach) +apply (clarsimp simp:one_flow_shm_attach split:if_splits) +apply (erule disjE, clarsimp) +apply (clarsimp) + + +apply (erule conjE)+ + + + +apply (erule conjE, clarsimp simp only:one_flow_shm_attach split:if_splits) +apply simp + + + +lemma path_by_shm_attach1_aux: + "path_by_shm s' pa path pb \ valid s' \ (s' = Attach p h flag # s) \ + path_by_shm s pa path pb \ + (if (pa = p \ flag = SHM_RDWR) + then \ p' flagb path'. (p', flagb) \ procs_of_shm s h \ + path_by_shm s p' path' pb \ path = path' @ [(p, h, p')] + else if (pb = p) + then \ p' path'. path_by_shm s pa path' p' \ path = (p', h, p) # path' \ + (p', SHM_RDWR) \ procs_of_shm s h + else (\ p' flag' patha pathb. path_by_shm s pa patha p \ flag = SHM_RDWR \ + (p', flag') \ procs_of_shm s h \ path_by_shm s p' pathb pb \ + path = pathb @ [(p, h, p')] @ patha) \ + (\ p' patha pathb. path_by_shm s pa patha p' \ (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb pb \ path = pathb @ [(p', h, p)] @ patha))" +proof (induct rule:path_by_shm.induct) + case (pbs1 proc \) + show ?case + proof (rule impI) + assume pre: "valid \ \ \ = Attach p h flag # s" + from pbs1 pre have "proc \ current_procs s" by simp + thus "path_by_shm s proc [] proc \ + (if proc = p \ flag = SHM_RDWR + then \p' flagb path'. + (p', flagb) \ procs_of_shm s h \ path_by_shm s p' path' proc \ [] = path' @ [(p, h, p')] + else if proc = p + then \p' path'. + path_by_shm s proc path' p' \ [] = (p', h, p) # path' \ (p', SHM_RDWR) \ procs_of_shm s h + else (\p' flag' patha pathb. + path_by_shm s proc patha p \ + flag = SHM_RDWR \ + (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pathb proc \ [] = pathb @ [(p, h, p')] @ patha) \ + (\p' patha pathb. + path_by_shm s proc patha p' \ + (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb proc \ [] = pathb @ [(p', h, p)] @ patha))" + by (auto intro:path_by_shm.intros) + qed +next + case (pbs2 \ pa path pb h' pc) + thus ?case + proof (rule_tac impI) + assume p1:"path_by_shm \ pa path pb" and p2: "valid \ \ \ = Attach p h flag # s \ + path_by_shm s pa path pb \ + (if pa = p \ flag = SHM_RDWR + then \p' flagb path'. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' path' pb \ path = path' @ [(p, h, p')] + else if pb = p + then \p' path'. path_by_shm s pa path' p' \ path = (p', h, p) # path' \ (p', SHM_RDWR) \ procs_of_shm s h + else (\p' flag' pathaa pathb. path_by_shm s pa pathaa p \ flag = SHM_RDWR \ + (p', flag') \ procs_of_shm s h \ path_by_shm s p' pathb pb \ + path = pathb @ [(p, h, p')] @ pathaa) \ + (\p' pathaa pathb. path_by_shm s pa pathaa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb pb \ path = pathb @ [(p', h, p)] @ pathaa))" + and p3: "one_flow_shm \ h' pb pc" and p4: "valid \ \ \ = Attach p h flag # s" + + from p2 and p4 have p2': " + path_by_shm s pa path pb \ + (if pa = p \ flag = SHM_RDWR + then \p' flagb path'. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' path' pb \ path = path' @ [(p, h, p')] + else if pb = p + then \p' path'. path_by_shm s pa path' p' \ path = (p', h, p) # path' \ (p', SHM_RDWR) \ procs_of_shm s h + else (\p' flag' pathaa pathb. path_by_shm s pa pathaa p \ flag = SHM_RDWR \ + (p', flag') \ procs_of_shm s h \ path_by_shm s p' pathb pb \ + path = pathb @ [(p, h, p')] @ pathaa) \ + (\p' pathaa pathb. path_by_shm s pa pathaa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb pb \ path = pathb @ [(p', h, p)] @ pathaa))" + by (erule_tac impE, simp) + from p4 have p5: "valid s" and p6: "os_grant s (Attach p h flag)" by (auto intro:vd_cons dest:vt_grant_os) + from p6 have "p \ current_procs s" by simp hence p7:"path_by_shm s p [] p" by (erule_tac path_by_shm.intros) + from p3 p4 have p8: "if (h' = h) + then (pb = p \ pc \ p \ flag = SHM_RDWR \ (\ flagb. (pc, flagb) \ procs_of_shm s h)) \ + (pc = p \ pb \ p \ (pb, SHM_RDWR) \ procs_of_shm s h) \ + (one_flow_shm s h pb pc) + else one_flow_shm s h' pb pc" by (auto simp add:one_flow_shm_attach) + + +(* + have "\ flagb. (pc, flagb) \ procs_of_shm s h + \ \ p' flagb. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' [] pc" + apply (rule_tac x= pc in exI, rule_tac x = flagb in exI, frule procs_of_shm_prop2) + by (simp add:p5, simp add:path_by_shm.intros(1)) + hence p10: "\ path_by_shm s p path pc \ (\p' flagb. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' pc) \ + path_by_shm s pa pc" + using p2' p7 p8 p5 + by (auto split:if_splits dest:path_by_shm.intros(2)) + (* apply (rule_tac x = pb in exI, simp add:one_flow_flows, rule_tac x = flagb in exI, simp)+ *) *) + + from p1 have a0: "(path = []) = (pa = pb)" using pbs_prop2 by simp + have a1:"\pa = p; flag = SHM_RDWR; \ path_by_shm s pa path pb\ \ + \p' flagb path'. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' path' pb \ path = path' @ [(p, h, p')]" + using p2' by auto + have b1: "\pa = p; flag = SHM_RDWR; \ path_by_shm s pa path pc\ \ + \p' flagb path'. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' path' pc \ + (pb, h', pc) # path = path' @ [(p, h, p')]" + + + using p8 a1 p7 p5 a0 + apply (auto split:if_splits elim:path_by_shm_intro4) + apply (rule_tac x = pb in exI, rule conjI, rule_tac x = SHM_RDWR in exI, simp) + apply (rule_tac x = pc in exI, rule conjI, rule_tac x = flagb in exI, simp) + apply (rule_tac x = "[]" in exI, rule conjI) +apply (erule path_by_shm_intro4, simp) + + apply (case_tac "path_by_shm s pa path pb", simp) defer + apply (drule a1, simp+, clarsimp) + apply (rule conjI, rule_tac x = flagb in exI, simp) + apply (rule path_by_shm_ + using p2' p8 p5 + apply (auto split:if_splits dest!:pbs_prop2' simp:path_by_shm_intro4) + apply (drule pbs_prop2', simp) + apply (erule_tac x = pc in allE, simp add:path_by_shm_intro4) + + apply (drule_tac x = "pc" in allE) + + apply simp + + sorry + moreover have "pc = p \ (\p' path'. path_by_shm s pa path' p' \ + (pb, h', pc) # path = path' @ [(p', h, p)] \ (p', SHM_RDWR) \ procs_of_shm s h) \ + (path_by_shm s pa path pc \ \ edge_related path p h)" + using p2' p7 p8 p5 + sorry (* + apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def) *) + moreover have "\pc \ p; pa \ p \ flag \ SHM_RDWR\ \ + (\p' flag' pathaa pathb. path_by_shm s pa pathaa p \ flag = SHM_RDWR \ (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pathb pc \ (pb, h', pc) # path = pathaa @ [(p, h, p')] @ pathb) \ + (\p' pathaa pathb. path_by_shm s pa pathaa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb pc \ (pb, h', pc) # path = pathaa @ [(p', h, p)] @ pathb) \ + (path_by_shm s pa path pc \ \ edge_related path p h)" + using p2' p7 p8 p5 (* + apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def) + apply (rule_tac x = pc in exI, simp add:path_by_shm_intro4) + apply (rule_tac x = flagb in exI, simp) + done *) + sorry + ultimately + show "if (pb, h', pc) # path = [] then pa = pc \ pa \ current_procs s + else path_by_shm s pa ((pb, h', pc) # path) pc \ \ edge_related ((pb, h', pc) # path) p h \ + (if pa = p \ flag = SHM_RDWR + then \p' flagb path'. (p', flagb) \ procs_of_shm s h \ + path_by_shm s p' path' pc \ (pb, h', pc) # path = path' @ [(p, h, p')] + else if pc = p + then \p' path'. path_by_shm s pa path' p' \ + (pb, h', pc) # path = (p', h, p) # path' \ (p', SHM_RDWR) \ procs_of_shm s h + else (\p' flag' pathaa pathb. path_by_shm s pa pathaa p \ flag = SHM_RDWR \ + (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pathb pc \ (pb, h', pc) # path = pathb @ [(p, h, p')] @ pathaa) \ + (\p' pathaa pathb. path_by_shm s pa pathaa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ + path_by_shm s p pathb pc \ (pb, h', pc) # path = pathb @ [(p', h, p)] @ pathaa))" + apply (auto split:if_splits) + using p7 by auto + qed +qed + +lemma path_by_shm_attach1: + "\valid (Attach p h flag # s); path_by_shm (Attach p h flag # s) pa pb\ + \ (if path_by_shm s pa pb then True else + (if (pa = p \ flag = SHM_RDWR) + then (\ p' flagb. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' pb) + else if (pb = p) + then (\ p'. (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s pa p') + else (\ p' flag'. path_by_shm s pa p \ flag = SHM_RDWR \ (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pb) \ + (\ p'. path_by_shm s pa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s p pb) + ) )" +apply (drule_tac p = p and h = h and flag = flag in path_by_shm_attach1_aux) +by auto + +lemma path_by_shm_attach_aux[rule_format]: + "path_by_shm s pa pb \ valid (Attach p h flag # s) \ path_by_shm (Attach p h flag # s) pa pb" +apply (erule path_by_shm.induct) +apply (rule impI, rule path_by_shm.intros(1), simp) +apply (rule impI, simp, rule_tac h = ha in path_by_shm.intros(2), simp) +apply (auto simp add:one_flow_shm_simps) +done + +lemma path_by_shm_attach2: + "\valid (Attach p h flag # s); if path_by_shm s pa pb then True else + (if (pa = p \ flag = SHM_RDWR) + then (\ p' flagb. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' pb) + else if (pb = p) + then (\ p'. (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s pa p') + else (\ p' flag'. path_by_shm s pa p \ flag = SHM_RDWR \ (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pb) \ + (\ p'. path_by_shm s pa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s p pb))\ + \ path_by_shm (Attach p h flag # s) pa pb" +apply (frule vt_grant_os, frule vd_cons) +apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def intro:path_by_shm_attach_aux) +apply (rule_tac p' = p' in Info_flow_trans) +apply (rule_tac p' = p and h = h in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1), simp) +apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def) +apply (rule conjI, rule notI, simp, rule_tac x = flagb in exI, simp) +apply (simp add:path_by_shm_attach_aux) + +apply (rule_tac p' = p' in Info_flow_trans) +apply (rule_tac p' = p in Info_flow_trans) +apply (simp add:path_by_shm_attach_aux) +apply (rule_tac p' = p and h = h in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1), simp) +apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def) +apply (rule conjI, rule notI, simp, rule_tac x = flag' in exI, simp) +apply (simp add:path_by_shm_attach_aux) + +apply (rule_tac p' = p in Info_flow_trans) +apply (rule_tac p' = p' in Info_flow_trans) +apply (simp add:path_by_shm_attach_aux) +apply (rule_tac p' = p' and h = h in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2) +apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def) +apply (rule notI, simp) +apply (simp add:path_by_shm_attach_aux) + +apply (rule_tac p' = p in Info_flow_trans) +apply (rule_tac p' = p' in Info_flow_trans) +apply (simp add:path_by_shm_attach_aux) +apply (rule_tac p' = p' and h = h in path_by_shm.intros(2)) +apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2) +apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def) +apply (rule notI, simp) +apply (simp add:path_by_shm_attach_aux) +done + +lemma path_by_shm_attach: + "valid (Attach p h flag # s) \ path_by_shm (Attach p h flag # s) = (\ pa pb. + path_by_shm s pa pb \ + (if (pa = p \ flag = SHM_RDWR) + then (\ p' flagb. (p', flagb) \ procs_of_shm s h \ path_by_shm s p' pb) + else if (pb = p) + then (\ p'. (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s pa p') + else (\ p' flag'. path_by_shm s pa p \ flag = SHM_RDWR \ (p', flag') \ procs_of_shm s h \ + path_by_shm s p' pb) \ + (\ p'. path_by_shm s pa p' \ (p', SHM_RDWR) \ procs_of_shm s h \ path_by_shm s p pb) + ) )" +apply (rule ext, rule ext, rule iffI) +apply (drule_tac pa = pa and pb = pb in path_by_shm_attach1, simp) +apply (auto split:if_splits)[1] +apply (drule_tac pa = pa and pb = pb in path_by_shm_attach2) +apply (auto split:if_splits) +done + + + +lemma info_flow_shm_detach: + "valid (Detach p h # s) \ info_flow_shm (Detach p h # s) = (\ pa pb. + self_shm s pa pb \ ((p = pa \ p = pb) \ (\ h'. h' \ h \ one_flow_shm s h' pa pb)) \ + (pa \ p \ pb \ p \ info_flow_shm s pa pb) )" +apply (rule ext, rule ext, frule vt_grant_os) +by (auto simp:info_flow_shm_def one_flow_shm_def) + +lemma info_flow_shm_deleteshm: + "valid (DeleteShM p h # s) \ info_flow_shm (DeleteShM p h # s) = (\ pa pb. + self_shm s pa pb \ (\ h'. h' \ h \ one_flow_shm s h' pa pb) )" +apply (rule ext, rule ext, frule vt_grant_os) +by (auto simp:info_flow_shm_def one_flow_shm_def) + +lemma info_flow_shm_clone: + "valid (Clone p p' fds shms # s) \ info_flow_shm (Clone p p' fds shms # s) = (\ pa pb. + (pa = p' \ pb = p') \ (pa = p' \ pb \ p' \ (\ h \ shms. one_flow_shm s h p pb)) \ + (pb = p' \ pa \ p' \ (\ h \ shms. one_flow_shm s h pa p)) \ + (pa \ p' \ pb \ p' \ info_flow_shm s pa pb))" +apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons, clarsimp) +apply (frule_tac p = p' in procs_of_shm_prop2', simp) +sorry (* +apply (auto simp:info_flow_shm_def one_flow_shm_def) +done *) + +lemma info_flow_shm_execve: + "valid (Execve p f fds # s) \ info_flow_shm (Execve p f fds # s) = (\ pa pb. + (pa = p \ pb = p) \ (pa \ p \ pb \ p \ info_flow_shm s pa pb) )" +apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:info_flow_shm_def one_flow_shm_def) + +lemma info_flow_shm_kill: + "valid (Kill p p' # s) \ info_flow_shm (Kill p p' # s) = (\ pa pb. + pa \ p' \ pb \ p' \ info_flow_shm s pa pb )" +apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:info_flow_shm_def one_flow_shm_def) + +lemma info_flow_shm_exit: + "valid (Exit p # s) \ info_flow_shm (Exit p # s) = (\ pa pb. + pa \ p \ pb \ p \ info_flow_shm s pa pb )" +apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons) +by (auto simp:info_flow_shm_def one_flow_shm_def) + +lemma info_flow_shm_other: + "\valid (e # s); + \ p h flag. e \ Attach p h flag; + \ p h. e \ Detach p h; + \ p h. e \ DeleteShM p h; + \ p p' fds shms. e \ Clone p p' fds shms; + \ p f fds. e \ Execve p f fds; + \ p p'. e \ Kill p p'; + \ p. e \ Exit p + \ \ info_flow_shm (e # s) = info_flow_shm s" +apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons) +apply (case_tac e, auto simp:info_flow_shm_def one_flow_shm_def dest:procs_of_shm_prop2) +apply (erule_tac x = h in allE, simp) +apply (drule procs_of_shm_prop1, auto) +done + + +(* +lemma info_flow_shm_prop1: + "\info_flow_shm s p p'; p \ p'; valid s\ + \ \ h h' flag. (p, SHM_RDWR) \ procs_of_shm s h \ (p', flag) \ procs_of_shm s h'" +by (induct rule: info_flow_shm.induct, auto) + +lemma info_flow_shm_cases: + "\info_flow_shm \ pa pb; \p s. \s = \ ; pa = p; pb = p; p \ current_procs s\ \ P; + \s p p' h p'' flag. \s = \; pa = p; pb = p''; info_flow_shm s p p'; (p', SHM_RDWR) \ procs_of_shm s h; + (p'', flag) \ procs_of_shm s h\\ P\ + \ P" +by (erule info_flow_shm.cases, auto) + +definition one_flow_shm :: "t_state \ t_process \ t_process \ bool" +where + "one_flow_shm s p p' \ p \ p' \ (\ h flag. (p, SHM_RDWR) \ procs_of_shm s h \ (p', flag) \ procs_of_shm s h)" + +inductive flows_shm :: "t_state \ t_process \ t_process \ bool" +where + "p \ current_procs s \ flows_shm s p p" +| "\flows_shm s p p'; one_flow_shm s p' p''\ \ flows_shm s p p''" + +definition attached_procs :: "t_state \ t_shm \ t_process set" +where + "attached_procs s h \ {p. \ flag. (p, flag) \ procs_of_shm s h}" + +definition flowed_procs:: "t_state \ t_shm \ t_process set" +where + "flowed_procs s h \ {p'. \ p \ attached_procs s h. flows_shm s p p'}" + +inductive flowed_shm:: "t_state \ t_process \ t_shm set" + +fun Info_flow_shm :: "t_state \ t_process \ t_process set" +where + "Info_flow_shm [] = (\ p. {p'. flows_shm [] p p'})" +| "Info_flow_shm (Attach p h flag # s) = (\ p'. + if (p' = p) then flowed_procs s h + else if () + " + + +lemma info_flow_shm_attach: + "valid (Attach p h flag # s) \ info_flow_shm (Attach p h flag # s) = (\ pa pb. (info_flow_shm s pa pb) \ + (if (pa = p) + then (if (flag = SHM_RDWR) + then (\ flag. (pb, flag) \ procs_of_shm s h) + else (pb = p)) + else (if (pb = p) + then (pa, SHM_RDWR) \ procs_of_shm s h + else info_flow_shm s pa pb)) )" +apply (frule vd_cons, frule vt_grant_os, rule ext, rule ext) +apply (case_tac "info_flow_shm s pa pb", simp) + +thm info_flow_shm.cases +apply (auto split:if_splits intro:info_flow_shm.intros elim:info_flow_shm_cases) +apply (erule info_flow_shm_cases, simp, simp split:if_splits) +apply (rule_tac p = pa and p' = p' in info_flow_shm.intros(2), simp+) +apply (rule notI, erule info_flow_shm.cases, simp+) +pr 5 +*) +lemmas info_flow_shm_simps = info_flow_shm_other (* info_flow_shm_attach *) info_flow_shm_detach info_flow_shm_deleteshm + info_flow_shm_clone info_flow_shm_execve info_flow_shm_kill info_flow_shm_exit + + + + + + +end + +end \ No newline at end of file