本文转载自:https://blog.csdn.net/u011386173/article/details/83339770

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011386173/article/details/83339770
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};


分类:

技术点:

相关文章: