我正在编写 Android Native 程序并设置它们的 SEPolicy
我想知道如何为非init程序设置进程上下文,看来域转换不起作用
我写了 2 个程序并将构建的可执行文件放在/vendor/bin
一个程序my_service作为初始化守护程序服务运行;
而另一个my_client是一个非初始化程序,必须手动执行
这 2 个程序使用 Binder IPC 进行通信。
但是我在尝试为my_client设置进程上下文时遇到了麻烦,这是一个非初始化程序
对于 my_service,它的 selinux 上下文主要设置在 2 个文件中
- 我的服务.te
- 文件上下文
# In file_context
/vendor/bin/my_service u:object_r:my_service_exec:s0
# In my_service.te
type my_service, domain;
type my_service_exec, exec_type, file_type, vendor_file_type;
init_daemon_domain(my_service)
而且我还在init.rc文件中使用了 seclabel
# In init.rc
service my_service /vendor/bin/my_service
class main
console
seclabel u:r:my_service:s0
我检查了my_service的文件上下文和进程上下文,它们被设置为我所期望的
对于 my_client 的SEPolicy,一切都与my_service类似,只是它没有写在init.rc文件中,因为它不是一个 init 程序
# In file_context
/vendor/bin/my_client u:object_r:my_client_exec:s0
# In my_client.te
type my_client, domain;
type my_client_exec, exec_type, file_type, vendor_file_type;
init_daemon_domain(my_client)
但是,对于my_client,只有文件上下文设置为my_client_exec
我尝试运行 my_client 并查看了进程上下文:
> # Executing my_client manually
> /vendor/bin/my_client
> ps -AZ | grep my_client
> u:r:su:s0 root 5838 5514 5948 1688 0 0 R my_client
进程上下文是su,而我希望它是my_client
此外,我在te_macros中获得了有关init_daemon_domain(XX)的信息
我认为它会进行域转换:当 init 运行带有 XX_exec 上下文的文件时,它会将其进程上下文转换为 XX!
所以我将规则更改为:
# init_daemon_domain(my_client)
domain_auto_trans(su, my_client_exec, my_client);
但这违反了一些预定义的策略。
顺便说一句,这两个程序之间的活页夹 IPC 似乎工作。
令人困惑的是,即使进程上下文不是my_client ,以下规则仍然有效?
binder_call(my_client, my_service)
binder_call(my_service, my_service)
有没有办法为非初始化程序进行域转换?
或者我对 SEPolicy 有什么误解?因为我找到的所有资源都是关于为 init 程序设置 SEPolicy