標籤:android selinux selinux seandroid selinux 影響
1 SEAndroid背景
Android對於作業系統安全性方面的增強一直沿用Linux核心所提供的MAC強制存取控制套件SELinux,對許可權進行了更為深度的管理,有效地控制著進程對資源的訪問。2012年才問世的SE Android將SELinux移植到Android平台上,以降低惡意應用程式攻擊帶來的損害,提供Android系統的防禦能力。 SE Android(Secutity-Enhanced Android)是Android與SE Linux的結合,由美國NSA在2012年推出的Android作業系統的安全強化套件,以支援在Android平台上使用SE Linux。SE Android 將原來應用在Linux作業系統上的MAC強制存取控制套件SELinux移植到Android平台上,其目的在於降低惡意應用程式攻擊帶來的損害。然而SE Android的範疇並不局限於SELinux,它通過強化Android作業系統對應用程式的存取控制,增強應用程式之間的隔離效果,確保每個應用程式之間的獨立運作,建立類似於沙箱的隔離效果,從而阻止惡意應用程式對系統或其他應用程式的攻擊。 Android是建立在標準的Linux Kernel 基礎上, 自然也可以開啟SELinux, 通常在通用移動平台上, 很少開啟這樣的安全服務, Google 為了進一步增強Android 的安全性, 經過長期的準備,目前已經在Android 5.0(L) 上完整的開啟SELinux, 並對SELinux 進行深入整合形成了SEAndroid.
【聲明】歡迎轉載,但請保留文章原始出處:http://blog.csdn.net/yelangjueqi/article/details/46756341
2 SEAndroid安全性原則概述
SE Android的策略源碼位置在external/sepolicy,其中包含用來產生SELinux核心策略檔案的原始碼。以下是Android 5.1的策略檔案結構樹:external/sepolicy |.├── access_vectors
├── adbd.te
├── Android.mk
├── app.te
├── attributes
├── binderservicedomain.te
├── bluetooth.te
├── bootanim.te
├── clatd.te
├── debuggerd.te
├── device.te
├── dex2oat.te
├── dhcp.te
├── dnsmasq.te
├── domain.te
├── drmserver.te
├── dumpstate.te
├── file_contexts
├── file.te
├── fs_use
├── genfs_contexts
├── global_macros
├── gpsd.te
├── hci_attach.te
├── healthd.te
├── hostapd.te
├── initial_sid_contexts
├── initial_sids
├── init_shell.te
├── init.te
├── inputflinger.te
├── installd.te
├── install_recovery.te
├── isolated_app.te
├── kernel.te
├── keys.conf
├── keystore.te
├── lmkd.te
├── logd.te
├── mac_permissions.xml
├── mdnsd.te
├── mediaserver.te
├── mls
├── mls_macros
├── mtp.te
├── netd.te
├── net.te
├── nfc.te
├── NOTICE
├── platform_app.te
├── policy_capabilities
├── port_contexts
├── ppp.te
├── property_contexts
├── property.te
├── racoon.te
├── radio.te
├── README
├── recovery.te
├── rild.te
├── roles
├── runas.te
├── sdcardd.te
├── seapp_contexts
├── security_classes
├── selinux-network.sh
├── service_contexts
├── servicemanager.te
├── service.te
├── shared_relro.te
├── shell.te
├── surfaceflinger.te
├── su.te
├── system_app.te
├── system_server.te
├── tee.te
├── te_macros
├── tools
│ ├── Android.mk
│ ├── checkfc.c
│ ├── check_seapp.c
│ ├── insertkeys.py
│ ├── post_process_mac_perms
│ ├── README
│ ├── sepolicy-analyze
│ │ ├── Android.mk
│ │ ├── dups.c
│ │ ├── dups.h
│ │ ├── neverallow.c
│ │ ├── neverallow.h
│ │ ├── perm.c
│ │ ├── perm.h
│ │ ├── README
│ │ ├── sepolicy-analyze.c
│ │ ├── typecmp.c
│ │ ├── typecmp.h
│ │ ├── utils.c
│ │ └── utils.h
│ └── sepolicy-check.c
├── ueventd.te
├── unconfined.te
├── uncrypt.te
├── untrusted_app.te
├── users
├── vdc.te
├── vold.te
├── watchdogd.te
├── wpa.te
└── zygote.te
SELinux核心策略檔案包含file_contexts設定檔、genfs_contexts設定檔、property_contexts設定檔、seapp_contexts設定檔和mac_permissions.xml設定檔,SE Android項目的開發人員仍然在對Android系統安全進行深入的研究,因此這些策略配置也處在隨時變化中。其中genfs_contexts設定檔、property_contexts設定檔和seapp_contexts設定檔是專門為SE Android系統建立的,因此不屬於傳統SELinux策略 這些策略檔案是在Android系統編譯過程中產生並且被添加到ramdisk鏡像當中,因此可以保證這些策略在系統啟動的初期,映射系統磁碟分割之前,最先被載入。一旦資料分區被載入後,可以將策略檔案放置在/data/system目錄下並且將selinux.reload_policy屬性置為1(使用setprop selinux.reload_policy 1 命令),之後重新載入/data/system目錄下的策略檔案,這種設定將會觸發系統的init進程重新載入策略,同時重新啟動ueventd和installd進程以保證它們可以重新載入與這兩個服務相關的策略。需要注意的是,對於核心策略,需要在主機的編譯環境中,重新編譯sepolicy(make policy),並且更新到/data/system中,如果希望每次裝置啟動時都會自動載入/data/system下的策略檔案,需要將setprop命令添加到init.rc(system/core/rootdir/init.rc)中。
2.1 seapp_contexts設定檔Android L(5.1) seapp_contexts檔案內容
# Input selectors:# isSystemServer (boolean)# user (string)# seinfo (string)# name (string)# path (string)# sebool (string)# isSystemServer=true can only be used once.# An unspecified isSystemServer defaults to false.# An unspecified string selector will match any value.# A user string selector that ends in * will perform a prefix match.# user=_app will match any regular app UID.# user=_isolated will match any isolated service UID.# All specified input selectors in an entry must match (i.e. logical AND).# Matching is case-insensitive.## Precedence rules:# (1) isSystemServer=true before isSystemServer=false.# (2) Specified user= string before unspecified user= string.# (3) Fixed user= string before user= prefix (i.e. ending in *).# (4) Longer user= prefix before shorter user= prefix.# (5) Specified seinfo= string before unspecified seinfo= string.# (6) Specified name= string before unspecified name= string.# (7) Specified path= string before unspecified path= string.# (8) Specified sebool= string before unspecified sebool= string.## Outputs:# domain (string)# type (string)# levelFrom (string; one of none, all, app, or user)# level (string)# Only entries that specify domain= will be used for app process labeling.# Only entries that specify type= will be used for app directory labeling.# levelFrom=user is only supported for _app or _isolated UIDs.# levelFrom=app or levelFrom=all is only supported for _app UIDs.# level may be used to specify a fixed level for any UID.#isSystemServer=true domain=system_serveruser=system domain=system_app type=system_app_data_fileuser=bluetooth domain=bluetooth type=bluetooth_data_fileuser=nfc domain=nfc type=nfc_data_fileuser=radio domain=radio type=radio_data_fileuser=shared_relro domain=shared_relrouser=shell domain=shell type=shell_data_fileuser=_isolated domain=isolated_appuser=_app seinfo=platform domain=platform_app type=app_data_fileuser=_app domain=untrusted_app type=app_data_file#user=_app seinfo=lenovoapp domain=platform_app type=app_data_fileuser=_app seinfo=lenovordvr domain=platform_app type=app_data_fileuser=_app seinfo=lenovordvm domain=platform_app type=app_data_fileuser=_app seinfo=lenovordvs domain=platform_app type=app_data_fileuser=_app seinfo=lenovordvp domain=platform_app type=app_data_fileuser=_app seinfo=lenovopadr domain=platform_app type=app_data_fileuser=_app seinfo=lenovopadm domain=platform_app type=app_data_fileuser=_app seinfo=lenovopads domain=platform_app type=app_data_fileuser=_app seinfo=lenovopadp domain=platform_app type=app_data_file
seapp_contexts檔案用來標記應用程式的進程和應用程式套件組合所在的目錄。該檔案的源位置在external/sepolicy目錄下,下面是可以再其中設定的選項(輸入)1).isSystemServer :布爾值,匹配系統級服務程式,在檔案中只能被定義為真(true)一次,預設值為假(false)2).user:字串,匹配應用程式的使用者,若為空白或沒有定義為任意使用者,以*結尾的字串將進行首碼匹配。user=_app將匹配任何一般應用UID,user=_isolated將匹配任意被隔離的服務UID3).seinfo:字串,匹配SELinux控制類型4).name:字串,匹配應用程式名稱,如com.android.deskclock5).sebool:字串,匹配布爾值,該字串定義的布爾值為真時匹配
SELinux會通過該定義檔案為匹配的應用程式找到對應的結果(輸出)1).domain:字串,程式所屬於域2).type:字串,程式所屬類型3).levelFromUid:布爾值,是否根據UID設定程式層級,當前只針對應用程式的UID。4).level:字串,應用程式的層級
根據這個結果,SELinux會為應用程式進程以及目錄分配相應的許可權。
2.2 property_contexts設定檔Android L(5.1)property_contexts檔案內容
########################### property service keys##net.rmnet u:object_r:net_radio_prop:s0net.gprs u:object_r:net_radio_prop:s0net.ppp u:object_r:net_radio_prop:s0net.qmi u:object_r:net_radio_prop:s0net.lte u:object_r:net_radio_prop:s0net.cdma u:object_r:net_radio_prop:s0net.dns u:object_r:net_radio_prop:s0sys.usb.config u:object_r:system_radio_prop:s0ril. u:object_r:radio_prop:s0gsm. u:object_r:radio_prop:s0persist.radio u:object_r:radio_prop:s0net. u:object_r:system_prop:s0dev. u:object_r:system_prop:s0runtime. u:object_r:system_prop:s0hw. u:object_r:system_prop:s0sys. u:object_r:system_prop:s0sys.powerctl u:object_r:powerctl_prop:s0service. u:object_r:system_prop:s0wlan. u:object_r:system_prop:s0dhcp. u:object_r:dhcp_prop:s0dhcp.bt-pan.result u:object_r:pan_result_prop:s0bluetooth. u:object_r:bluetooth_prop:s0debug. u:object_r:debug_prop:s0debug.db. u:object_r:debuggerd_prop:s0log. u:object_r:shell_prop:s0service.adb.root u:object_r:shell_prop:s0service.adb.tcp.port u:object_r:shell_prop:s0persist.audio. u:object_r:audio_prop:s0persist.logd. u:object_r:logd_prop:s0persist.sys. u:object_r:system_prop:s0persist.service. u:object_r:system_prop:s0persist.service.bdroid. u:object_r:bluetooth_prop:s0persist.security. u:object_r:system_prop:s0# selinux non-persistent propertiesselinux. u:object_r:security_prop:s0# default property context* u:object_r:default_prop:s0# data partition encryption propertiesvold. u:object_r:vold_prop:s0crypto. u:object_r:vold_prop:s0# ro.build.fingerprint is either set in /system/build.prop, or is# set at runtime by system_server.build.fingerprint u:object_r:fingerprint_prop:s0# ctl propertiesctl.bootanim u:object_r:ctl_bootanim_prop:s0ctl.dumpstate u:object_r:ctl_dumpstate_prop:s0ctl.fuse_ u:object_r:ctl_fuse_prop:s0ctl.mdnsd u:object_r:ctl_mdnsd_prop:s0ctl.ril-daemon u:object_r:ctl_rildaemon_prop:s0ctl.bugreport u:object_r:ctl_bugreport_prop:s0ctl.dhcpcd_bt-pan u:object_r:ctl_dhcp_pan_prop:s0ctl. u:object_r:ctl_default_prop:s0# NFC propertiesnfc. u:object_r:nfc_prop:s0# DOLBY_STARTdolby.audio u:object_r:audio_prop:s0dolby. u:object_r:system_prop:s0# DOLBY_END
property_contexts設定檔為許可權檢查定義了Android系統各屬性間的安全性關聯。該檔案為系統中的每一種服務類型定義了不同的屬性,包括使用者(user)、角色(role)、屬性(property)和層級(level)。一種應用程式在調用某一服務資源時,系統將會根據這些屬性檢查是否有許可權使用這些資源。 以下是目前各項屬性可用的值。
1) 使用者:u,系統預設,唯一值
2) 角色:object_r ,系統預設,唯一值
3) 屬性:預設屬性是default_prop,其他屬性分別是:見上,如net_radio_prop、system_radio_prop、shell_prop ...
4) 層級:s0 ,系統預設,唯一值
3 SELinux在Android上的更新過程如所描述:
SELinux 在Android 的更新過程
1) KK 4.4 針對netd, installd, zygote, vold 四個原本具有root 許可權的process, 以及它們fork 出的子進程啟用Enforce 模式.
2) L 版本普遍性開啟SELinux Enforce mode.
3) Permissive 模式,只列印audit 異常LOG,不拒絕請求, Enforce 模式,即列印audit 異常LOG, 也拒絕請求
4 SELinux給Android帶來了哪些影響 1) 嚴格限制了ROOT 許可權, 以往ROOT "無法無天" 的情況將得到極大的改善.
2) 通過SELinux保護, 降低系統關鍵進程受攻擊的風險, 普通進程將沒有許可權直接連接到系統關鍵進程.
3) 進一步強化APP的沙箱機制, 確保APP難以做出異常行為或者攻擊行為.
4) 將改變APP一旦安裝, 許可權就已經頂死的曆史, APP許可權動態調整將成為可能.
參考文獻1) Android安全機制解析與應用實踐(吳倩/趙晨嘯)2) MTK-SELinux問題快速分析
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Android [Android L]SEAndroid增強Androd安全性背景概要及帶來的影響