- 1. 配置SELinux权限
SELinux(或SEAndroid)主要将app划分为三种类型(根据user不同,也有其他的domain类型):
1)untrusted_app 第三方app,没有android平台签名,没有system权限
2)platform_app 有android平台签名,没有system权限
3)system_app 有android平台签名和system权限
从上面划分,权限等级,理论上:untrusted_app < platform_app < system_app
TE介绍:
allow netd proc:file write
这条语句的语法为:
allow:TE的allow语句,表示授权。除了allow之外,还有allowaudit、dontaudit、neverallow等。
netd:source type。也叫subject,domain。
proc:target type。它代表其后的file所对应的Type。
file:代表Object Class。它代表能够给subject操作的一类东西。例如File、Dir、socket等。在Android系统中,有一个其他Linux系统没有的Object Class,那就是Binder。
write:在该类Object Class中所定义的操作。
根据SELinux规范,完整的allow相关的语句格式为:
rule_name source_type target_type : class perm_set
我们直接来看几个实例:
[例子3]
//SEAndroid中的安全策略文件policy.conf
#允许zygote域中的进程向init type的进程(Object Class为process)发送sigchld信号
allow zygote init:process sigchld;
#允许zygote域中的进程search或getattr类型为appdomain的目录。注意,多个perm_set
#可用{}括起来
allow zygote appdomain:dir { getattr search };
#来个复杂点的:
#source_type为unconfineddomain target_type为一组type,由
#{ fs_type dev_type file_type }构成。object_class也包含两个,为{ chr_file file }
#perm_set语法比较奇特,前面有一个~号。它表示除了{entrypoint relabelto}之外,{chr_file #file}这两个object_class所拥有的其他操作
allow unconfineddomain {fs_type dev_type file_type}:{ chr_file file } \
~{entrypoint relabelto};
#特殊符号除了~外,还有-号和*号,其中:
# 1):-号表示去除某项内容。
# 2):*号表示所有内容。
#下面这条语句中,source_type为属于appdomain,但不属于unconfinedomain的进程。
#而 *表示所有和capability2相关的权限
#neverallow:表示绝不允许。
neverallow { appdomain -unconfineddomain } self:capability2 *;
type的定义:
type命令的完整格式为:type type_id [alias alias_id,] [attribute_id]
其中,方括号中的内容为可选。alias指定了type的别名,可以指定多个别名
/device/qcom/sepolicy/common/
1 file.te 定义 sysfs_brightness
type sysfs_brightness, sysfs_type, fs_type;
2 file_comtexts 配置sysfs_brightness
/sys/class/leds/lcd-backlight/brightness