您的位置:首页 > 移动开发 > Android开发

[Android L]SEAndroid增强Androd安全性背景概要及带来的影响

2015-07-04 17:20 543 查看

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文件内容
<span style="font-size:18px;"># 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_server
user=system domain=system_app type=system_app_data_file
user=bluetooth domain=bluetooth type=bluetooth_data_file
user=nfc domain=nfc type=nfc_data_file
user=radio domain=radio type=radio_data_file
user=shared_relro domain=shared_relro
user=shell domain=shell type=shell_data_file
user=_isolated domain=isolated_app
user=_app seinfo=platform domain=platform_app type=app_data_file
user=_app domain=untrusted_app type=app_data_file
#user=_app seinfo=lenovoapp domain=platform_app type=app_data_file
user=_app seinfo=lenovordvr domain=platform_app type=app_data_file
user=_app seinfo=lenovordvm domain=platform_app type=app_data_file
user=_app seinfo=lenovordvs domain=platform_app type=app_data_file
user=_app seinfo=lenovordvp domain=platform_app type=app_data_file
user=_app seinfo=lenovopadr domain=platform_app type=app_data_file
user=_app seinfo=lenovopadm domain=platform_app type=app_data_file
user=_app seinfo=lenovopads domain=platform_app type=app_data_file
user=_app seinfo=lenovopadp domain=platform_app type=app_data_file</span>


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文件内容
<span style="font-size:18px;">##########################
# property service keys
#
#
net.rmnet               u:object_r:net_radio_prop:s0
net.gprs                u:object_r:net_radio_prop:s0
net.ppp                 u:object_r:net_radio_prop:s0
net.qmi                 u:object_r:net_radio_prop:s0
net.lte                 u:object_r:net_radio_prop:s0
net.cdma                u:object_r:net_radio_prop:s0
net.dns                 u:object_r:net_radio_prop:s0
sys.usb.config          u:object_r:system_radio_prop:s0
ril.                    u:object_r:radio_prop:s0
gsm.                    u:object_r:radio_prop:s0
persist.radio           u:object_r:radio_prop:s0

net.                    u:object_r:system_prop:s0
dev.                    u:object_r:system_prop:s0
runtime.                u:object_r:system_prop:s0
hw.                     u:object_r:system_prop:s0
sys.                    u:object_r:system_prop:s0
sys.powerctl            u:object_r:powerctl_prop:s0
service.                u:object_r:system_prop:s0
wlan.                   u:object_r:system_prop:s0
dhcp.                   u:object_r:dhcp_prop:s0
dhcp.bt-pan.result      u:object_r:pan_result_prop:s0
bluetooth.              u:object_r:bluetooth_prop:s0

debug.                  u:object_r:debug_prop:s0
debug.db.               u:object_r:debuggerd_prop:s0
log.                    u:object_r:shell_prop:s0
service.adb.root        u:object_r:shell_prop:s0
service.adb.tcp.port    u:object_r:shell_prop:s0

persist.audio.          u:object_r:audio_prop:s0
persist.logd.           u:object_r:logd_prop:s0
persist.sys.            u:object_r:system_prop:s0
persist.service.        u:object_r:system_prop:s0
persist.service.bdroid. u:object_r:bluetooth_prop:s0
persist.security.       u:object_r:system_prop:s0

# selinux non-persistent properties
selinux.                u:object_r:security_prop:s0

# default property context
*                       u:object_r:default_prop:s0

# data partition encryption properties
vold.                   u:object_r:vold_prop:s0
crypto.                 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 properties
ctl.bootanim            u:object_r:ctl_bootanim_prop:s0
ctl.dumpstate           u:object_r:ctl_dumpstate_prop:s0
ctl.fuse_               u:object_r:ctl_fuse_prop:s0
ctl.mdnsd               u:object_r:ctl_mdnsd_prop:s0
ctl.ril-daemon          u:object_r:ctl_rildaemon_prop:s0
ctl.bugreport           u:object_r:ctl_bugreport_prop:s0
ctl.dhcpcd_bt-pan       u:object_r:ctl_dhcp_pan_prop:s0
ctl.                    u:object_r:ctl_default_prop:s0

# NFC properties
nfc.                    u:object_r:nfc_prop:s0
# DOLBY_START
dolby.audio             u:object_r:audio_prop:s0
dolby.                  u:object_r:system_prop:s0
# DOLBY_END</span>


      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问题快速分析
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: