如何将selinux scontext分配给Android应用程序

问题描述 投票:0回答:1

我的问题与此类似: android selinux 上下文下的进程是如何被标记的?

除了我试图将它分配给 Android 应用程序。目前,我的应用程序被标记为

platform_app
,由于某些
neverallow
规则,该应用程序被其他一些 tcontext 阻止。我相信它是这样分配的,因为我给了它一个
certificate: "platform",
,完整的构建文件:

android_app {
    name: "MyApp",
    srcs: [
        "src/**/*.java",
    ],
    resource_dirs: [
        "res/",
    ],
    manifest: "AndroidManifest.xml",
    platform_apis: true,
    installable: true,
    certificate: "platform",
    privileged: true,
}

这是一个示例日志:

04-22 14:07:33.660  2209  2209 I pool-2-thread-1: type=1400 audit(0.0:2203): avc:  denied  { open } for  path="/path/im/trying/to/read" dev="tmpfs" ino=59937 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:the_target_context:s0 tclass=file permissive=1 app=com.example.product.MyApp

假设我想创建一个新的上下文(我相信我知道该怎么做),如何将该上下文分配给我的应用程序? 我当前遇到的问题是不知道如何指向运行的二进制文件,因为该应用程序是 .apk:

/where/to/point/to/my/app   u:object_r:my_new_context:s0
android selinux
1个回答
0
投票

我明白了!

sepolicy/
中创建一个新的
sepolicy/seapp_contexts

# Add new domain for MyApp
user=_app seinfo=platform name=com.example.product.MyApp
 domain=my_app_service

现在您可以注册并授予

my_app
上下文
sepolicy/my_app.te
中的权限:

type my_app_service, domain;
app_domain(display_monitor_service)

allow my_app_service the_target_context:file open;
© www.soinside.com 2019 - 2024. All rights reserved.