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策略很好的例子。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 编译 SELinux 政策 本文介绍了如何编译 SELinux 政策。SELinux 政策组合使用核心 AOSP ...
    uin_sisyphus阅读 6,823评论 1 1
  • 版权说明:本文为 开开向前冲 原创文章,转载请注明出处;注:限于作者水平有限,文中有不对的地方还请指教 1. SC...
    开开向前冲阅读 5,442评论 0 2
  • SELinux概念 以一个例子来记录下学习SEAndroid的笔记。 需求:很简单,一个system进程要往Ser...
    杰杰_88阅读 5,613评论 0 6
  • 快速阅读 框架 SELinux介绍 看Android怎么写? 如何确认是SELinux 约束引起? 怎么抓取SEL...
    锄禾豆阅读 36,926评论 12 17
  • 进程和文件/目录的标签查看 在支持SELinux的系统中,所有的进程都有一个SELinux的标签,查看进程的标签可...
    杰杰_88阅读 7,337评论 2 2