SELinux LOG分析及添加权限

adb修改selinux

Enforcing(表示已打开),Permissive(表示已关闭)

getenforce; //获取当前selinux状态

setenforce 1; //打开selinux

setenforce 0; //关闭selinux

 

从kernel中彻底关闭

修改/linux/android/kernel/arch/arm64/configs/xxx_defconfig文件(xxx一般为产品名),去掉CONFIG_SECURITY_SELINUX = y的设置项

 

sepolicy中添加权限

  • 修改依据,通过指令cat /proc/kmsg | grep denied,或Kernel 的log中定位到的标志性log
  • 修改步骤
    • 找相应的源类型.te文件,此文件可能存放的路径:
      • linux/android/external/sepolicy
      • linux/android/device/qcom/sepolicy/common
      • device/xxx/sepolicy(与device相关)
    • 标志性log
avc: denied  { 操作权限  }  for pid=7201  comm=“进程名”  scontext=u:r:源类型:s0  tcontext=u:r:目标类型:s0  tclass=访问类型 permissive=0

 在相应源类型.te文件,添加如下格式的一行语句(结尾有分号)

格式:allow  源类型 目标类型:访问类型 {操作权限};

 

实例 : 

kernel log:

avc: denied {getattr read} for pid=7201 comm="xxx.xxx" scontext=u:r:system_app:s0 tcontext=u:r:shell_data_file:s0 tclass=dir permissive=0

修改方案

在system_app.te文件中,添加下面语句:
allow system_app shell_data_file:dir{getattr read};

 

修改Sepolicy后出现“Error While Expanding policy”

在系统添加某个*.te或在te文件中添加某个selinux权限后,build会出现如下error:

genfscon proc /driver/thermal u:object_r:proc_thermal:s0
libsepol.report_failure: neverallow on line 429 of system/sepolicy/private/app.te (or line 21317 of policy.conf) violated by allow system_app system_file:file { write };
libsepol.report_failure: neverallow on line 406 of system/sepolicy/public/domain.te (or line 8484 of policy.conf) violated by allow system_app system_file:file { write };
libsepol.check_assertions: 2 neverallow failures occurred
Error while expanding policy

这是因为在/system/sepolicy/private/app.te和system/sepolicy/public/domain.te文件中添加了一些neverallow rules,导致编译检查的时候出现错误

neverallow appdomain system_file:dir_file_class_set {create write setattr relabelfrom relabelto append unlink link rename};

只需要在上面的规则中去掉添加的allow xx system_file:file { write };中的xx,具体方式是在nerverallow中用{}里用-xx排除某个,即不需要有此规则:

neverallow {appdomain -system_app} system_file:dir_file_class_set {create write setattr relabelfrom relabelto append unlink link rename};

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值