Android 添加 SELinux權限
SE Linux:
SELinux(Security-Enhanced Linux) 是美國國家安全域(NSA)對于強制訪問控制的實作,是 Linux歷史上最杰出的新安全子系統,NSA是在Linux社區
的幫助下開發了一種訪問控制體系,在這種訪問控制體系的限制下,行程只能訪問那些在他的任務中所需要檔案,SELinux默認安裝在 Fedora 和 Red
Hat Enterprise Linux上,也可以作為其他發行版上容易安裝的包得到,
SELinux是 2.6 版本的 Linux內核中提供的強制訪問控制(MAC)系統,對于目前可用的 Linux安全模塊來說,SELinux是功能最全面,而且測驗最充分
的,它是在 20 年的 MAC研究基礎上建立的,SELinux在型別強制服務器中合并了多級安全性或一種可選的多類策略,并采用了基于角色的訪問控制
概念,
SELinux是一種基于 域-型別 模型(domain-type)的強制訪問控制(MAC)安全系統,它由NSA撰寫并設計成內核模塊包含到內核中,相應的某些安
全相關的應用也被打了SELinux的補丁,最后還有一個相應的安全策略,任何程式對其資源享有完全的控制權,假設某個程式打算把含有潛在重要信
息的檔案扔到/tmp目錄下,那么在DAC情況下沒人能阻止他,SELinux提供了比傳統的UNⅨ權限更好的訪問控制,
SELinux 三種模式:
Enforcing 強制— SELinux 策略強制執行,基于 SELinux 策略規則授予或拒絕主體對目標的訪問
Permissive 寬容— SELinux 策略不強制執行,不實際拒絕訪問,但會有拒絕資訊寫入日志
Disabled 禁用— 完全禁用SELinux
Android 如何關閉SELinux:
adb root
adb shell setenforce 0 //關閉SELinux
adb shell setenforce 1 //打開SELinux
如何查看是否是SELinux引起的問題:
adb logcat | grep -i avc
在log中查看:
09-06 07:12:52.891 2792 2792 W ls : type=1400 audit(0.0:13152): avc: denied { getattr } for path="/init" dev="dm-0" ino=25 scontext=u:r:shell:s0 tcontext=u:object_r:init_exec:s0 tclass=lnk_file permissive=0
09-06 07:12:52.895 2792 2792 W ls : type=1400 audit(0.0:13153): avc: denied { getattr } for path="/init.environ.rc" dev="dm-0" ino=26 scontext=u:r:shell:s0 tcontext=u:object_r:rootfs:s0 tclass=file permissive=0
09-06 07:12:56.818 2793 2793 W ls : type=1400 audit(0.0:13154): avc: denied { getattr } for path="/linkerconfig" dev="tmpfs" ino=3170 scontext=u:r:shell:s0 tcontext=u:object_r:linkerconfig_file:s0 tclass=dir permissive=0
09-06 07:12:56.818 2793 2793 W ls : type=1400 audit(0.0:13155): avc: denied { getattr } for name="bootstrap" dev="tmpfs" ino=3170 scontext=u:r:shell:s0 tcontext=u:object_r:linkerconfig_file:s0 tclass=dir permissive=0
09-06 07:12:56.818 2793 2793 W ls : type=1400 audit(0.0:13156): avc: denied { getattr } for path="/data_mirror" dev="tmpfs" ino=1595 scontext=u:r:shell:s0 tcontext=u:object_r:mirror_data_file:s0 tclass=dir permissive=0
09-06 07:12:56.818 2793 2793 W ls : type=1400 audit(0.0:13157): avc: denied { getattr } for name="/" dev="tmpfs" ino=1595 scontext=u:r:shell:s0 tcontext=u:object_r:mirror_data_file:s0 tclass=dir permissive=0
09-06 07:12:56.818 2793 2793 W ls : type=1400 audit(0.0:13158): avc: denied { getattr } for path="/init" dev="dm-0" ino=25 scontext=u:r:shell:s0 tcontext=u:object_r:init_exec:s0 tclass=lnk_file permissive=0
添加節點以及分配權限:
1.file.te 定義路徑:
# add by mazhuang for Factory mode LCD test LED light is not on 2021-03-26
/sys/class/leds/red/brightness u:object_r:led_data_file:s0
/sys/class/leds/scan_red/brightness u:object_r:led_data_file:s0
/sys/class/leds/green/brightness u:object_r:led_data_file:s0
/sys/class/leds/scan_blue/brightness u:object_r:led_data_file:s0
2.file.te 定義type:
# add by mazhuang for Factory mode LCD test LED light is not on 2021-03-26
type led_data_file, fs_type, sysfs_type;
3.system_app.te 重新封裝:
# add by mazhuang for Factory mode LCD test LED light is not on 2021-03-26
allow system_app led_data_file:file {open write getattr};
#{ }中放入所需要的權限
注:在生成安全策略檔案時進行檢查,判斷是否有違反neverallow陳述句,在編譯程序中,發現neverallow中有注明不能allow的權限,而你又allow了一條,就會編譯失敗,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/298217.html
標籤:其他
