SEAndroid使用两种方式为进程设置安全上下文
1.为独立进程静态的设置安全上下文
这和传统的LInux系统很像。android系统中的每个独立进程都对应着一个可执行文件。
以init为例,查看init进程的启动脚本system/core/rootdir/init.rc,部分内容如下:
on early-init
...........
# Set thesecurity context for the init process.
# Thisshould occur before anything else (e.g. ueventd) is started.
setconu:r:init:s0
这一行的作用是让init进程将自己的安全上下文设为u:r:init:s0。
查看external/sepolicy/init.te中,init这个domain的规则:
# init switches to init domain (via init.rc).
type init, domain;
# init is unconfined.
unconfined_domain(init)
tmpfs_domain(init)
allow init self:capability { sys_rawio mknod };
.........
domain_trans(init, rootfs, adbd)
.........
neverallow { domain -kernel} init:process dyntransition;
..........
首先(除注释以外)第一行,type init, domain;声明init具有domain的属性。这样它就可以和u,r一起,组成合法的安全上下文。
第二行unconfined_domain(init)unconfined_domain是一个宏,定义在external/sepolicy/te_macros文件中,声明init是一个不受限制的domain,它可以访问系统中的大部分资源。宏定义如下:
#####################################
# unconfined_domain(domain)
# Allow the specified domain to perform more privilegedoperations
# than would be typically allowed. Please see the comments atthe
# top of unconfined.te.
#
define(`unconfined_domain', `
typeattribute $1 mlstrustedsubject;
typeattribute $1 unconfineddomain;
')
第三行tmpfs_domain(
1.为独立进程静态的设置安全上下文
on early-init
这一行的作用是让init进程将自己的安全上下文设为u:r:init:s0。
查看external/sepolicy/init.te中,init这个domain的规则:
# init switches to init domain (via init.rc).
type init, domain;
# init is unconfined.
unconfined_domain(init)
tmpfs_domain(init)
allow init self:capability { sys_rawio mknod };
.........
domain_trans(init, rootfs, adbd)
.........
neverallow { domain -kernel} init:process dyntransition;
..........
首先(除注释以外)第一行,type init, domain;声明init具有domain的属性。这样它就可以和u,r一起,组成合法的安全上下文。
第二行unconfined_domain(init)
#####################################
# unconfined_domain(domain)
# Allow the specified domain to perform more privilegedoperations
# than would be typically allowed. Please see the comments atthe
# top of unconfined.te.
#
define(`unconfined_domain', `
typeattribute $1 mlstrustedsubject;
typeattribute $1 unconfineddomain;
')
第三行tmpfs_domain(