1. 確認 seLinux導致權限問題
1.1 標誌性log 格式:
avc: denied { 操作權限 } for pid=7201 comm=“進程名” scontext=u:r:源類型:s0 tcontext=u:r:目標類型:s0 tclass=訪問類別 permissive=0
1.2 舉例:
Kenel log:
avc: denied { execheap } for pid=7201 comm="com.baidu.input" scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0
Logcat log:
com.baidu.input: type=1400audit(0.0:29): avc: denied { execheap } for scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0
1.3 方法1:adb在線修改
關閉 seLinux:
打開seLinux:
Enforcing:seLinux已經打開;
Permissive:seLinux已經關閉;
1.4 方法2: 從kernel中徹底關閉 (用於開機初始化時的seLinux權限問題,要重編bootimage)
修改LINUX/android/kernel/arch/arm64/configs/XXXdefconfig文件(找相應config文件)
去掉CONFIG_SECURITY_SELINUX=y 的配置項
2.1 修改依據:
log 信息:
avc: denied { 操作權限 } for pid=7201 comm=“進程名” scontext=u:r:源類型:s0 tcontext=u:r:目標類型:s0
tclass=訪問類別 permissive=0
2.2 修改步驟:
找相應的“源類型.te ”文件
有兩個位置可能存在相應的te文件:
位置一:LINUX/android/external/sepolicy
位置二:LINUX/android/device/qcom/sepolicy/common
2.3 按如下格式在該文件中添加:
allow 源類型 目標類型:訪問類別 {權限};
2.4 舉例
Kernel Log:
avc: denied { execheap } for pid=7201 comm="com.baidu.input" scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0
修改:
在LINUX/android/external/sepolicy/untrusted_app.te 中添加:
allow untrusted_app untrusted_app:process { execheap };
備註:
在這個例子中,由於源類型和目標類型都是untreated_app, 所以也可以寫成:
allow untrusted_app self:process { execheap };
3. 添加權限後的neverallowed衝突
3.1 編譯報錯:
libsepol.check_assertion_helper: neverallow on line xxx ofexternal/sepolicy/domain.te ……
3.2 原因:
新添加的sepolicy項目違反了domain.te 中規定的的總策略原則。所以該條權限策略不能添加,如果強行添加的話有CTS測試失敗的風險。
3.3 解決方法:
avc: denied { read write } for pid=303 comm="mediaserver" name="tfa9890"dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0tcontext=u:object_r:device:s0tclass=chr_file permissive=0
一般有file_contexts, genfs_contexts, property_contexts, service_contexts 等文件
如:在file_contexts中添加: /dev/tfa9890 u:object_r:audio_device:s0
3.4 舉例
添加權限:
在mediaserver.te中添加allow mediaserver device:chr_file { read write open};
編譯報錯:
libsepol.check_assertion_helper: neverallow on line 258 ofexternal/sepolicy/domain.te (or line 5252 of policy.conf) violated byallow mediaserver device:chr_file { read write open};
違反了domain.te 258的:
neverallow {domain –unconfineddomain –ueventd } device:chr_file { open read write}
運行Log:
avc: denied { read write } for pid=303 comm="mediaserver"name="tfa9890" dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0tclass=chr_file permissive=0
1.目標名稱是: tfa9890, 其在系統中的路徑是: /dev/tfa9890, 是audio相關的設備文件
2.源類型是mediaserver, 在mediaserver.te 文件中發現其具有 audio_device 目標類型的權限
3.所以在file_contexts 中添加 “/dev/tfa9890 u:object_r:audio_device:s0” 可以解決問題