android selinux报avc denied权限和编译报neverallow解决方案

avc: denied { read } for name="present" dev="sysfs" ino=42693 scontext=u:r:hal_health_default:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1

denied {xxx}: 表示缺少什么权限

scontext:表示谁缺少权限

tcontext:表示对那些文件缺少权限:

tclass:表示什么文件类型缺少权限

修改公式如下:

通常需要在${scontext}.te添加 allow scontext tcontext:tclass denied

带入内容:修改hal_health_default.te

allow hal_health_default sysfs:fie { read };

allow hal_health_default sysfs:fie { open};

RK平台te文件一般在device/rockchip/common/sepolicy/下 类似上面的修改即可

如果编译时报错 提示

复制代码
libsepol.report_failure: neverallow on line 444 of system/sepolicy/public/domain.te (or line 12990 of policy.conf) violated by allow tee device:chr_file { read write };
libsepol.check_assertions: 1 neverallow failures occurred
Error while expanding policy

报错原因也比较直接,就是domain域中指明的规则,我们先看下为什么会报错吧

直接打开编译报错中那个domain.te,路径:system/sepolicy/public/domain.te,找到和我们添加的部分,搜索"device:chr_file",可以找到如下内容了,看一下就明白了,不允许我们这样修改了。

复制代码
# Don't allow raw read/write/open access to generic devices.
# Rather force a relabel to a more specific type.
neverallow domain device:chr_file { open read write };

以下是实例,我这边提示system_app权限异常

复制代码
avc: denied { read } for name="u:object_r:serialno_prop:s0" dev="tmpfs" ino=12228 scontext=u:r:system_app:s0 tcontext=u:object_r:serialno_prop:s0 tclass=file permissive=1

在device/rockchip/common/sepolicy/system_app.te下修改

复制代码
allow system_app serialno_prop:file { open read getattr };

提示neverallow错误 找到对应的domain.te

system/sepolicy/public/domain.te

复制代码
# a few whitelisted domains.
neverallow {
  domain
  -adbd
  -dumpstate
  -hal_drm
  -hal_cas
  -init
  -mediadrmserver
  -recovery
  -shell
  -system_server
} serialno_prop:file r_file_perms;

查看到serialno_prop:file,其实直接将domain修改为-domain即可

复制代码
neverallow {
  -domain
  -adbd
  -dumpstate
  -hal_drm
  -hal_cas
  -init
  -mediadrmserver
  -recovery
  -shell
  -system_server
} serialno_prop:file r_file_perms;
相关推荐
墨染天姬43 分钟前
【android 驱动开发九】生产者-消费者模型
android·驱动开发
android_xc3 小时前
Android Studio适配butterknife遇到的坑
android·ide·android studio·butterknife
2501_915918413 小时前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张3 小时前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview
米豆同学5 小时前
SufraceFlinger图像合成原理(3)-SurfaceFlinger中Layer的创建和销毁
android
米豆同学5 小时前
SufraceFlinger图像合成原理(2)-SurfaceFlinger与应用进程间的通信
android
用户2018792831675 小时前
uses-library:系统应用报NoClassDefFoundError问题
android
叽哥5 小时前
Kotlin学习第 4 课:Kotlin 函数:从基础定义到高阶应用
android·java·kotlin
mg6685 小时前
安卓玩机工具----安卓“搞机工具箱”最新版 控制手机的玩机工具
android·智能手机
诺诺Okami5 小时前
Android Framework- Activity启动2
android