高通平台中为一个server添加SELinux权限
TNT_TT
2019-04-03 12:00:56
596
收藏
1
分类专栏:
Linux 设备驱动
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_24622489/article/details/88992098
版权
假设我们在Android平台中实现了一个server,编译生成的应用程序位于/vendor/bin/testfd.下面为这个应用程序添加selinx权限。 1.在devices/qcom/sepolicy/vendor/common/目录下新建一个testfd.te文件,这个文件将用来添加testfd这个应用程序的权限。 2.将testfd.te这个文件加入到devices/qcom/sepolicy/Androd.mk中BOARD_SEPOLICY_UNION的列表中。现在的Android P 版本已经不用进行这步操作了,只需在第一步创建文件即可,Androd.mk的组织结构改进了。 3.在testfd.te 中定义新的domain 名字(testfd)和新的执行程序 文件type(testfd_exe)
type testfd, domain;
type testfd_exec, exec_type, file_type;
//如果这个server是被init进程启动的话还需要进行如下定义来进行作用域的转换
init_daemon_domain(testfd)
1234
4.在devices/qcom/sepolicy/vendor/common/目录下的file_contexts文件中加上我们自己的server的type和server将要访问和生成的文件的type。
//我们server的type
/(vendor | system/vendor)/bin/testfd u:object_r:testfd_exec:s0
//server访问文件的type,假设server生成的文件目录是/data/vendor/testfd
/data/vendor/testfd(/.)? u:object_r:testfd_log_file:s0
/dev/socket/testfd(/.)? u:object_r:testfd_socket:s0
/data/system/testfd(/.*)? u:object_r:testfd_data_file:s0
123456
我们server生成的文件testfd_log_file 还没有定义,需要在devices/qcom/sepolicy/vendor/common/目录下的file.te中加上
type testfd_log_file , fs_type, data_file_type;
//后面的这些attribute根据具体文件位置来选,data分区下的data_file_type,sys目录下的就是sysfs_file_type具体视情况而定
12
5.最后一步,就是在testfd.te文件下面加上我们自己设置的权限即可。
allow testfd testfd_socket:dir rw_dir_perms;
allow testfd testfd_data_file:file { create_file_perms unlink };
123
修改完成以后需要重新编译boot.img和system.img,然后重新烧录运行。 开机以后可以使用ls -Z和ps -Z来查看相应的文件和server的权限设置
最后,假如你的Android系统kernel log出现了seLinux权限禁止访问的avc log,下面是修复案例:
//错误log信息如下
Line 841: [ 62.078199] type=1400 audit(86434.459:326): avc: denied { write } for pid=1701 comm=“mpdecision” name=“socket” dev=“tmpfs” ino=7171 scontext=u:r:init:s0 tcontext=u:object_r:socket_device:s0 tclass=dir
12
将以上信息保存为avc.txt,然后使用Ubuntu的audit2allow工具来自动生成权限信息: audit2allow -i avc.txt
allow init socket_device:sock_file { write create setattr };
1
done
————————————————
版权声明:本文为CSDN博主「TNT_TT」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_24622489/article/details/88992098