Android4.4版本后,google 默認啟用了SElinux, 并會把SELinux 審查異常打印在kernel log 或者 android log(L 版本)中,對應的關鍵字是: "avc: denied" 或者"avc: denied"。
格式
avc: denied { 操作權限 } for pid=7201 comm=“進程名” scontext=u:r:源類型:s0 tcontext=u:r:目標類型:s0 tclass=訪問類型 permissive=0
scontext和tcontext都是安全上下文,分別稱為主體和客體,主體一般都是進程,客體則是主體訪問的資源。
例如:
audit: type=1400 audit(1113.763:288): avc: denied { write } for pid=328 comm="fastbootd" name="mmcblk0p29" dev="tmpfs" ino=7915 scontext=u:r:fastbootd:s0 tcontext=u:object_r:mmcblk_device:s0 tclass=blk_file permissive=1#fastbootd進程對mmcblk_device類型的blk_file缺少write權限。處理方式
提取所有的avc LOG,可以使用adb shell "cat /proc/kmsg | grep avc" > avc.txt
根據(jù)日志缺失哪個進程訪問哪個資源,需要哪些權限,當前進程是否已經(jīng)創(chuàng)建了policy文件(一般是進程process.te),如果沒有且父進程無須訪問時可以新建
文件主要在
./device/rockchip/common/sepolicy/system/sepolicy下。
如果是新文件,按下面格式添加后再添加策略。
type idmap, domain;type idmap_exec, exec_type, file_type;domain_auto_trans(zygote, idmap_exec, idmap);增加策略
進程名: comm="fastbootd" fastbootd
缺少什么權限: { write }權限,
誰缺少權限: scontext=u:r:fastbootd:s0 fastbootd
對哪個資源缺少權限: tcontext=
u:object_r:mmcblk_device:s0 mmcblk_device
什么類型的資源: tclass=blk_file
解決方法:在fastbootd.te文件(若沒有則添加)加入內容:
allow fastbootd mmcblk_device:blk_file { read write getattr open ioctl };
即允許fastbootd對mmcblk_device類型的blk_file進行read/write/ioctl等操作。
注:要確認對應的進程訪問系統(tǒng)資源是否正常,是否必要。
頭條號:懷揣夢想的自由開發(fā)者
公眾號:風宇軟件
B站:貓貓俠的正義