Selinux Error while expanding policy libsepol.check_assertions: 2 neverallow failures occurred
添加selinux 权限报以上的错误。
错误缘由
今天在完善一个功能,即将U盘中的文件拷贝到系统的data 目录下。始终拷贝不过去。然后看log,发现了一顿avc的log。这才知道是selinux的锅。log 如下:
type=1400 audit(0.0:257): avc: denied { write } for comm=73656E6420636F6D6D616E6420706F name="terminalplayer-res" dev="mmcblk0p44" ino=128314 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=0
type=1400 audit(0.0:258): avc: denied { open } for comm=73656E6420636F6D6D616E6420706F path=2F646174612F7465726D696E616C706C617965722D7265732FE5B091E5A5B3E697B6E4BBA34F684D5646756C6C4844313038302E617669 dev="mmcblk0p44" ino=128319 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0
PlaysourceManageModel: onOperateInfo:源文件异常,请检查U盘。java.io.FileNotFoundException: /data/terminalplayer-res/[ 196 ]mkv_AVC+AAC(LC)(y-Subtitle)_1280×720.ass (Permission denied)
type=1400 audit(0.0:259): avc: denied { open } for comm=73656E6420636F6D6D616E6420706F path=2F646174612F7465726D696E616C706C617965722D7265732F5B20303932205D6D6B765F4D504547342B4143335F373230C3973430302E6D6B76 dev="mmcblk0p44" ino=128318 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0
Search "error" (202 hits in 1 file)
为了进一步确认是否是selinux权限的问题。我在串口输入了:setenforce 0 然后再去执行拷贝的动作,果然,可以了。
那么既然是这样的话,那就好办了,selinux 缺什么补什么就完事了。
具体可以参考我的这篇博客
这里根据规则直接在system.te 文件中加了下面两句话:
allow system_app system_data_file:dir { read open add_name write create remove_name setattr search };
allow system_app system_data_file:file { open lock create read write rename setattr unlink};
然后开始编译验证。结果,悲剧了,编译报错。谢天谢地,幸好我保存了log。我在编译生成的log 中发现了如下的报错:
[19:27:57]libsepol.report_failure: neverallow on line 458 of system/sepolicy/public/app.te (or line 8377 of policy.conf) violated by allow system_app system_data_file:dir { write create };
[19:27:57]libsepol.report_failure: neverallow on line 458 of system/sepolicy/public/app.te (or line 8377 of policy.conf) violated by allow system_app system_data_file:file { write create unlink };
[19:27:57]libsepol.check_assertions: 2 neverallow failures occurred
[19:27:57]Error while expanding policy
解决
从上面的报错可以看出,是因为app.te 这个文件里面不允许这样做,于是打开app.te,发现了如下字段:
原来这里定义了不允许的权限。所以,改下这里就好了。