SEAndroid 一些默认定义

编写和阅读Android中的SELinux的策略时常常会有许多类似“API”的东西无法理解,其实通过如下目录可以很好的去理解为Android已经写好的Sepolicy,也可以理解为Sepolicy Android下的“标准库”

android/system/sepolicy

例如如下文件定义了很多“全局” attribute

public/attributes

在这里可以找到其定义以及注释说明,比如最常见的 domain 属性:

# All types used for processes.
attribute domain;

例如如下文件定义了很多“宏” 或者可以看做sepolicy中的“函数”

public/te_macros

#####################################
# init_daemon_domain(domain)
# Set up a transition from init to the daemon domain
# upon executing its binary.
define(`init_daemon_domain', `
domain_auto_trans(init, $1_exec, $1)
tmpfs_domain($1)
')


#####################################
# app_domain(domain)
# Allow a base set of permissions required for all apps.
define(`app_domain', `
typeattribute $1 appdomain;
# Label ashmem objects with our own unique type.
tmpfs_domain($1)
# Map with PROT_EXEC.
allow $1 $1_tmpfs:file execute;
')


#####################################
# untrusted_app_domain(domain)
# Allow a base set of permissions required for all untrusted apps.
define(`untrusted_app_domain', `
typeattribute $1 untrusted_app_all;
')


#####################################
# file_type_trans(domain, dir_type, file_type)
# Allow domain to create a file labeled file_type in a
# directory labeled dir_type.
# This only allows the transition; it does not
# cause it to occur automatically - use file_type_auto_trans
# if that is what you want.
#
define(`file_type_trans', `
# Allow the domain to add entries to the directory.
allow $1 $2:dir ra_dir_perms;
# Allow the domain to create the file.
allow $1 $3:notdevfile_class_set create_file_perms;
allow $1 $3:dir create_dir_perms;
')

#####################################
# file_type_auto_trans(domain, dir_type, file_type)
# Automatically label new files with file_type when
# they are created by domain in directories labeled dir_type.
#
define(`file_type_auto_trans', `
# Allow the necessary permissions.
file_type_trans($1, $2, $3)
# Make the transition occur by default.
type_transition $1 $2:dir $3;
type_transition $1 $2:notdevfile_class_set $3;
')

许多相对复杂的操作,比如文件的类型转换,进程的类型转换,都可以在这里找到相应比较完善的宏定义,用起来安全可靠又方便。

对于不同类型可以进行的操作可以到如下文件中查找

private/access_vectors

例如,对文件可以进行的操作的定义:

common file
{
    ioctl
    read
    write
    create
    getattr
    setattr
    lock
    relabelfrom
    relabelto
    append
    map
    unlink
    link
    rename
    execute
    quotaon
    mounton
}

Android中服务标签的定义文件:

private/service_contexts

Android中系统属性标签的定义文件:

private/property_contexts

Android中系统应用标签的定义文件:

private/seapp_contexts

Android中文件标签的定义:

private/file_contexts

Hal 服务bin文件的定义:

private/hwservice_contexts

其他以.te结尾的文件都是Android自带的策略文件,可以作为学习SELinux策略很好的例子。

你可能感兴趣的:(SEAndroid 一些默认定义)