我在Android 4.4.4上運行並有兩個進程。兩個處理的安全上下文包括: -防止untrusted_app訪問數據庫
com.example.contentproviderexample having security context --> u:r:hm_phonebookaccess_app:s0
com.example.contentprovideruser having security context --> u:r:untrusted_app:s0
com.example.contentproviderexample是內容提供商,並且具有作爲安全上下文數據庫 -
mydb --> u:object_r:hm_phonebookaccess_data_file:s0
mydb-journal --> u:object_r:hm_phonebookaccess_data_file:s0
上述安全上下文已經使用設置以下規則 -
type hm_phonebookaccess_app, domain;
app_domain(hm_phonebookaccess_app)
allow hm_phonebookaccess_app dalvikcache_data_file:file { write setattr };
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file { read getattr open };
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir setattr;
allow hm_phonebookaccess_app zygote:unix_stream_socket { getopt getattr };
allow hm_phonebookaccess_app apk_data_file:dir getattr;
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir { write create add_name };
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file { write create setattr };
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir search;
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir { read open };
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file lock;
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir remove_name;
allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file unlink;
allow installd hm_phonebookaccess_data_file:lnk_file create;
在運行時,我正在setenforce爲1
我的目標是防止任何屬於域 - > untrusted_app的進程訪問屬於域的數據庫-u:r:hm_phonebookaccess_app:s0
注意:內容提供程序導出爲true。
在seapp_contexts,以下條目已取得: -
user=_app domain=hm_phonebookaccess_app name=com.example.contentproviderexample type=hm_phonebookaccess_data_file
我的觀察是,在強制模式,進程「com.example.contentprovideruser」能夠訪問數據庫。
有沒有什麼辦法可以防止「untrusted_app」域訪問該數據庫?
感謝和問候, Souvik
有幾個問題:1)您是否確認運行設備上的'sepolicy'二進制文件反映了您的新域和規則?爲了檢查確定,我建議使用'adb'將它從運行設備上打印出來,並將其加載到開發包中的'apol'上。 2)你有沒有嘗試在你的類型執行規則中引入一個'neverallow'?在編譯期間,如果策略中存在不一致,則會導致錯誤並停止。出現錯誤時,它應該幫助您找到允許'untrusted_app'訪問'hm_phonebookaccess_app'的'allow'規則。 – 2015-04-20 15:14:17