01> 文件拷貝腳本:
MT6580_M/external$ vi sepolicy/cpgf3208.sh
#!/bin/bash echo nicek: cp_gf3208 DIR=$(cd `dirname $0`; pwd) #echo $DIR cp ${DIR}/gf3208_te/* ${DIR}/ cp ${DIR}/../../device/mediatek/common/gf3208_te/* ${DIR}/../../device/mediatek/common/sepolicy/
將對應屬性添加到:
生效的文件:

刪掉不用的功能,保留只用的,再將刪掉功能中添加的其他屬性放到該文件下;
Android 5.0下,因為采取了SEAndroid/SElinux的安全機制,即使擁有root權限,或者對某內核節點設置為777的權限,仍然無法在JNI層訪問。
01設備節點(或bin文件);02file_contexts;03device.te;04進程文件添加權限;
本文將以用戶自定義的內核節點
/dev/wf_bt為例,手把手教會讀者如何在JNI層獲得對該節點的訪問權限。
第一步:找到需要訪問該內核節點的進程(process),筆者自己這個節點由system_server進程來訪問
第二步:打開文件
AndroidL/android/external/sepolicy/file_contexts
仿照這個文件里的寫法,為你的節點定義一個你想要的名字:
- /dev/tegra.* u:object_r:video_device:s0
- /dev/tf_driver u:object_r:tee_device:s0
- /dev/tty u:object_r:owntty_device:s0
- /dev/tty[0-9]* u:object_r:tty_device:s0
- # We add here
- /dev/wf_bt u:object_r:wf_bt_device:s0
wf_bt_device是自定義,其他左右兩邊的內容都和上面的范例一致。
第三步:打開文件
AndroidL/android/external/sepolicy/device.te
仿照這個文件里的寫法,將剛剛第二步寫的wf_bt_device聲明為dev_type:
- # Device types
- type device, dev_type, fs_type;
- type alarm_device, dev_type, mlstrustedobject;
- type adb_device, dev_type;
- type ashmem_device, dev_type, mlstrustedobject;
- type audio_device, dev_type;
- type binder_device, dev_type, mlstrustedobject;
- type block_device, dev_type;
- # We add here
- type wf_bt_device, dev_type;
第四步:
AndroidL/android/external/sepolicy/目錄下
很多.te文件都是以進程名來結尾的,比如有針對surfaceflinger進程的surfaceflinger,有針對vold進程的vold.te,
剛剛從第一步得到,這個節點是由system_server進程來訪問,所以,我們找到system_server.te打開,
加入允許這個進程對/dev/wf_bt的讀寫權限,
- # Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid.
- allow system_server qtaguid_proc:file rw_file_perms;
- allow system_server qtaguid_device:chr_file rw_file_perms;
- # chr_file表示字符設備文件,如果是普通文件用file,目錄請用dir
- # rw_file_perms代表讀寫權限
- allow system_server wf_bt_device:chr_file rw_file_perms; // 允許system_server進程擁有對wf_bt_device的這個字符設備的讀寫權限;
這句話的意思是:允許system_server進程擁有對wf_bt_device的這個字符設備的讀寫權限。
改了這些之后,你就可以
make installclean;make -j16編譯image來驗證權限是否獲取成功。
fd =open("/dev/wf_bt",O_RDONLY | O_NOCTTY); 絕對成功!!!!!
=====================================
allow system_server wf_bt_device:chr_file rw_file_perms; //允許system_server進程擁有對wf_bt_device的這個字符設備的讀寫權限。
=====================================
allow system_server wf_bt_device:chr_file rw_file_perms; //允許system_server進程擁有對wf_bt_device的這個字符設備的讀寫權限。
ls -Z 節點 (查看權限)
可以用命令來查看selinux的狀態 getenforce 這個命令可以查看到selinux的狀態,當前可以看到是關閉狀態的。 還有一個命令也可以查看出selinux的狀態。 sestatus -v 還有一個setenforce 命令可以設置selinux的狀態
xxx:# getenforce
Enforcing
mmm external/sepolicy
make -j24 ramdisk-nodeps
make -j24 bootimage-nodeps
對於tee:
可信執行環境(TEE)介紹 與應用
-------------------
