环境平台:msm8953、android7.1.2
实例报错:
avc: denied { read write } for pid=3944 comm="handsetpowerlib" name="xxxxx" dev="tmpfs" ino=5545 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
可得:主体untrusted_app在对客体类别为chr_file、客体为device操作read write时权限不够被拒!
1、为了修改后不会提升其他所有是device类型的设备权限,首先打算修改/dev/xxxxx的类型type,由device改为xxxxx_device,后面只需提升untrusted_app对type为xxxxx_device的设备权限即可。即:
device/qcom/sepolicy/common/device.te增加这个新类型:
type xxxxx_device,dev_type;
device/qcom/sepolicy/common/file_contexts增加定义设备的安全上下文:
/dev/xxxxx u:object_r:xxxx_device:s0
2、在相应的主体文件device/qcom/sepolicy/common/untrusted_app.te中aloow相应权限:
allow untrusted_app xxxx_device:chr_file { open read write getattr };
3、此时编译测试发现,仍然报错,多半就是MLS检查导致的,需要设置untrusted_app为type充当domain时越过MLS检查,system/sepolicy/untrusted_app.te中修改:
type untrusted_app,domain;为type untrusted_app,domain,mlstrustedsubject;
4、如上,出现了多少avc:denied...就增加多少主体、客体、客体类别对应的allow语句即可。