android之selinux问题解决记录 一

简述

主要是使用第三方应用来读写usb设备中的mode值,遇到的selinux权限问题的处理;

流程分析

当logcat日志中有avc:denied关键字段打印时,说明存在selinux问题

1.读取

读取配置中的mode值时,第一次出现了日志信息如下所示

avc: denied { open } for path="/sys/devices/platform/soc/xxxxxx.ssusb/mode" dev="sysfs" 
ino=40085 scontext=u:r:untrusted_app:s0:c78,c256,c512,c768 
tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 app=com.example.test

配置allow语句

allow untrusted_app sysfs:file open;

第二次读取时,日志打印信息如下所示,说明还是需要配置其他selinux权限

avc: denied { getattr } for path="/sys/devices/platform/soc/xxxxxx.ssusb/mode" dev="sysfs" ino=40085 scontext=u:r:untrusted_app:s0:c78,c256,c512,c768 
tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 app=com.example.test

增加getattr权限,配置allow语句

allow untrusted_app sysfs:file { open getattr };

再次执行读取时,此时没有avc相关的报错,读取ok。

2.写入

执行写入数据时,有logcat 日志打印如下所示

 avc: denied { write } for name="mode" dev="sysfs" ino=40156 scontext=u:r:untrusted_app:s0:c78,c256,c512,c768 
 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 app=com.example.test

增加write权限,配置allow语句

allow untrusted_app sysfs:file { open getattr write };

3.总结

使用直观的语句表达如下

 avc: denied { 操作权限 } for name="mode" dev="sysfs" ino=40156 scontext=u:r:主体type:s0:c78,c256,c512,c768 tcontext=u:object_r:客体type:s0 tclass=客体类别 permissive=0 app=com.example.test

使用allow语句描述如下

allow 主体type 客体type:客体类别 {操作权限}

需要将allow语句放到untrusted_app.te中

在这里插入图片描述需要处理的是以下四个文件
./private/untrusted_app.te
./public/untrusted_app.te
./prebuilts/api/29.0/private/untrusted_app.te
./prebuilts/api/29.0/public/untrusted_app.te
其中29代表当前系统版本,
在以上的te中加入

allow untrusted_app sysfs:file { open getattr write };

编译验证

make selinux_policy
将编译好的文件push到对应的设备目录下

  adb push ./out/target/product/xxxxxx/system/etc/selinux/* /system/etc/selinux/
  adb push ./out/target/product/xxxxxx/vendor/etc/selinux/* /vendor/etc/selinux/
  adb push ./out/target/product/xxxxxx/system/product/etc/selinux/* /system/product/etc/selinux/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值