SElinux和SEandroid验证denied处理

来源:互联网 发布:2010年人口普查数据 编辑:程序博客网 时间:2024/05/22 10:12

SEandroid和SElinux在加入到android4.X之后,

在开发的过程中经常会在log中看到类似下面的denied信息,这是由于在相应的进程没有操作权限造成的,这些权限在sepolicy中没有被允许,

或者是没有继承父进程的权限。


<5>[77037.274119] [(2015-01-20 09:17:42.876329323 UTC)] [cpuid: 2] type=1400 audit(1421745462.859:2172964): avc:  denied  { write } for  pid=15848 comm="system_server" name="enable" dev="sysfs" ino=9381 scontext=u:r:zygote:s0 tcontext=u:object_r:sysfs:s0 tclass=file

<5>[77037.841329] [(2015-01-20 09:17:43.443539322 UTC)] [cpuid: 0] type=1400 audit(1421745463.429:2172966): avc:  denied  { open } for  pid=15871 comm="ActivityManager" name="stat" dev="proc" ino=5513 scontext=u:r:zygote:s0 tcontext=u:r:init:s0 tclass=file

<5>[77037.912449] [(2015-01-20 09:17:43.514659321 UTC)] [cpuid: 2] type=1400 audit(1421745463.509:2172968): avc:  denied  { open } for  pid=15871 comm="ActivityManager" name="stat" dev="proc" ino=5515 scontext=u:r:zygote:s0 tcontext=u:r:kernel:s0 tclass=file


这种情况可能发生在代码中fork一个进程或者调用system()函数进行read/write某个file时就会出现这些denied,使得操作无法进行。
那么如何处理这些denied信息,


我们拿上面的log作为例子,可以在extern/sepolicy下新建一个test.te文件(这个目录下的te文件会自动全部加入编译),比如

test.te


allow zygote sysfs:file write; #允许源上下文类型是zygote的进程对目的上下文类型是sysfs的file进行write操作

allow zygote init:file open;

allow zygote kernel:file open;

这样就可以保证上面的log中就不会再出现这些denied了。


如果我们想验证已经写好的一些te文件是否生效,当然很简单,只需要我们将这些allow删除就可以看到效果了。


比如说external/sepolicy/unconfined.te(android代码中已经有了),我们想不允许adb shell 中的 setprop操作,

setprop 在external/sepolicy/shell.te中被加到unconfineddomain不受限的域(domain)中,所以在unconfined.te可以看到


allow unconfineddomain property_type:property_service set;

#unconfineddomain被允许对property_type类型的property_service进行set操作,


那么只要我们将这行删除allow unconfineddomain property_type:property_service set;

就再重新编译kernel烧进机器,就可以从log中看到

adb shell setprop test xx

不能再被使用的denied的信息。





0 0
原创粉丝点击