[Android L]SEAndroid增強Androd安全性背景概要及帶來的影響


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.
 
 

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文件內容
 1 # Input selectors:
 2 #     isSystemServer (boolean)
 3 #     user (string)
 4 #     seinfo (string)
 5 #     name (string)
 6 #     path (string)
 7 #     sebool (string)
 8 # isSystemServer=true can only be used once.
 9 # An unspecified isSystemServer defaults to false.
10 # An unspecified string selector will match any value.
11 # A user string selector that ends in * will perform a prefix match.
12 # user=_app will match any regular app UID.
13 # user=_isolated will match any isolated service UID.
14 # All specified input selectors in an entry must match (i.e. logical AND).
15 # Matching is case-insensitive.
16 #
17 # Precedence rules:
18 #        (1) isSystemServer=true before isSystemServer=false.
19 #       (2) Specified user= string before unspecified user= string.
20 #       (3) Fixed user= string before user= prefix (i.e. ending in *).
21 #       (4) Longer user= prefix before shorter user= prefix.
22 #       (5) Specified seinfo= string before unspecified seinfo= string.
23 #       (6) Specified name= string before unspecified name= string.
24 #       (7) Specified path= string before unspecified path= string.
25 #       (8) Specified sebool= string before unspecified sebool= string.
26 #
27 # Outputs:
28 #     domain (string)
29 #     type (string)
30 #     levelFrom (string; one of none, all, app, or user)
31 #     level (string)
32 # Only entries that specify domain= will be used for app process labeling.
33 # Only entries that specify type= will be used for app directory labeling.
34 # levelFrom=user is only supported for _app or _isolated UIDs.
35 # levelFrom=app or levelFrom=all is only supported for _app UIDs.
36 # level may be used to specify a fixed level for any UID.
37 #
38 isSystemServer=true domain=system_server
39 user=system domain=system_app type=system_app_data_file
40 user=bluetooth domain=bluetooth type=bluetooth_data_file
41 user=nfc domain=nfc type=nfc_data_file
42 user=radio domain=radio type=radio_data_file
43 user=shared_relro domain=shared_relro
44 user=shell domain=shell type=shell_data_file
45 user=_isolated domain=isolated_app
46 user=_app seinfo=platform domain=platform_app type=app_data_file
47 user=_app domain=untrusted_app type=app_data_file
48 #user=_app seinfo=lenovoapp domain=platform_app type=app_data_file
49 user=_app seinfo=lenovordvr domain=platform_app type=app_data_file
50 user=_app seinfo=lenovordvm domain=platform_app type=app_data_file
51 user=_app seinfo=lenovordvs domain=platform_app type=app_data_file
52 user=_app seinfo=lenovordvp domain=platform_app type=app_data_file
53 user=_app seinfo=lenovopadr domain=platform_app type=app_data_file
54 user=_app seinfo=lenovopadm domain=platform_app type=app_data_file
55 user=_app seinfo=lenovopads domain=platform_app type=app_data_file
56 user=_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將匹配任意被隔離的服務UID
3).seinfo:字符串,匹配SELinux控制類型
4).name:字符串,匹配應用名稱,如com.android.deskclock
5).sebool:字符串,匹配布爾值,該字符串定義的布爾值為真時匹配
 
SELinux會通過該定義文件為匹配的應用程序找到對應的結果(輸出)
1).domain:字符串,程序所屬於域
2).type:字符串,程序所屬類型
3).levelFromUid:布爾值,是否根據UID設置程序級別,當前只針對應用程序的UID。
4).level:字符串,應用程序的級別
 
根據這個結果,SELinux會為應用程序進程以及目錄分配相應的權限。
 

2.2 property_contexts配置文件

 
Android L(5.1)property_contexts文件內容
 
 1 ##########################
 2 # property service keys
 3 #
 4 #
 5 net.rmnet               u:object_r:net_radio_prop:s0
 6 net.gprs                u:object_r:net_radio_prop:s0
 7 net.ppp                 u:object_r:net_radio_prop:s0
 8 net.qmi                 u:object_r:net_radio_prop:s0
 9 net.lte                 u:object_r:net_radio_prop:s0
10 net.cdma                u:object_r:net_radio_prop:s0
11 net.dns                 u:object_r:net_radio_prop:s0
12 sys.usb.config          u:object_r:system_radio_prop:s0
13 ril.                    u:object_r:radio_prop:s0
14 gsm.                    u:object_r:radio_prop:s0
15 persist.radio           u:object_r:radio_prop:s0
16 
17 net.                    u:object_r:system_prop:s0
18 dev.                    u:object_r:system_prop:s0
19 runtime.                u:object_r:system_prop:s0
20 hw.                     u:object_r:system_prop:s0
21 sys.                    u:object_r:system_prop:s0
22 sys.powerctl            u:object_r:powerctl_prop:s0
23 service.                u:object_r:system_prop:s0
24 wlan.                   u:object_r:system_prop:s0
25 dhcp.                   u:object_r:dhcp_prop:s0
26 dhcp.bt-pan.result      u:object_r:pan_result_prop:s0
27 bluetooth.              u:object_r:bluetooth_prop:s0
28 
29 debug.                  u:object_r:debug_prop:s0
30 debug.db.               u:object_r:debuggerd_prop:s0
31 log.                    u:object_r:shell_prop:s0
32 service.adb.root        u:object_r:shell_prop:s0
33 service.adb.tcp.port    u:object_r:shell_prop:s0
34 
35 persist.audio.          u:object_r:audio_prop:s0
36 persist.logd.           u:object_r:logd_prop:s0
37 persist.sys.            u:object_r:system_prop:s0
38 persist.service.        u:object_r:system_prop:s0
39 persist.service.bdroid. u:object_r:bluetooth_prop:s0
40 persist.security.       u:object_r:system_prop:s0
41 
42 # selinux non-persistent properties
43 selinux.                u:object_r:security_prop:s0
44 
45 # default property context
46 *                       u:object_r:default_prop:s0
47 
48 # data partition encryption properties
49 vold.                   u:object_r:vold_prop:s0
50 crypto.                 u:object_r:vold_prop:s0
51 
52 # ro.build.fingerprint is either set in /system/build.prop, or is
53 # set at runtime by system_server.
54 build.fingerprint       u:object_r:fingerprint_prop:s0
55 
56 # ctl properties
57 ctl.bootanim            u:object_r:ctl_bootanim_prop:s0
58 ctl.dumpstate           u:object_r:ctl_dumpstate_prop:s0
59 ctl.fuse_               u:object_r:ctl_fuse_prop:s0
60 ctl.mdnsd               u:object_r:ctl_mdnsd_prop:s0
61 ctl.ril-daemon          u:object_r:ctl_rildaemon_prop:s0
62 ctl.bugreport           u:object_r:ctl_bugreport_prop:s0
63 ctl.dhcpcd_bt-pan       u:object_r:ctl_dhcp_pan_prop:s0
64 ctl.                    u:object_r:ctl_default_prop:s0
65 
66 # NFC properties
67 nfc.                    u:object_r:nfc_prop:s0
68 # DOLBY_START
69 dolby.audio             u:object_r:audio_prop:s0
70 dolby.                  u:object_r:system_prop:s0
71 # 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問題快速分析
 
轉自:http://blog.csdn.net/yelangjueqi/article/details/46756341
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM