加载中…
个人资料
行者无疆-超越
行者无疆-超越
  • 博客等级:
  • 博客积分:0
  • 博客访问:471
  • 关注人气:1
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

SEAndroid的各种策略文件

(2014-04-24 11:38:55)
标签:

android

seandroid

selinux

安全

it

分类: Android安全

external/sepolicy目录存放了很多SELinux的策略定义文件。通过这些文件我们能了解到SEAndroid更多的细节,下面我们一起看看这些文件的内容。

1.   角色定义文件roles

角色定义文件用来定义SELinux系统的角色。文件roles的内容如下:

role r;

role r types domain;

从这里可以看到,SEAndroid实际上只定义了一种角色r

2.   用户定义文件users

用户定义文件用来定义用户,前面我们介绍了,SELinux中的用户可以有三种,但是SEAndroid中只定义了一种u,下面是文件user的内容:

user u roles { r } level s0 range s0 - mls_systemhigh;

无论是user,还是role,在SEAndroid目前的定义中都只有一种,所以暂时也就没有大的用处。

3.   属性定义文件attributes

属性定义文件attributes中定义了所有type定义中需要用到的属性值,如下所示:

attribute dev_type;                # 表示设备文件

attribute domain;              # 表示域

attribute fs_type;                 # 表示文件系统

attribute file_type;               # 表示所有的普通文件

attribute exec_type;               # 表示所有可执行文件

attribute data_file_type;          # 表示所有数据文件

attribute sysfs_type;          # 表示sysfs类型的文件

attribute sdcard_type;         # 表示sdcard中的文件

attribute node_type;               # 表示网络中的host节点

attribute netif_type;          # 表示网络接口

attribute port_type;               # 表示网络的端口

attribute property_type;           # 表示所有Android的属性

attribute mlstrustedsubject;       # 表示系统中所有受信任的主体

attribute mlstrustedobject;        # 表示系统中所有受信任的客体

attribute unconfineddomain;        # 表示系统中哪些没有任何限制的域

attribute appdomain;               # 表示系统中所有的app的域

attribute netdomain;               # 表示系统中所有能访问网络的app的域

attribute bluetoothdomain;     # 表示系统中所有能访问bluetoothapp的域

attribute binderservicedomain; # 表示系统中所有的binder server的域

attribute platformappdomain;       # 表示系统中所有平台提供的app的域

attribute relabeltodomain;     # 表示系统中所有能够重新设置安全上下文的域

4.   Class定义文件security_classes

在规则定义语句中会用到客体限制类别(Object Class),文件security_classes定义了所有系统中用到的class,如下所示:

class security

class process

class system

class capability

 

# file-related classes

class filesystem

class file

class dir

class fd

class lnk_file

class chr_file

class blk_file

class sock_file

class fifo_file

....

security_classes文件比较长,这里只列举了其中的一部分,class的定义比较容易理解,基本上是对系统资源一个细化的类别定义。定义客体的类型(type)时,附加属性相当于指定了客体能代表的一个比较粗的范围,在allow规则中加上客体限制类别后,相当于把客体限制到了一个更小的范围。

5.   操作定义文件access_vectors

allow语句的最后一项为允许的操作,所有的操作都在文件access_vectors中定义,文件的部分内容如下:

common file

{

ioctl

read

write

create

getattr

......

}

......

class filesystem

{

mount

remount

unmount

getattr

relabelfrom

relabelto

transition

associate

quotamod

quotaget

}

 

class dir

inherits file

{

add_name

remove_name

reparent

search

rmdir

open

audit_access

execmod

}

......

access_vectors文件通过两种方式定义操作,一种方式是通过common语句,这种方式定义的操作是一种公共的操作,没有限定哪种类别的客体可以使用,还可以被继承。另一种定义的方式是通过class语句,但是calss语句后面的名称必须是某种客体限制类别,这也意味着通过class语句定义的操作只能使用在相应的客体限制类别中。class语句可以继承common语句中定义的操作。

6.   类型强制规则文件

目录中凡是以te结尾的文件都属于类型强制规则文件(Type Enforcement)。它主要有类型定义和规则定义两部分组成。我们看看su.te文件的内容:

type su, domain;

permissive su;

type su_exec, file_type;

domain_auto_trans(shell, su_exec, su)

 

# su is unconfined.

unconfined_domain(su)

su.te中定义了两种类型:susu_execsu用在进程的安全上下文中,su_exec则用在文件的安全上下文中。su.te中还调用了两个宏,domain_auto_trans宏我们前面已经分析过了,用来规定在shell执行su文件时将进程转移到su域。unconfined_domain宏则用来把su域定义成一个不受限制的域。

7.   TE的宏定义文件te_macros

te_macros 文件中定义了在TE规则文件中用到的宏。前面我们已经介绍了domain_auto_trans宏。下面我们再看看unconfined_domain宏是如何定义的:

define(`unconfined_domain', `

typeattribute $1 mlstrustedsubject;

typeattribute $1 unconfineddomain;

')

unconfined_domain中使用了typeattribute语句。 typeattribute语句的作用是指定类型(type)的属性,我们知道定义type时可以在后面用逗号分割后指定属性,typeattribute语句可以给定义好的类型增加属性。因此unconfined_domain(su)的结果是给域su增加了mlstrustedsubjectunconfineddomain两种属性。这两种属性分别代表了系统中所有可信任的客体和不受限制的主体,因此su域将拥有系统中类似以前系统中超级用户的权限。这里虽然通过规则给了su域相当大的权限,但是也能通过修改规则来限制su的权限。这就是SELinux的强大之处,它能灵活的通过配置文件来修改任何的访问权限。当然这也对系统管理员的能力提出了更高的要求。所有通常我们不需要去修改Android中的这些配置文件,但是我们需要能理解它们的含义。

8.   file_contexts文件

file_contexts文件保存的是系统中所有文件的安全上下文定义,文件部分内容如下:

下面我们看看文件file_contexts的内容。

#line 1 "external/sepolicy/file_contexts"

###########################################

# Root

/             u:object_r:rootfs:s0

 

# Data files

/adb_keys     u:object_r:rootfs:s0

/default.prop     u:object_r:rootfs:s0

/fstab\..*        u:object_r:rootfs:s0

/init\..*     u:object_r:rootfs:s0

/res(/.*)?        u:object_r:rootfs:s0

/ueventd\..*      u:object_r:rootfs:s0

 

# Executables

/charger      u:object_r:rootfs:s0

/init             u:object_r:rootfs:s0

/sbin(/.*)?       u:object_r:rootfs:s0

......

file_contexts文件的格式比较简单,每行的前半部分是文件的路径,后面是它的安全上下文的定义。从文件可以看到,这里的路径定义也支持通配符。

9.   property_contexts文件

property_contexts文件中保存的是系统中所有Android属性的安全上下文定义,内容如下:

#line 1 "external/sepolicy/property_contexts"

##########################

# property service keys

#

#

net.rmnet0              u:object_r:radio_prop:s0

net.gprs                u:object_r:radio_prop:s0

net.ppp                 u:object_r:radio_prop:s0

net.qmi                 u:object_r:radio_prop:s0

net.lte                 u:object_r:radio_prop:s0

net.cdma                u:object_r:radio_prop:s0

gsm.                    u:object_r:radio_prop:s0

persist.radio           u:object_r:radio_prop:s0

net.dns                 u:object_r:radio_prop:s0

sys.usb.config          u:object_r:radio_prop:s0

......

property_contexts文件的格式也相当简单,每行前面是属性,后面是它对应的安全上下文。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有