当前位置: 首页 > news >正文

Android selinux 权限 修复 avc: denied


selinux
{
getenforce 串口命令查看权限

selinux=0 内核关闭 selinux
selinux=1 内核打开 selinux

android 系统 两种模式
androidboot.selinux=permissive 宽松
androidboot.selinux=enforcing 强制

getenforce
setenforce 0 命令,让 selinux 处于宽容模式

sn: getprop ro.serialno
mac: cat /sys/class/net/wlan0/address


相关文件
{
修改权限最好在device下客制化修改
device/xxx/xxx/sepolicy/

原始code的权限最好不要动
system/sepolicy/public/
system/sepolicy/prebuilts/api/xx/public/

}

设置文件 device/softwinner/eros-p1/BoardConfig.mk
BOARD_KERNEL_CMDLINE += selinux=1 androidboot.selinux=permissive androidboot.dtbo_idx=0,1,2
BOARD_KERNEL_CMDLINE += selinux=1 androidboot.selinux=enforcing androidboot.dtbo_idx=0,1,2

权限报错,类似提示
{
init: Unable to set property 'persist.standby.mode' to '1' from uid:1000 gid:1000 pid:7184: SELinux permission check failed
[ 2.047169] selinux: avc: denied { set } for scontext=u:r:vendor_init:s0 tcontext=u:object_r:default_prop:s0 tclass=property_service permissive=1
[ 2.064680] selinux: avc: denied { set } for scontext=u:r:vendor_init:s0 tcontext=u:object_r:config_prop:s0 tclass=property_service permissive=1
[ 2.081488] selinux: avc: denied { set } for scontext=u:r:vendor_init:s0 tcontext=u:object_r:exported2_default_prop:s0 tclass=property_service permissive=1
[ 153.759885] selinux: avc: denied { set } for property=persist.standby.mode pid=3928 uid=1000 gid=1000 scontext=u:r:system_app:s0 tcontext=u:object_r:default_prop:s0 tclass=property_service permissive=1
[ 178.937290] selinux: avc: denied { set } for property=settings.notifi.count pid=2183 uid=1000 gid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_prop:s0 tclass=property_service permissive=1
avc: denied { write } for name="light" dev="sysfs" ino=14600 scontext=u:r:system_server:s0 tcontext=u:object_r:sysfs_gpio:s0 tclass=file permissive=0
}

方法一 修改
vendor/aw/homlet/sepolicy/property_contexts
system/sepolicy/.../property_contexts
{
system_prop 对应的只能在 系统层app才能使用
ro.datamax.RomVersion u:object_r:system_prop:s0
persist.ota.server u:object_r:system_prop:s0
persist.standby.mode u:object_r:system_prop:s0
}


方法二
{
抓取相关log,提取权限名称。
dmesg|grep avc
获取所有的avc 权限问题
logcat|grep avc: > /sdcard/avc.log

linux工具 需要先 source build/envsetup.sh & lunch
audit2allow -i avc.log

源码中使用工具生成
{
#============= hal_wifi_default ==============
allow hal_wifi_default vendor_data_file:file getattr;

#============= init ==============
allow init settings_service:service_manager find;
allow init system_file:file execute_no_trans;

#============= system_app ==============
allow system_app system_data_file:file { write read create };
}
根据生成的条件修改 te文件

system/sepolicy/public/system_app.te
allow system_app system_data_file:dir { add_name write };
allow system_app system_data_file:file { create open write };

报错提示:
libsepol.report_failure: neverallow on line 458 of system/sepolicy/public/app.te (or line 8332 of policy.conf) violated by allow system_app system_data_file:dir { write };
libsepol.report_failure: neverallow on line 458 of system/sepolicy/public/app.te (or line 8332 of policy.conf) violated by allow system_app system_data_file:file { write create };
libsepol.check_assertions: 2 neverallow failures occurred

找到 app.te 中对应的 458 等行修改
{
原始:
neverallow appdomain system_data_file:dir_file_class_set
{ create write setattr relabelfrom relabelto append unlink link rename };

修改后 1
neverallow appdomain -system_app system_data_file:dir_file_class_set
{ create write setattr relabelfrom relabelto append unlink link rename };

修改后 2
neverallow appdomain system_data_file:dir_file_class_set
{ setattr relabelfrom relabelto append unlink link rename };
}

报错提示:
Files system/sepolicy/prebuilts/api/28.0/public/app.te and system/sepolicy/public/app.te differ
对比两个文件输入的字符,一个空格都要一致

编译测试
make selinux_policy
}
}

http://www.cnnetsun.cn/news/100302.html

相关文章:

  • vue基于springboot的基于建筑物识别的无人驾驶车辆路径规划系统
  • 启天 M 系列 Smart Power On/Fast boot 置灰?2 步解锁修改权限!
  • 告别繁琐问卷设计!百考通AI智能助手,5分钟生成专业调研问卷
  • 百考通AI:你的智能学术助手,让毕业论文写作化繁为简
  • IntelliJ IDEA 2025.3 正式发布
  • MyBatis-Flex 来了!完爆MyBatis-Plus?
  • 神经紧张素受体SORT1
  • 高盐高铵根工业废水去除重金属
  • 某211高校讲师晒工资条,网友:公积金数额令人瞩目...
  • Nature Electronics 一种用于多模态皮肤信号监测的柔性触觉接口
  • 小鼠T细胞激活:如何系统解析其发育分化与免疫功能表征?
  • 基于springboot和vue的民航飞机票务管理系统设计与实现
  • 2025年12月-2026年4月,计算机领域涵盖的前言学术会议推荐!
  • 基于单片机的智能镜子系统设计(有完整资料)
  • 国产化替代SSD的标杆之路:天硕TOPSSD以自主可控存储解决方案重塑高端工业存储格局
  • EmotiVoice本地化部署优势:数据安全与响应效率兼得
  • 【Java毕设全套源码+文档】基于springboot的数据库课程在线教学系统设计与实现(丰富项目+远程调试+讲解+定制)
  • 【Java毕设全套源码+文档】基于springboot的实验室安全考试系统设计与实现(丰富项目+远程调试+讲解+定制)
  • 基于QT(C++)实现的翻金币游戏
  • 基于 Spring·Boot和 Vue 框架的校园快递代领系统设计与实现
  • NVIDIA设置疑难杂症诊所:万字终极实战指南
  • 边缘Agent的Docker监控实践(资源利用率提升90%的秘密)
  • 揭秘Docker Scout漏洞导出功能:如何快速获取镜像安全报告
  • 【云原生Agent资源调度实战】:Docker环境下高效分配CPU与内存的5大黄金法则
  • 增长有毒?流血三闯港股!希迪智驾带病叩钟:115亿市值撑得住“白条狂欢”吗?
  • 多模态Agent性能骤降?可能是Docker网络隔离没做好(附诊断清单)
  • 为什么你的Docker镜像总被攻破?:可能是扫描频率设置错了
  • 背胶条分类识别:基于计算机视觉的修复状态差异检测与质量评估系统
  • 【新】基于SSM的高校实验室管理系统【包括源码+文档+调试】
  • Python 爬虫实战:沪深 300 股票(下)—— 适当进阶!爬取往期批量数据