SeLinux 常见的宏

在SeLinux框架中,google定义好了一些宏,我们使用这些宏,开发时可以更加方便。大部分的宏是定义在te_macros文件中

type_transition

type_transition source_type target_type : class default_type

当主体进程域source_type 对target_type 类型的客体进行class 定义的操作时,主体或者客体会切换到default_type。意味着该声明是可以描述主体和客体的类型切换的, 比如客体文件类型切换, 或者主体进程域的type 切换(上下文切换), 注意:此时只是描述了从哪里切换到哪里的问题。
比如:

type_transition vold storage_file:dir storage_stub_file;

vold进程在对打了storage_file标签的目录中创建一个文件,子文件的上下文应该变成storage_stub_file标签,而不是继承父目录的上下文

domain_trans
domain_trans(olddomain, target_type, newdomain)

允许在olddomain 操作target_type 时,从olddomain 到newdomain 转化规则。主要针对进程上下文的转换。注意:该宏只是申请允许切换,相当于为type_transition申请切换的权限

domain_auto_trans
是type_transition和domain_trans的结合,可以使用该宏,将上下文转换过去

define(`domain_auto_trans', `
domain_trans($1,$2,$3)
type_transition $1 $2:process $3;
')

示例:

domain_auto_trans(adbd, shell_exec, shell)

允许adbd进程,在执行shell_exec上下文的可执行程序时,自动切换到shell进程上下文

init_daemon_domain

init_daemon_domain(domain)
等同于domain_auto_trans

define(`init_daemon_domain', `
domain_auto_trans(init, $1_exec, $1)
')

我们自定义init进程启动的服务时,需要加上这个来切换进程的上下文。注意第二个参数,该服务的bin程序的安全上下文要配置成固定的。如:

type adbd, domain;
type adbd_exec, exec_type, file_type, system_file_type;
init_daemon_domain(adbd)

init 启动 adbd_exec程序时,启动的进程允许配置成adbd上下文

file_type_trans
file_type_trans(domain, dir_type, file_type)

申请在某个domain(进程)在安全上下文为dir_type的目录下,创建文件,新文件的安全上下文为file_type的权限。注意该宏只是申请切换的权限。

define(`file_type_trans', `
allow $1 $2:dir ra_dir_perms;
allow $1 $3:notdevfile_class_set create_file_perms;
allow $1 $3:dir create_dir_perms;
')

file_type_auto_trans
file_type_auto_trans(domain, dir_type, file_type)
相当于domain_auto_trans。除了申请权限外,还会执行真正的切换。

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;
')

r_dir_file

define(`r_dir_file', `
allow $1 $2:dir r_dir_perms;
allow $1 $2:{ file lnk_file } r_file_perms;
')

r_dir_file(domain, type)
允许domain(进程)对安全上下文为type的目录有r_dir_perms权限,文件和lnk_file 有r_file_perms权限
其中r_dir_perms和r_file_perms的定义在global_macros文件中

define(`r_dir_perms', `{ open getattr read search ioctl lock watch watch_reads }')
define(`r_file_perms', `{ getattr open read ioctl lock map watch watch_reads }')

net_domain

#####################################
# net_domain(domain)
# Allow a base set of permissions required for network access.
define(`net_domain', `
typeattribute $1 netdomain;
')

domain继承netdomain,为domain定义访问网络所需的基本权限

set_prop

#####################################
# set_prop(sourcedomain, targetproperty)
# Allows source domain to set the
# targetproperty.
#
define(`set_prop', `
unix_socket_connect($1, property, init)
allow $1 $2:property_service set;
get_prop($1, $2)
')

允许sourcedomain对targetproperty系统属性具有set的权限

get_prop

#####################################
# get_prop(sourcedomain, targetproperty)
# Allows source domain to read the
# targetproperty.
#
define(`get_prop', `
allow $1 $2:file { getattr open read map };
')

允许sourcedomain对targetproperty系统属性具有get的权限

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值