完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
Platform: RK3399 OS: Android 7.1 Kernel: v4.4.83 说明: 之前在处理mtp的问题将Selinux改成了permissive后,出现了自己添加的后台服务无法起来的问题,比如添加了自己实现的batteryd服务。 Log: init: Service batteryd does not have a SELinux domain defined. 原因: SELinux安全检查机制被启用后会对新加的服务做检查。 解决方法: 以添加batteryd服务为例. init.rc中添加 service batteryd /system/bin/batteryd class late_start user root oneshot seclabel u:r:batteryd:s0 file_contexts添加: kris@ecobsp:~/rk3399/device/rockchip/common/sepolicy$ g df diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index d33fb31..73f0729 100755 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -152,3 +152,9 @@ /dev/block/mmcblk1 u:object_r:uboot_block_device:s0 /dev/block/mmcblk1rpmb u:object_r:rpmb_block_device:s0 + +/system/bin/batteryd u:object_r:batteryd_exec:s0 再在上面目录添加新文件 batteryd.te type batteryd, domain; type batteryd_exec, exec_type, file_type; init_daemon_domain(batteryd) 编译生成boot.img,可以看到batteryd服务已经起来了 rk3399_mid:/ $ ps | grep batteryd root 246 1 10032 1968 0 0000000000 S /system/bin/batteryd 不过还是有些问题 [ 2.578694] type=1400 audit(1514752624.453:16): avc: denied { create } for pid=246 comm="batteryd" scontext=u:r:batteryd:s0 tcontext=u:r:batteryd:s0 tclass=tcp_socket permissive=1 [ 2.578851] type=1400 audit(1514752624.453:17): avc: denied { net_raw } for pid=246 comm="batteryd" capability=13 scontext=u:r:batteryd:s0 tcontext=u:r:batteryd:s0 tclass=capability permissive=1 [ 2.579176] type=1400 audit(1514752624.456:18): avc: denied { setopt } for pid=246 comm="batteryd" scontext=u:r:batteryd:s0 tcontext=u:r:batteryd:s0 tclass=tcp_socket permissive=1 [ 2.579288] type=1400 audit(1514752624.456:19): avc: denied { bind } for pid=246 comm="batteryd" scontext=u:r:batteryd:s0 tcontext=u:r:batteryd:s0 tclass=tcp_socket permissive=1 接着收集所有相关avc denied的信息 dmesg | grep avc > /sdcard/avc_log.txt ubuntu上再安装工具 sudo apt-get install policycoreutils 过滤出batteryd相关log audit2allow -i avc_log.txt 得到batteryd相关结果如下: #============= batteryd ============== allow batteryd node:tcp_socket node_bind; allow batteryd port:tcp_socket name_bind; allow batteryd rootfs:lnk_file getattr; allow batteryd self:capability net_raw; allow batteryd self:tcp_socket { bind create setopt accept listen }; allow batteryd system_file:file entrypoint; 把上面信息copy到batteryd.te中,再次编译boot.img, 会出现如下错误: FAILED: /bin/bash -c "(out/host/linux-x86/bin/checkpolicy -M -c 30 -o out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.tmp out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/policy.conf ) && (out/host/linux-x86/bin/checkpolicy -M -c 30 -o out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates//sepolicy.dontaudit out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/policy.conf.dontaudit ) && (out/host/linux-x86/bin/sepolicy-analyze out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.tmp permissive > out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains ) && (if [ "user" = "user" -a -s out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains ]; then echo "==========" 1>&2; echo "ERROR: permissive domains not allowed in user builds" 1>&2; echo "List of invalid domains:" 1>&2; cat out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains 1>&2; exit 1; fi ) && (mv out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy.tmp out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/sepolicy )" libsepol.report_failure: neverallow on line 237 of system/sepolicy/domain.te (or line 8823 of policy.conf) violated by allow batteryd system_file:file { entrypoint }; libsepol.check_assertions: 1 neverallow failures occurred Error while expanding policy out/host/linux-x86/bin/checkpolicy: loading policy configuration from out/target/product/rk3399_mid/obj/ETC/sepolicy_intermediates/policy.conf ninja: build stopped: subcommand failed. make: *** [ninja_wrapper] Error 1 #### make failed to build some targets (05:59 (mm:ss)) #### 修改domain.te文件: kris@ecobsp:~/rk3399/system/sepolicy$ g df diff --git a/domain.te b/domain.te index 45569de..0c02969 100644 --- a/domain.te +++ b/domain.te @@ -234,7 +234,7 @@ neverallow { domain -init } kernel:security setsecparam; neverallow { domain -init -system_server -ueventd } hw_random_device:chr_file *; # Ensure that all entrypoint executables are in exec_type or postinstall_file. -neverallow * { file_type -exec_type -postinstall_file }:file entrypoint; +neverallow { -batteryd } { file_type -exec_type -postinstall_file }:file entrypoint; # Ensure that nothing in userspace can access /dev/mem or /dev/kmem neverallow { domain -kernel -ueventd -init } kmem_device:chr_file *; 编译通过, 烧录开机正常。 原作者:KrisFei |
|
相关推荐
1个回答
|
|
6666
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1924 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
2406 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
5193 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 22:03 , Processed in 0.723405 second(s), Total 71, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号