[英]Is it possible to use the package name as the domain name in Android SELinux?
Android SELinux( or you can say SEAndroid) defines many domains which include system_app, platform_app, isolated_app, etc. Android SELinux(或者你可以说 SEAndroid)定义了许多域,包括 system_app、platform_app、isolated_app 等。
Each domain has different meanings, for example, system_app includes all the apps which share the system uid, and the platform_app includes all the apps which sign the platform key.每个域都有不同的含义,例如,system_app 包括所有共享系统 uid 的应用程序,而 platform_app 包括所有签署平台密钥的应用程序。
All the SE files are located in external/sepolicy, I can modify the rules from these files.所有 SE 文件都位于 external/sepolicy 中,我可以从这些文件中修改规则。
Is it possible to define a new domain which points to a specified package name (For example, com.google.android.music)?是否可以定义一个指向指定包名称的新域(例如,com.google.android.music)?
I do not find any document or example about that, so I am not sure how to do that.我没有找到任何关于此的文档或示例,所以我不知道该怎么做。
I will appreciate any suggestions or comments.我将不胜感激任何建议或意见。
Thank you.谢谢你。
After a long research, I find a way to define a new domain for a specified package经过长时间的研究,我找到了一种为指定包定义新域的方法
Define a new domain in seapp_contexts
在seapp_contexts
中定义一个新域
like this,像这样,
user=_app domain=googlemusic seinfo=platform name=com.google.android.music type=app_data_file
then define the permission of a new domain googlemusic
然后定义新域googlemusic
的权限
create a te file called googlemusic.te
创建一个名为googlemusic.te
的 te 文件
type googlemusic_app,domain
app_domain(googlemusic)
#more permissions
Just to update @alec.tu answer for Android 12 - in the googlemusic.te file the 2 first lines should be:只是为了更新 Android 12 的@alec.tu 答案 - 在 googlemusic.te 文件中,前两行应该是:
typeattribute googlemusic_app coredomain;
app_domain(googlemusic_app)
And another new file - system/sepolicy/public/googlemusic_app.te should be created with the content:另一个新文件 - system/sepolicy/public/googlemusic_app.te 应该使用以下内容创建:
type googlemusic_app, domain;
Okay, to whoever is trying to achieve this: in AOSP 11, if you are getting an error when building that contains anything with "neverallow", you need to specify a domain for your app.好的,对于任何试图实现这一点的人:在 AOSP 11 中,如果您在构建包含“neverallow”的任何内容时遇到错误,您需要为您的应用程序指定一个域。 I was getting this error while trying this in platform_app.te file in device/ yourvendor / yourdevice /sepolicy by writing a line: allow platform_app sysfs:file { getattr open read };.我在 device/ yourvendor / yourdevice /sepolicy 的 platform_app.te 文件中尝试此操作时遇到此错误,方法是写一行:allow platform_app sysfs:file { getattr open read };。
The build stopped on error while breaking the neverallow rule.构建在违反 neverallow 规则时因错误而停止。
Solution is to open file seapp_contexts and then add a line:解决方法是打开文件 seaapp_contexts 然后添加一行:
Explanation:解释:
user=_app domain=*you can name it whatever you want, lets say selinuxtest, but you have to add "_app", so it should be selinuxtest_app seinfo=platform name=com. user=_app domain=*你可以任意命名,比如说selinuxtest,但是你必须添加“_app”,所以它应该是selinuxtest_app seinfo=platform name=com。 yourappname .你的应用名称。 whatever type=app_data_file levelFrom=all任何类型=app_data_file levelFrom=all
Example:例子:
user=_app domain=selinuxtest_app seinfo=platform name=com.testapplication.myname type=app_data_file levelFrom=all user=_app domain=selinuxtest_app seinfo=platform name=com.testapplication.myname type=app_data_file levelFrom=all
then create a file in the same folder as platform_app.te, in our case it should be selinuxtest.te, and simply put this into it:然后在与 platform_app.te 相同的文件夹中创建一个文件,在我们的例子中它应该是 selinuxtest.te,然后简单地将其放入其中:
Explanation:解释:
type yourappdomainname & "_app" , domain;输入yourappdomainname & "_app" ,域; app_domain( yourappdomainname & "_app" ) app_domain(你的应用域名和“_app” )
Example:例子:
type selinuxtest_app, domain;键入 selinuxtest_app,域; app_domain(selinuxtest_app) app_domain(selinuxtest_app)
allow selinuxtest_app sysfs:file { getattr open read };允许 selinuxtest_app sysfs:file { getattr open read };
voila!瞧! It works like that, access granted just for your very own app/apps.它就是这样工作的,只为您自己的应用程序授予访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.