Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

SELinux 權限問題排查與策略修改實務筆記

編輯:Linux 教學
 

記錄 Android/Linux 系統下 SELinux 權限被拒 (avc: denied) 的排查與修改策略方法。

即時狀態切換 (需 root)

getenforce          # 顯示 Enforcing / Permissive / Disabled
setenforce 1        # 切換至 Enforcing
setenforce 0        # 切換至 Permissive (暫時關閉,重開機失效)

核心編譯階段徹底關閉

修改核心配置 arch/arm64/configs/xxx_defconfig,移除 CONFIG_SECURITY_SELINUX=y。

修改 sepolicy 允許特定存取 (標準做法)

  1. 定位被拒日誌:
    cat /proc/kmsg | grep denied 或核心日誌中搜尋 avc: denied。
  2. 解析日誌格式:
    avc: denied { 權限集合 } for pid=XXX comm="進程名" scontext=u:r:來源類型:s0 tcontext=u:r:目標類型:s0 tclass=存取類別 permissive=0
  3. 編輯對應 .te 檔案:
    來源類型對應的 .te 檔可能位於:
    external/sepolicy、device/qcom/sepolicy/common 等目錄。
  4. 新增 allow 規則 (結尾需分號):
    allow 來源類型 目標類型:存取類別 {權限集合};

實例

# 核心日誌
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 並刷入生效。

Copyright © Windows教程網 All Rights Reserved