转自:https://blog.csdn.net/xiaoxiangyuhai/article/details/76270294

1. 确认 seLinux导致权限问题

1.1 标志性log 格式:

avc: denied  { 操作权限 }  for pid=7201 comm=“进程名”  scontext=u:r:源类型:s0  tcontext=u:r:目标类型:s0  tclass=访问类别  permissive=0

1.2 举例:

Kenel log:

avc: denied { execheap } for pid=7201 comm="com.baidu.input" scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0

Logcat log:

com.baidu.input: type=1400audit(0.0:29): avc: denied { execheap } for scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0

1.3 方法1:adb在线修改


关闭 seLinux:

打开seLinux:

Enforcing:seLinux已经打开;        

Permissive:seLinux已经关闭;

1.4 方法2: 从kernel中彻底关闭 (用于开机初始化时的seLinux权限问题,要重编bootimage)


修改LINUX/android/kernel/arch/arm64/configs/XXXdefconfig文件(找相应config文件)
去掉CONFIG_SECURITY_SELINUX=y 的配置项

2. 在sepolicy中添加相应权限
2.1 修改依据:

log 信息:

avc: denied  { 操作权限  }  for pid=7201  comm=“进程名”  scontext=u:r:源类型:s0  tcontext=u:r:目标类型:s0  tclass=访问类别  permissive=0

2.2 修改步骤:

找相应的“源类型.te ”文件


有两个位置可能存在相应的te文件:


位置一:LINUX/android/external/sepolicy
位置二:LINUX/android/device/qcom/sepolicy/common 


2.3 按如下格式在该文件中添加: 

allow  源类型 目标类型:访问类别 {权限};

2.4 举例

Kernel Log:

avc: denied { execheap } for pid=7201 comm="com.baidu.input" scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0

修改:

在LINUX/android/external/sepolicy/untrusted_app.te 中添加:

allow untrusted_app untrusted_app:process { execheap };

备注:

在这个例子中,由于源类型和目标类型都是untreated_app, 所以也可以写成:

allow untrusted_app self:process { execheap };

3. 添加权限后的neverallowed冲突

3.1 编译报错:

libsepol.check_assertion_helper: neverallow on line xxx ofexternal/sepolicy/domain.te ……

3.2 原因:

新添加的sepolicy项目违反了domain.te 中规定的的总策略原则。所以该条权限策略不能添加,如果强行添加的话有CTS测试失败的风险。

3.3 解决方法:

1.从运行log中找到要访问的目标名称,一般是name字段后的名称
avc: denied { read write } for pid=303 comm="mediaserver" name="tfa9890"dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0tcontext=u:object_r:device:s0tclass=chr_file permissive=0

2.找到相应的*_contexts文件。

  一般有file_contexts, genfs_contexts,  property_contexts,  service_contexts 等文件

3.在contexts文件中指定要访问的目标为一个“源类型 ”有权限访问的“目标类型”
  如:在file_contexts中添加: /dev/tfa9890     u:object_r:audio_device:s0

3.4 举例

添加权限:

在mediaserver.te中添加allow mediaserver device:chr_file { read write open};


编译报错:

libsepol.check_assertion_helper: neverallow on line 258 ofexternal/sepolicy/domain.te (or line 5252 of policy.conf) violated byallow mediaserver device:chr_file { read write open};


违反了domain.te 258的:

neverallow {domain –unconfineddomain –ueventd } device:chr_file { open read write}


运行Log:

avc: denied { read write } for pid=303 comm="mediaserver"name="tfa9890" dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0tclass=chr_file permissive=0

修改步骤:
1.目标名称是: tfa9890, 其在系统中的路径是: /dev/tfa9890,  是audio相关的设备文件
2.源类型是mediaserver, 在mediaserver.te 文件中发现其具有 audio_device 目标类型的权限
3.所以在file_contexts 中添加 “/dev/tfa9890        u:object_r:audio_device:s0” 可以解决问题
 

更多相关文章

  1. Android简单的利用MediaRecorder进行录音
  2. Android(安卓)字体设置-Typeface讲解
  3. android 5.0 以上获取栈顶应用包名以及程序锁的实现
  4. Android(安卓)studio添加按钮点击进入下一页
  5. Android中Paint字体属性的一些设置
  6. SharedPreferences存与取,
  7. android 仿微信多图选择器(带预览、照相功能)
  8. android studio 构建maven私有库环境搭建
  9. Android(安卓)photoview使用遇到Failed to resolve: com.github.

随机推荐

  1. Running GPS positioning in a backgroun
  2. android 测试Activity,Content Provider,
  3. [android]gsm smsmessage 类部分详解
  4. Android(安卓)Menu菜单的编写及事件响应
  5. android retrofit2 如何多文件上传
  6. android中读取assets中的文件
  7. 通过adb shell命令查看当前与用户交互的
  8. Android(安卓)布局学习
  9. android 比较靠谱的图片压缩
  10. android 判断当前application 是在前台还