根据“avc: denied“的log添加了selinux权限还是提示没有相应的权限问题

 在高通10.0的平台上遇到自己添加的设备节点在app调用失败的问题,通过过滤”avc: denied”查看log知道是缺少selinu权限,但根据log给相应的设备节点添加了selinux权限后,还提示却相应的selinux权限,出问题时的log如下:

07-18 02:55:14.619 13924 13924 W xxx.activity: type=1400 audit(0.0:527): avc: denied { read write } for name="spidev" dev="tmpfs" ino=14885 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=0

根据log添加selinux权限如下:

+++ b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/device.te
@@ -167,3 +167,7 @@ type nlcm_dev,dev_type;
+
+# for spidev
+type spidev_device, dev_type;

diff --git a/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/file_contexts b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/file_contexts
index f470634..7773b53 100644
--- a/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/file_contexts
+++ b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/file_contexts
@@ -94,6 +94,8 @@
 /dev/CM30                                       u:object_r:nlcm_dev:s0
 /dev/i2c-6                                      u:object_r:nlcm_dev:s0
 /dev/softd                                      u:object_r:nlcm_dev:s0
+/dev/spidev                                     u:object_r:spidev_device:s0


diff --git a/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/untrusted_app_25.te b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/untrusted_app_25.te
new file mode 100644
index 0000000..c910ac5
--- /dev/null
+++ b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/untrusted_app_25.te
@@ -0,0 +1,5 @@
+# for spidev
+allow untrusted_app_25 spidev_device:chr_file rw_file_perms;

理论上 加了 rw_file_perms,这个权限,已经包含了 读 写的 全部权限, 但是 实际情况是 还是 有 avc: denied

07-18 03:38:14.619 13924 13924 W xxx.activity: type=1400 audit(0.0:527): avc: denied { read write } for name="spidev" dev="tmpfs" ino=14885 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:spidev_device:s0 tclass=chr_file permissive=0

这个 write 权限还是有问题, 打出的log中正常的情况是没有“c512,c768”的。selinux主要采用了两种强制访问的方法: TE  MLS,这个就是 和MLS 相关的,具体的可在网上搜selinux MLS了解。

在selinux中共定义了三个拥有巨大权限的attribute分别是mlstrustedsubject、mlstrustedobject、unconfineddomain,被分类到mlstrustedsubject的type在充当主体domain是可以越过MLS检查,被分类到mlstrustedobject的type在充当客体时可以越过MLS检查,被分到unconfineddomain的type则拥有所有权限可对客体进行任意操作。

具体的修改如下:

+++ b/LA.UM.8.6.2/LINUX/android/device/qcom/sepolicy/vendor/common/device.te
@@ -167,3 +167,7 @@ type nlcm_dev,dev_type;
+
+# for spidev
+type spidev_device, dev_type, mlstrustedobject;

 

本文地址:https://blog.csdn.net/u010867436/article/details/107462532

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐