news 2026/2/3 12:11:13

Android selinux 权限 修复 avc: denied

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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
}
}

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/1 5:17:36

【Java毕设源码分享】基于springboot+vue的数据库课程在线教学平台设计与实现(程序+文档+代码讲解+一条龙定制)

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围:&am…

作者头像 李华
网站建设 2026/2/3 3:26:27

【Java毕设源码分享】基于springboot+vue的人力资源管理系统的设计与实现(程序+文档+代码讲解+一条龙定制)

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围:&am…

作者头像 李华
网站建设 2026/1/30 2:36:59

基于 SVG 的钓鱼攻击与 Amatera/PureMiner 载荷的 DNS 基础设施分析

摘要近年来,可缩放矢量图形(Scalable Vector Graphics, SVG)因其支持内嵌 JavaScript 与外部资源引用的能力,逐渐被攻击者用作绕过传统邮件安全网关的初始投递载体。本文以近期活跃的 Amatera Stealer 信息窃取木马与 PureMiner 挖…

作者头像 李华
网站建设 2026/1/30 11:00:02

打击钓鱼即服务:诉讼、立法与技术协同的反诈治理路径

摘要近年来,以“钓鱼即服务”(Phishing-as-a-Service, PhaaS)为代表的诈骗基础设施呈现高度模块化、跨境化与自动化特征,尤其在短信(smishing)与邮件渠道中,通过仿冒知名品牌诱导用户泄露凭证或…

作者头像 李华
网站建设 2026/1/30 12:56:26

2025亲测高效:5款AI论文编辑工具深度测评,告别写作难题

在学术论文写作的全流程中,从选题构思时的灵感枯竭,到正文撰写中的逻辑卡顿,再到文献整理、格式排版等繁琐事务,每一步都可能成为“拦路虎”。2025年,AI技术在学术领域的应用愈发成熟,一批实用的论文编辑工…

作者头像 李华
网站建设 2026/1/25 3:38:44

vue基于springboot的基于现代物流的快递物流运单管理系统

目录已开发项目效果实现截图开发技术介绍系统开发工具:核心代码参考示例1.建立用户稀疏矩阵,用于用户相似度计算【相似度矩阵】2.计算目标用户与其他用户的相似度系统测试总结源码文档获取/同行可拿货,招校园代理 :文章底部获取博主联系方式&…

作者头像 李华