编写背景

OpenHarmony5.1 某产品A中,Selinux默认打开,使用截屏功能会提示失败。

但是如果setenforce 0 临时关闭selinux,可以截屏成功,此时就需要适配Selinux策略。

 

适配步骤

hdc 连接设备后

1. 清空dmesg 的log数据

dmesg  -c

执行 dmesg | grep denied 显示为空

2. 点击截屏操作后显示截屏失败,再次执行 dmesg | grep denied 结果如下:

# dmesg | grep denied
[  143.499035] audit: type=1400 audit(1771991005.912:286): avc:  denied  { ioctl } for  pid=2461 comm="OS_IPC_1_2540" path="/dev/gk_disp" dev="tmpfs" ino=196 ioctlcmd=0x2227 scontext=u:r:tvservice_factory_host:s0 tcontext=u:object_r:dev_file:s0 tclass=chr_file permissive=0

适配数据:allow tvservice_factory_host dev_file:chr_file  { ioctl } 

3. 查找 tvservice_factory_host.te 文件

进入base/security/selinux_adapter 目录下查找 tvservice_factory_host.te 文件,将allow tvservice_factory_host dev_file:chr_file  { ioctl } 贴到此文件最后

4. 源码根目录下 执行编译命令:

# ./build.sh --product-name 产品名 --ccache --load-test-config=false -T selinux_adapter

5. out目录下生成 policy.31

./out/产品名/obj/base/security/selinux_adapter/policy.31

6. 将policy.31 文件推送到设备  /etc/selinux/targeted/policy 目录下;

7. 执行截屏操作,成功

 

参考文章:

https://laval.csdn.net/67b7e7d3bf22ba11594c6592.html

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐