Aispeech Audio Hal porting到android系统中需要添加如下selinux权限(android8.1): diff --git a/system/sepolicy/public/domain.te b/system/sepolicy/public/domain.te --- a/system/sepolicy/public/domain.te +++ b/system/sepolicy/public/domain.te @@ -623,6 +623,7 @@ full_treble_only(`     -coredomain     -netdomain     -socket_between_core_and_vendor_violators +    -hal_audio   }, netd);

# Vendor domains are not permitted to initiate create/open sockets owned by core domains diff --git a/system/sepolicy/public/hal_audio.te b/system/sepolicy/public/hal_audio.te index 33330bf..e69a19b7 100644 --- a/system/sepolicy/public/hal_audio.te +++ b/system/sepolicy/public/hal_audio.te @@ -32,7 +32,7 @@ neverallow hal_audio { file_type fs_type }:file execute_no_trans;

# Should never need network access. # Disallow network sockets. -neverallow hal_audio domain:{ tcp_socket udp_socket rawip_socket } *; +#neverallow hal_audio domain:{ tcp_socket udp_socket rawip_socket } *;

# Only audio HAL may directly access the audio hardware neverallow { halserverdomain -hal_audio_server } audio_device:chr_file *; diff --git a/system/sepolicy/public/hal_neverallows.te b/system/sepolicy/public/hal_neverallows.te index 036e1d2..13f78aa 100644 --- a/system/sepolicy/public/hal_neverallows.te +++ b/system/sepolicy/public/hal_neverallows.te @@ -16,6 +16,7 @@ neverallow {   -hal_wifi_server   -hal_wifi_supplicant_server   -rild +  -hal_audio } domain:{ tcp_socket udp_socket rawip_socket } *;

###

diff --git a/device/rockchip/common/sepolicy/hal_audio_default.te b/device/rockchip/common/sepolicy/hal_audio_default.te index ebc2023..f96c83d 100644 --- a/device/rockchip/common/sepolicy/hal_audio_default.te +++ b/device/rockchip/common/sepolicy/hal_audio_default.te @@ -7,3 +7,18 @@ allow hal_audio_default hidraw_device:chr_file { open read write };

set_prop(hal_audio_default,media_prop) allow hal_audio_default sysfs:file rw_file_perms; + +#for aispeech +allow hal_audio_default hal_audio_default:udp_socket { create bind write read getattr }; +allow hal_audio_default hal_audio_default:tcp_socket { create connect getopt setopt read write

name_connect }; +allow hal_audio_default audioserver_data_file:dir { add_name remove_name write search }; +allow hal_audio_default port:tcp_socket name_connect; +allow hal_audio_default audioserver_data_file:file { write open getattr create }; +allow hal_audio_default node:udp_socket node_bind; +allow hal_audio_default netd:unix_stream_socket connectto; +allow hal_audio_default fwmarkd_socket:sock_file write; +allow hal_audio_default audioserver_data_file:file unlink; + +#fixed common +#allow hal_audio_default vendor_shell_exec:file execute_no_trans; +#allow hal_audio_default su_exec:file { execute_no_trans read open getattr}; diff --git a/device/rockchip/common/sepolicy/netd.te b/device/rockchip/common/sepolicy/netd.te index 3acb9a6..34f814f 100644 --- a/device/rockchip/common/sepolicy/netd.te +++ b/device/rockchip/common/sepolicy/netd.te @@ -9,3 +9,7 @@ allow netd netd:netlink_scsitransport_socket { create setopt bind write read get allow netd netd:netlink_rdma_socket { create setopt bind write read getopt getattr }; allow netd netd:netlink_crypto_socket { create setopt bind write read getopt getattr };

+#for aispeech +allow netd hal_audio_default:tcp_socket { setopt getopt read write}; +allow netd hal_audio_default:udp_socket { setopt getopt read write}; +allow netd hal_audio_default:fd { use }; 说明:以上修改可以过selinux验证,但是有修改系统默认selinux权限,无法过CTS某些测试。 见下面: armeabi-v7a CtsSecurityHostTestCases Test Result Details

android.cts.security.SELinuxNeverallowRulesTest# testNeverallowRules56 fail

junit.framework.AssertionFailedError: The following errors were encountered when validating the SELinuxneverallow rule:

使用脚本添加selinux

2.2.2Selinux 添加方法
Selinux 在 Android5.1 之后被真正的引入到 android 系统之中。目前在 Android8.0 及以上 系统常见 selinux 处于打开状态。详细的 Selinux 规则此处不再描述。Selinux 规则可以根据 log 中的提示信息进行添加。以 AispeechAudioHal 为例,开机之后可以通过 grep logcat 获取 selinux 的警告信息。命令如下: logcat|grepavc 或者 logcat |grepdenied 从 log 中再筛选出 audioserver 相关的 log,部分如下所示: 7 04-15 16:11:41.440 316 316 I Auth : type=1400 audit(0.0:9): avc: denied { read } for name="address" dev="sysfs" ino=14731 scontext=u:r:audioserver:s0 tcontext=u:object_r:sysfs:s0tclass=file permissive=1 8 04-15 16:11:41.440 316 316 I Auth : type=1400 audit(0.0:10): avc: denied { open } for path="/sys/devices/platform/fe300000.ethernet/net/eth0/address" dev="sysfs" ino=14731 scontext=u:r:audioserver:s0 tcontext=u:object_r: sysfs:s0 tclass=file permissive=1 9 04-15 16:11:41.443 316 316 I Auth : type=1400 audit(0.0:11): avc: denied { getattr } for path="/sys/devices/platform/fe300000.ethernet/net/eth0/address" dev="sysfs" ino=14731 scontext=u:r:audioserver:s0 tcontext=u:object _r:sysfs:s0 tclass=file permissive=1 10 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:12): avc: denied { create } for scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0 tclass=udp_socket permissive=1
11 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:13): avc: denied { bind } for scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0 tclass=udp_socket permissive=1 12 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:14): avc: denied { node_bind } for saddr=127.0.0.1 scontext=u:r:audioserver:s0 tcontext=u:object_r:node:s0 tclass=udp_socketpermissive=1 13 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:15): avc: denied { getattr } for laddr=127.0.0.1 lport=42108 scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0tclass=udp_socketpermissive=1 14 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:16): avc: denied { write } for name="fwmarkd" dev="tmpfs" ino=16490 scontext=u:r:audioserver:s0 tcontext=u:object_r:fwmarkd_socket:s0tclass=sock_file permissive=1 15 04-15 16:11:41.460 316 316 I Auth : type=1400 audit(0.0:17): avc: denied { connect } for scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0 tclass=udp_socket permissive=1 16 04-15 16:11:41.466 316 316 I Auth : type=1400 audit(0.0:18): avc: denied { write } for scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0 tclass=udp_socket permissive=1 17 04-15 16:11:51.483 316 316 I Auth : type=1400 audit(0.0:19): avc: denied { create } for scontext=u:r:audioserver:s0 tcontext=u:r:audioserver:s0 tclass=tcp_socket permissive=1 18 04-15 16:11:51.483 316 316 I Auth : type=1400 audit(0.0:20): avc: denied { write } for name="fwmarkd" dev="tmpfs" ino=16490 scontext=u:r:audioserver:s0 tcontext=u:object_r:fwmarkd_socket:s0tclass=sock_file permissive=1 19 04-15 16:11:51.483 316 316 I Auth : type=1400 audit(0.0:21): avc: denied { connectto } for path="/dev/socket/fwmarkd" scontext=u:r:audioserver:s0 tcontext=u:r:netd:s0tclass=unix_stream_socket permissive=1 把所有相关 log 全部筛选出来,存放在一个log 文件中, 例如存放在名为audiohal_avc.log 的文件中。

通过如下命令可以自动生成 avc 规则: external/selinux/prebuilts/bin$ ./audit2allow -i audiohal_avc.log

生成的规则如下:

#============= audioserver==============

allow  audioserver:fileopen;

allow  audioserverfwmarkd_socket:sock_filewrite;

allow  audioservernetd:unix_stream_socket connectto;

allow  audioservernode:udp_socketnode_bind; allowaudioserverself:tcp_socket create;

allow audioserverself:udp_socket{writebindcreategetattrconnect};

将上述规则添加到相应的系统 te 文件中即可。

系统 xxx.te 文件存放位置一般在如下两个地方:

1./external/sepolicy(注 7.0 及以上在/system/sepolicy)下面的 xxx.te

2.device/xxxxxxxx/common/sepolicy 下面的 xxxx.te。 添加好规则之后重新编译固件进行刷机测试,重复上述步骤,直到 log 中没有再出现audiohal avc 相关提示警告信息。

添加规则编译的时候有可能会出现 neverallow 规则冲突,导致编译出错。此时需要到 系统限定 neverallow 规则的 te 文件中去掉相关限制即可编译通过。

更加详细的方法可以 自行查看相关资料。修改 neverallow 规则会导致 cts 测试无法通过,请知悉。如果系统无 需过 cts 认证,可以按需求修改系统 neverallow 规则。

selinux-添加相关推荐

  1. 2022-07-20 Android 11 SELinux avc 修改sys目录下面某个节点的权限

    一.我这里有/sys/devices/platform/thermal-camera-control/powerenable 这样一个节点,用命令ls -Z 查看该文件的域. 二.我现在在一个普通ap ...

  2. centos 修改ssh默认端口号

    linux服务器一般默认的ssh端口号都为22,所以在大部分的使用者手中出于安全考虑就需要修改ssh的默认端口号,下面为为修改ssh默认端口号方法 一:修改/etc/ssh/sshd_config配置 ...

  3. Docker启动Mysql容器失败,挂载时权限不足,chown: changing ownership of ‘/var/lib/mysql/‘: Permission denied

    文章目录 1. 现象 2. 查看日志分析 3. 提示信息 4. 解决方案 5. 再次执行成功 6. 技巧 1. 现象 今天用Docker运行Mysql容器时,一直启动不了,删除了重新制作容器也不行 镜 ...

  4. b宝塔 centos端口更改_centos修改ssh默认端口号的方法示例

    linux 一:修改/etc/ssh/sshd_config配置文件(注意:这里是sshd_config,而不是ssh_config) 1:查看ssh的默认端口号 netstat -anp|grep ...

  5. linux 7 打开22端口号,Centos 7 修改 SSH 默认端口号

    为了增强服务器的网络安全,我们增加了服务器的云安全中心企业版,同时我们修改 SSH 的默认端口号 Linux 服务器的 SSH 默认端口号为 22 ,大家都使用这个默认的端口号,虽说方便,但是也增加了 ...

  6. Mysql组复制(MGR)——常问的问题

    本文提供常被问到问题的答案. 1.复制组中最多能有多少个mysql服务器? 复制组最多包含9个mysql服务器.尝试向已有9个服务器的组添加另外的服务器将被拒绝. 2.组内服务器间如何连接? 组内服务 ...

  7. chown: changing ownership of ‘/var/lib/mysql/‘: Permission denied

    今天在搭建mysql集群的时候发现一个问题,我创建的docker master实例为下面的语句: docker run -p 3307:3306 --name mysql-master -v /myd ...

  8. Linux 修改ssh端口 | Bind to port 2222 on 0.0.0.0 failed: Permission denied

    文章目录 修改配置文件 防火墙放行 SELinux添加修改的SSH端口 重启服务 修改配置文件 vi /etc/ssh/sshd_config 添加2222 # If you want to chan ...

  9. Ansible篇-CentOS7安装AWX详解

    1 引言 网上很多教程,但是根据教程安装一直报错,唉,排错重重,赶紧记下笔记! 2 系统要求 至少4G内存 至少2 CPU 至少20G磁盘空间 可运行docker,k8s,openshift 3 环境 ...

  10. Kubernetes 用kubeadm安装kubernetes_v1.18.x

    Kubernetes 用kubeadm安装kubernetes_v1.18.x 安装参考 https://kuboard.cn/install/install-k8s.html#%E7%A7%BB%E ...

最新文章

  1. RunTime的使用-Category改变整个项目全部字体
  2. 希尔排序python实现
  3. 跨域资源共享 CORS 详解
  4. html美甲预约网页制作,教程.html · NFS1077/FNM美甲店 - Gitee.com
  5. 大数据 -- Spark
  6. (85)FPGA约束有哪些-面试必问(九)(第17天)
  7. Java研发知识图谱
  8. pid调节软件_(四)差分底盘设计——5.底盘PID控制参数整定
  9. viewport就是这回事
  10. java对数据库的基础知识
  11. 利用辗转相除法——求最大公约数(详解)
  12. 关于贯彻《财政部 税务总局关于调整增值税税率的通知》的通知 〔2018〕405
  13. 内存不能为read大全
  14. 微信7012android1620,微信7012版
  15. 看完Alibaba“Java成长笔记”我懂了! 为什么阿里的程序员成长如此之快?
  16. 人类第一张黑洞照片背后的功臣,竟然是她!
  17. 哪个国家程序员最多?不是美国和中国,是这个‘落后’的亚洲国家
  18. python基础—3
  19. linux系统启动的第一个进程是,CentOS6开机启动过程详解
  20. 空气动力学基础课堂笔记

热门文章

  1. 【ObjectC—浅copy和深copy】
  2. ADO.NET中异步处理的方式
  3. TreeView控件节点重命名后没有进入beginEdit的解决方案
  4. 修改已经打开的对话框的浏览路径
  5. UA PHYS515A 电磁理论III 静磁学问题2 标量势方法与向量势方法简介
  6. 首次使用Windbg调试dNet程序
  7. Windows内核对象管理
  8. 安装了超图、oracle、eclipse、JDK后系统的java进程情况以及java.exe、javaw.exe
  9. python数组排序(递归实现)
  10. 大话设计模式-备忘录模式