当前位置:   article > 正文

Android7.1 Selinux使用_手机selinux在哪

手机selinux在哪

讲Selinux的原理的文章太多了,讲实际使用也是有一些,但是都不够完整,这里举一个在Android7.1下的服务的例子。

服务第一步,我们会在init.rc下增加服务。 
因为我的设备是freesale sabresd 所以路径是: 
device/fsl/sabresd_6dq/init.rc

  1. service crondd /system/bin/crondd
  2. class late_start
  3. user root
  • 1
  • 2
  • 3
  • 4

接着我把重新编译过boot.img镜像烧录进设备,我使用命令 
start crondd 毫无疑问系统提示 
init: Service crondd does not have a SELinux domain defined.

接着我们需要给我们的crondd 增加一下domain:

这里我的增加的目录为: 
device/fsl/imx6/sepolicy/crondd.te 
或者这里也行: 
system/sepolicy/ 
通用的目录是,另外包含的路径可以参考一下system/sepolicy/Android.mk

具体什么意思就不解释了。

  1. type crondd, domain, domain_deprecated;
  2. type crondd_exec, exec_type, file_type;
  3. type crondd_device, dev_type;
  4. type crondd_data_file, file_type, data_file_type;
  5. init_daemon_domain(crondd)
  6. allow crondd crondd_data_file:dir rw_dir_perms;
  7. allow crondd crondd_data_file:file create_file_perms;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

然后重新编译boot.img 我们再将服务启动起来,这时候我们能看到一些selinux打印出来的信息。

现在我们关闭掉selinux: 
setenforce 0

然后把所有的selinux收集起来: 
dmesg | grep avc > /data/avc_log.txt

这些信息我们可以用工具翻译出来,如果一句句自己翻译估计要崩溃了。 
ubuntu下: 
sudo apt install policycoreutils

然后: 
audit2allow -i avc_log.txt

  1. #============= crondd ==============
  2. allow crondd busybox_exec:file { read getattr open execute execute_no_trans };
  3. allow crondd dex2oat:dir { getattr search };
  4. allow crondd dex2oat:file { read open };
  5. allow crondd platform_app:dir { getattr search };
  6. allow crondd platform_app:file read;
  7. allow crondd priv_app:dir { getattr search };
  8. allow crondd priv_app:file read;
  9. allow crondd untrusted_app:dir { getattr search };
  10. allow crondd untrusted_app:file read;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

很简单,把这些全部拷贝进去就可以了。 
这个工作很有可能重复很多次,因为有些命令是因为selinux 或者权限的问题执行失败,要一步一步的加。

其中有一种情况,用selinux的工具似乎是没法生成,这个只好自己了解一下生成的规则自己凑一下了。 
allow surfaceflinger system_prop:property_service set;

还有一种: 
type=1400 audit(1420226774.850:4466): avc: denied { read } for pid=3978 comm=”busybox” 
scontext=u:r:logdumpd:s0 tcontext=u:r:platform_app:s0:c512,c768 tclass=file permissive=0

需要把.te的第一行修改成:mlstrustedsubject。 
type logdumpd , domain,mlstrustedsubject

关于规则和一些说明可以参考如下网址: 
http://blog.csdn.net/Innost/article/details/19299937 
http://blog.csdn.net/xbalien29/article/details/19505575

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/961995
推荐阅读
相关标签
  

闽ICP备14008679号