SELinux策略规则

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
根据日志缺失哪个进程访问哪个资源,需要哪些权限,当前进程是否已经创建了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等操作 。
注:要确认对应的进程访问系统资源是否正常,是否必要 。
头条号:怀揣梦想的自由开发者
公众号:风宇软件
B站:猫猫侠的正义

【SELinux策略规则】


    推荐阅读