selinux權限問題【轉】


本文轉載自: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};



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM