国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

詳解Android Selinux 權(quán)限及問(wèn)題

2019-12-12 01:41:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

由于現(xiàn)做的是MTK平臺(tái),源碼路徑基于MTK, 不過(guò)高通大同小異

說(shuō)明

Android 5.0以后完全引入了 SEAndroid/SELinux 安全機(jī)制,這樣即使擁有 root 權(quán)限或 chmod 777 ,仍然無(wú)法再JNI以上訪問(wèn)內(nèi)核節(jié)點(diǎn)。

其實(shí)在 Android 4.4 就有限制的啟用此安全機(jī)制了。后面內(nèi)容都按照 5.0 以后介紹,4.4 會(huì)有些許差異。

SELinux Mode

SELinux 分為兩種模式,Android 5.0 后所有進(jìn)程都使用 enforcing mode。

enforcing mode: 限制訪問(wèn)permissive mode: 只審查權(quán)限,不限制

SELinux Policy文件路徑

# Google 原生目錄 external/sepolicy# 廠家目錄,高通將 mediatek 換為 qcomalps/device/mediatek/common/sepolicyalps/device/mediatek/<platform>/sepolicy

編譯時(shí)將以合并的方式將廠家policy追加到Google原生。

Log

沒(méi)有權(quán)限時(shí)可以在內(nèi)核找到如下 log :

# avc: denied { 操作權(quán)限 } for pid=7201 comm=“進(jìn)程名” scontext=u:r:源類(lèi)型:s0 tcontext=u:r:目標(biāo)類(lèi)型:s0 tclass=訪問(wèn)類(lèi)型 permissive=0avc: 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``` ## 權(quán)限修改主要有三種方式,前兩種只能用來(lái)測(cè)試,第三種是推薦的正式處理方式。### adb在線修改seLinux```bash# Enforcing - 表示已打開(kāi) ,Permissive - 表示已關(guān)閉getenforce;  //獲取當(dāng)前seLinux狀態(tài)setenforce 1; //打開(kāi)seLinuxsetenforce 0; //關(guān)閉seLinux

kernel中關(guān)閉

# alps/kernel-3.18/arch/arm64/configs/xxx_defconfigCONFIG_SECURITY_SELINUX=y // 屏蔽此配置項(xiàng)

SELinux Sepolicy中添加權(quán)限

修改相應(yīng)源類(lèi)型.te文件(基本以源進(jìn)程名命名),添加如下一行語(yǔ)句:

# 格式allow 源類(lèi)型 目標(biāo)類(lèi)型:訪問(wèn)類(lèi)型 {操作權(quán)限}; // 注意分號(hào)# 實(shí)例,具體寫(xiě)法參考源碼allow system_app shell_data_file:dir{getattr read write};allow mediaserver tfa9897_device:chr_file { open read write }; allow system_server tfa9897_device:chr_file rw_file_perms; chr_file - 字符設(shè)備 file - 普通文件 dir - 目錄

通常很少修改Google default 的policy, 推薦更新mediatek 下面的相關(guān)的policy.

新建節(jié)點(diǎn)

如果是自己新建的節(jié)點(diǎn),需要在 sepolicy 路徑下的 file_contexts 文件中做如下添加:

# 參考已有的格式/dev/goodix_fp     u:object_r:goodixfp_device:s0

Android 5.0 修改的文件為device.te 和 file_contexts.be,而且device/mediatek/common/BoardConfig.mk 中的 BROAD_SEPOLICY_UNION 增加對(duì)應(yīng)的xxxx.te。

編譯

# 模塊編譯mmm external/sepolicymake -j24 ramdisk-nodeps & make -j24 bootimage-nodeps# 整編make -j24

ps添加權(quán)限后的neverallowed沖突

編譯報(bào)錯(cuò):

libsepol.check_assertion_helper: neverallow on line xxx ofexternal/sepolicy/domain.te ……

 原因:

新添加的sepolicy項(xiàng)目違反了domain.te 中規(guī)定的的總策略原則。所以該條權(quán)限策略不能添加,如果強(qiáng)行添加的話有CTS測(cè)試失敗的風(fēng)險(xiǎn)。

解決方法:

1.從運(yùn)行l(wèi)og中找到要訪問(wèn)的目標(biāo)名稱(chēng),一般是name字段后的名稱(chēng)
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

2.找到相應(yīng)的*_contexts文件。

  一般有file_contexts, genfs_contexts,  property_contexts,  service_contexts 等文件

在contexts文件中指定要訪問(wèn)的目標(biāo)為一個(gè)“源類(lèi)型 ”有權(quán)限訪問(wèn)的“目標(biāo)類(lèi)型”

如:在file_contexts中添加: /dev/tfa9890     u:object_r:audio_device:s0

 舉例

添加權(quán)限:

在mediaserver.te中添加allow mediaserver device:chr_file { read write open};

編譯報(bào)錯(cuò):
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

主站蜘蛛池模板: 吉水县| 湄潭县| 吉木萨尔县| 浦县| 新兴县| 遂昌县| 扶余县| 昌吉市| 延吉市| 平塘县| 宣武区| 金阳县| 贺州市| 师宗县| 白玉县| 新安县| 赤峰市| 望奎县| 太谷县| 浪卡子县| 涪陵区| 大英县| 邹平县| 泾川县| 六安市| 仙桃市| 大兴区| 永宁县| 连城县| 瓦房店市| 宁安市| 黑河市| 伊宁市| 荆州市| 高青县| 灵石县| 绥中县| 兴安盟| 常宁市| 仪征市| 武宁县|