当前位置:   article > 正文

添加selinux权限_selinux权限添加

selinux权限添加

一、根据报错添加selinux权限

一般在logcat中报以下错误

avc: denied { read write } for comm="AdaptorThread" name="video31" dev="tmpfs" ino=18586 scontext=u:r:system_app:s0 tcontext=u:object_r:video_device:s0 tclass=chr_file permissive=0

分析:

缺少的权限:{ read write }

谁缺少的权限:system_app

对哪个类型缺少的权限:video_device

什么格式的文件:chr_file

1.找到system_app.te文件

2.添加:

allow system_app video_device:chr_file { read write };

二、如果编译报错

到system/sepolicy/public目录下,找到video_device,发现不允许video_devices类型的chr_file有read write的权限

neverallow appdomain{

    video_devices

}:chr_file { read write };

 方法:1.将文件绑定其他现有的类型        2.定义其他类型,与文件绑定,再给予权限

2.1将文件绑定其他现有的类型 

1.找到对应的文件

根据以下的报错,在日志中搜索video31

avc: denied { read write } for comm="AdaptorThread" name="video31" dev="tmpfs" ino=18586 scontext=u:r:system_app:s0 tcontext=u:object_r:video_device:s0 tclass=chr_file permissive=0

找到相应的文件是/dev/video31

2.找到相近的文件,参考绑定类型

在sepolicy/file_contexts文件中找到/dev/video31,查看其他相近的文件绑定的类型,参考修改/dev/video31的绑定类型。

/dev/video31        u:object_r:绑定的类型:s0

注意:

        1./dev/video31不能随意绑定类型

        2.绑定的类型要满足在system_app.te至少有allow system_app 绑定的类型:chr_file { read write };

        3.留意绑定的类型可能导致没有之前的权限,可能会出现其他功能不正常。(举个例子,/dev/video31之前绑定了A类型在xx.te文件有Q权限,绑定之后的B类型可能在xx.te文件没有Q权限,可能导致其他功能不正常)     

3.测试  

  1. setenforce 1        //打开selinux
  2. chcon u:object_r:绑定类型:s0 /dev/video31 //设置/dev/video31的绑定类型
  3. ls -Z /dev/video31 //查看/dev/video31的绑定类型

测试功能是否正常 

2.2定义其他类型,与文件绑定,再给予权限

1.定义其他类型

在 sepolicy目录下知道定义video_device类型的文件,定义一个其他类型(type开头是定义类型)

2.与文件绑定

在 sepolicy/file_contexts文件中找到/dev/video31,修改为定义的类型

3.给予权限

1.加上报的权限问题,在 system_app.te添加

allow system_app 定义的类型:chr_file { read write };

2.在加上之前video_devices类型拥有的权限

建议用grep -nr video_devices,可以快速找到其拥有的权限

4.编译测试

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/961961
推荐阅读
相关标签
  

闽ICP备14008679号