如何根據(jù)log 信息修改SELinux 權(quán)限
當(dāng)出現(xiàn) SELinux
權(quán)限不足時,可根據(jù)LOG 信息提示進(jìn)行相應(yīng)的修改。下面介紹如何根據(jù) kernel log
來查看信息
1. disable selinux
在終端下
su
setenforce 0
該操作主要是為了禁用系統(tǒng)SELinux
序无,讓權(quán)限暫時通過试幽。但是依然是會輸出 SELinux
校驗時的LOG。后面根據(jù)輸出的LOG 進(jìn)行相應(yīng)的處理。
2. 查看kernel log
復(fù)現(xiàn)問題垢粮,導(dǎo)出 kernel log
.
或者 adb shell
su
之后輸入 cat /dev/kmsg | grep avc
在控制臺輸出關(guān)鍵信息
kernel
日志的輸出在 /dev/kmsg
節(jié)點下,avc
是 SELinux
打印的信息
如:
5,4978,791423968,-;audit: type=1400 audit(1556096333.959:26): avc: denied { write } for pid=5106 comm="Log_LogStrategy" name="Logs_Collector" dev="mmcblk0p40" ino=16321 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4979,791424019,-;audit: type=1400 audit(1556096333.959:27): avc: denied { add_name } for pid=5106 comm="Log_LogStrategy" name="amefrktoukgokiph_20190424165853.zip" scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4980,791424176,-;audit: type=1400 audit(1556096333.959:28): avc: denied { create } for pid=5106 comm="Log_LogStrategy" name="amefrktoukgokiph_20190424165853.zip" scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4981,791425437,-;audit: type=1400 audit(1556096333.959:29): avc: denied { write } for pid=5106 comm="Log_LogStrategy" path="/data/Logs_Collector/amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4982,797691545,-;audit: type=1400 audit(1556096340.229:30): avc: denied { remove_name } for pid=5086 comm="xtc.systemagent" name="amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4983,797691614,-;audit: type=1400 audit(1556096340.229:31): avc: denied { rename } for pid=5086 comm="xtc.systemagent" name="amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4984,797693717,-;audit: type=1400 audit(1556096340.229:32): avc: denied { unlink } for pid=5086 comm="xtc.systemagent" name="1556096340234" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
3. 修改te 文件
- 3.1 找到對應(yīng)的
domain
如:
scontext=u:r:system_app:s0
domain
為 system_app
靠粪, 所以需要修改 system/sepolicy/system_app.te
文件
- 3.2 找到 target 和 Object Class
如:
tcontext=u:object_r:system_data_file:s0 tclass=dir
target
為 system_data_file
, object class
為 dir
- 3.3 找到缺失的權(quán)限
如:
denied { add_name }
缺失的權(quán)限為: add_name
- 3.4 最后整合整個缺失的權(quán)限蜡吧,統(tǒng)一處理
最后針對上面的權(quán)限提示修改的 system/sepolicy/system_app.te
為,增加如下內(nèi)容:
allow system_app system_data_file:dir { add_name remove_name rw_dir_perms };
allow system_app system_data_file:file { create rename unlink rw_file_perms };
格式(分號結(jié)尾)
allow scontext tcontext:tclass { perm };
4. 檢查是否違反了 neverallow
可以先進(jìn)行嘗試編譯占键,若有違反 neverallow
的 SELinux
定義昔善,會編譯不通過,同時會提示哪個 te
文件中定義的 neverallow
沖突了畔乙。
如上面的修改會導(dǎo)致 system/sepolicy/app.te
文件中的 neverallow
規(guī)則有沖突君仆。
原先沖突的 nerverallow
定義為:
# Write to system-owned parts of /data.
# This is the default type for anything under /data not otherwise
# specified in file_contexts. Define a different type for portions
# that should be writable by apps.
neverallow { appdomain} system_data_file:dir_file_class_set
{ create write setattr relabelfrom relabelto append unlink link rename };
這里定義了不允許 system_data_file
的 target
進(jìn)行 create
write
unlink
等操作
此時解決方法是,需要過濾去除掉我們需要的 domain
進(jìn)行修改如下:
neverallow { appdomain -system_app }
system_data_file:dir_file_class_set
{ create write setattr relabelfrom relabelto append unlink link rename };
加上 -system_app
的排除語法牲距。
5. 重編系統(tǒng)
至此根據(jù) kernel log
信息提取權(quán)限完成返咱,重新編譯系統(tǒng)。