1.概述
SELinux全称是Security Enhanced Linux,它拥有一个灵活而强制性的访问控制结构,旨在提高Linux系统的安全性,提供强健的安全保证,可防御未知攻击
2.问题定位
通过指令cat /proc/kmsg | grep denied,或者kernel的Log中定位到标志性log(如:logcat |grep avc),出错信息如下所示:
avc: denied { create } for name="smdl76259125.tmp.asec" scontext=u:r:vold:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file
3.权限关闭方法
3.1 adb命令方式
可用getenforce获取当前seLinux状态, 若为Enforcing(表示已打开),若为Permissive(表示已关闭)。
setenforce 命令进行权限设置。
getenforce; //获取当前seLinux状态
setenforce 1; //打开seLinux
setenforce 0; //关闭seLinux
3.2 修改kernel配置
修改LINUX/android/kernel/arch/arm64/configs/xxx_defconfig文件(xxx一般为产品名), 去掉CONFIG_SECURITY_SELINUX=y 的配置项
4. 解决方法
一般以.te为后缀的文件都在external/sepolicy/ 或者device/ic_product/xxxx-commm/sepolicy/ 下,将一下两种方式得到的内容添加到对应的文件下即可解决avc权限问题。
4.1 工具生成
在Ubuntu环境下安装audit2allow工具,实例如下:
1将avc出错日志保存为一个文件avc.
W/vold ( 338): type=1400 audit(0.0:34): avc: denied { create } for name="smdl76259125.tmp.asec" scontext=u:r:vold:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file
W/vold ( 338): type=1400 audit(0.0:35): avc: denied { open } for name="smdl76259125.tmp.asec" dev="tmpfs" ino=24405 scontext=u:r:vold:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file
W/vold ( 338): type=1400 audit(0.0:36): avc: denied { getattr } for path="/mnt/secure/asec/smdl76259125.tmp.asec" dev="tmpfs" ino=24405 scontext=u:r:vold:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file
W/vold ( 338): type=1400 audit(0.0:37): avc: denied { rename } for name="smdl76259125.tmp.asec" dev="tmpfs" ino=24405 scontext=u:r:vold:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file
W/m.android.phone( 1148): type=1400 audit(0.0:38): avc: denied { getattr } for path="/mnt/asec/com.baidu.appsearch-2/base.apk" dev="dm-0" ino=12 scontext=u:r:radio:s0 tcontext=u:object_r:asec_apk_file:s0 tclass=file
W/m.android.phone( 1148): type=1400 audit(0.0:39): avc: denied { read } for name="base.apk" dev="dm-0" ino=12 scontext=u:r:radio:s0 tcontext=u:object_r:asec_apk_file:s0 tclass=file
W/m.android.phone( 1148): type=1400 audit(0.0:40): avc: denied { open } for name="base.apk" dev="dm-0" ino=12 scontext=u:r:radio:s0 tcontext=u:object_r:asec_apk_file:s0 tclass=file
W/installd( 257): type=1400 audit(0.0:41): avc: denied { getattr } for path="/mnt/secure/asec/com.baidu.appsearch-2.asec" dev="tmpfs" ino=24405 scontext=u:r:installd:s0 tcontext=u:object_r:vold_tmpfs:s0 tclass=file123456789
2 执行命令audit2allow -i avc.txt -o avc.te,就会生成avc.te文件
#============= installd ==============
allow installd vold_tmpfs:file getattr;
#============= radio ==============
allow radio asec_apk_file:file { read getattr open };
#============= vold ==============
allow vold vold_tmpfs:file { rename create open getattr };`
在对应的te文件中加上生成avc.te中的内容即可解决权限问题
4.2 套用公式
例如:
avc: denied { execmem } for pid=22992 comm="rild" scontext=u:r:rild:s0 tcontext=u:r:rild:s0 tclass=process
于是得到:
allow rild rild:process execmem