当前位置: 首页 > news >正文

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的权限

http://www.lryc.cn/news/329985.html

相关文章:

  • 图解PyTorch中的torch.gather函数和 scatter 函数
  • Pytorch实用教程: torch.tensor()的用法
  • Java设计模式详解:工厂模式
  • Python爬虫:爬虫常用伪装手段
  • 【数据结构】非线性结构---二叉树
  • 【战略前沿】与中国达成生产协议后,飞行汽车即将起飞
  • 谷粒商城实战(007 压力测试)
  • 使用CSS计数器,在目录名称前加上了序号,让目录看起来更加井然有序
  • SSH常见运维总结
  • uni app 扫雷
  • MATLAB绘制堆叠填充图--巧用句柄
  • JQuery的定义
  • 【操作系统】FCFS、SJF、HRRN、RR、EDF、LLF调度算法及python实现代码
  • Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions(IA-YOLO)
  • Mac电脑Jmeter集成到Jenkins,压测多个接口并生成测试报告
  • redis-Hash
  • Kubernetes kafka系列 | Strimzi 部署kafka-bridge
  • AR和VR如何改变客户体验?
  • 微信小程序中实现埋点的方法
  • vue记事本渲染以及交互
  • Zookeeper中的脑裂
  • 【漏洞复现】金和OA XmlDeal.aspx XXE漏洞
  • 对比:React 还是 Vue
  • ubuntu 20.04 SD 卡分区类型 msdos 改为 GPT 的方法
  • Kubernetes(K8s)技术解析
  • Python 基于 OpenCV 视觉图像处理实战 之 OpenCV 简单实战案例 之十 简单颜色反转效果
  • 【ELK+Kafka+filebeat分布式日志收集】部署filebeat和Kibana(三)
  • 二.音视频编辑-媒体组合-播放
  • 前端安全-面试题(2024)
  • CVE-2022-29405 Apache Archiva任意用户密码重置漏洞分析