selinux - Android编写sepolicy

为service编写sepolicy由init启动的service服务要在各自的selinux domain中运行。
摘要由CSDN通过智能技术生成

为service编写sepolicy

由init启动的service服务要在各自的selinux domain中运行。具体flow如下:
init.devices.rc中声明service,将在init时启动:
init.rc z中服务定义
Note:seclabel标签用作设定service运行domain,如果设置了如下的init_daemon_domain便不需要该标签,该标签的优先级比init_daemon_domain要高

1 创建一个新的domain及file type

创建sepolicy文件device/manufacturer/device-name/sepolicy/mt_wlan_dongle_detect.te
内容如下:
在这里插入图片描述
Note:不是一定要使用目录device/manufacturer/device-name/sepolicy,以BOARD_SEPOLICY_DIRS宏为准 指定device sepolicy目录
L1 创建mt_wlan_dongle_detect domain
L2 创建mt_wlan_dongle_detect_exec file type
L3 声明为init的 service domain
init_daemin_damain实现如下, 主要是设置selinux,在init执行service bin时,允许由init domain自动转到service对应的domain:

/system/sepolicy/prebuilts/api/30.0/public/te_macros
#####################################
159 # init_daemon_domain(domain)
160 # Set up a transition from init to the daemon domain
161 # upon executing its binary.
162 define(`init_daemon_domain', `
163 domain_auto_trans(init, $1_exec, $1)
164 ')

#####################################
24 # domain_auto_trans(olddomain, type, newdomain)
25 # Automatically transition from olddomain to newdomain
26 # upon executing a file labeled with type.
27 #
28 define(`domain_auto_trans', `
29 # Allow the necessary permissions.
30 domain_trans($1,$2,$3)
31 # Make the transition occur by default.
32
  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值