Android Selinux增加权限策略

624 阅读1分钟

最近遇到一个权限问题,解决之路非常崎岖。问题详情是这样的:android10 mtk平台下有个节点 dev/ttyS1, 对应的是北斗模块的串口数据。北斗应用需要监对串口数据进行解析,对出口需要读写权限。针对这种dev的节点配置如下,亲测有效。

log如下: 2022-10-07 18:23:38.328 4715-4715/com.coresat.dwxj I/om.coresat.dwxj: type=1400 audit(0.0:603): avc: denied { read } for name="ttyS1" dev="tmpfs" ino=16436 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:ttyS_device:s0 tclass=chr_file permissive=1 app=com.coresat.dwxj

增加权限步骤: 1,在device目录下找到platform_app.te文件增加下面: allow platform_app spidev_device:chr_file {ioctl getattr open read write}

2,在device目录下找到file_contexts定义文件: /dev/ttyS1 u:object_r:spidev_device:s0

3,在device目录下找到file.te定义文件: type spidev_device, dev_type, mlstrustedobject;