• Android SELinux


    Google参考链接:https://source.android.com/docs/core/architecture/aidl/aidl-hals#sepolicy

    A. 通信框架SE文件修改 public /attributes  vendor/hal_foo.te

    B. server端SE文件修改 vendor/service.te  vendor/service_contexts(实例安全属性申明)

    vendor/hal_foo_default.te(新建,配置server端进程的权限) vendor/file_contexts

    C.client端SE文件修改

    private/system_server.te

    system侧进程安全策略配置放在private目录下

    vendor侧进程安全策略配置放在vendor目录下

    hal_attribute(xxx)

    宏,定义hal服务相关的hal属性:hal_xxx, hal_xxx_client 和 hal_xxx_server 两种属性

    当新的Hal(服务)类型创建时,需要添加对应的HAL attributes

    属性定义方式

     放public目录下

     attribute hal_foo;
      attribute hal_foo_client;
      attribute hal_foo_server;

    或者通过宏定义:

    hal_attribute(foo)

    域domain具有访问某类资源的集合,比如访问foo service,需要具备hal_foo_client属性。所有具有hal_foo_client权限的client端进程都同属一个域?

    hal_foo_client

    type示例,hal服务客户端属性.

    hal_foo_server 

    示例,hal服务服务端属性。

    hal_client_domain 

    宏,将domain域和(hal_xxx_client )属性关联,system_server作为Hal服务客户端示例:hal_client_domain(system_server, hal_foo)

    hal_server_domain

    宏,将domain域和(hal_xxx_server )属性关联,A HAL server关联域示例:hal_server_domain(my_hal_domain, hal_foo)

    hal_foo

    以上宏中,hal_foo实际不是sepolicy 对象,而是一个符号,通过它引用到hal_foo_client 和 hal_foo_server等属性.

    hal_foo_serverhal层服务端,通过他来发现和注册对应的新的hal服务?

    hal_foo_service

    hal服务对应的新建类型,需要通过以下宏和相关属性关联:

    hal_attribute_service(hal_foo, hal_foo_service)。关联后,具有hal_foo_server属性的进程能注册到hal作为服务。具有hal_foo_client属性的进程能从hal层获取到服务

    rulesThe enforcement of these registration rules is done by the context manager (servicemanager) 这些注册规则是通过servicemanager强制保证的

    所以,为一个服务添加完整的SELinux权限的过程是这样的:

    1.     public/attributes:
    2.     //1.属性定义 define hal_foo, hal_foo_client, hal_foo_server
    3.     hal_attribute(foo)
    4.     public/service.te
    5.     //2.hal服务类型定义,逗号后表示继承 define hal_foo_service
    6.     type hal_foo_service, hal_service_type, protected_service, service_manager_type
    7.     public/hal_foo.te:
    8.     //3.sepolicy定义 allow binder connection from client to server
    9.     binder_call(hal_foo_client, hal_foo_server)
    10. binder_call(hal_foo_server, hal_foo_client) //服务回调到客户端要配
    11.     //4.hal类型和服务关联
    12. // allow client to find the service, allow server to register the service
    13.     hal_attribute_service(hal_foo, hal_foo_service)
    14.     //5.允许hal服务通过binder连接service_manager
    15. // allow binder communication from server to service_manager
    16.     binder_use(hal_foo_server)
    17. //or以下?
    18. binder_call(hal_foo_server, servicemanager)
    19. binder_call(hal_foo_client, servicemanager)
    20.     private/service_contexts:
    21.     //6.将服务实例名和服务类型绑定 bind an AIDL service name to the selinux type
    22.     android.hardware.foo.IFooXxxx/default u:object_r:hal_foo_service:s0
    23.     private/<some_domain>.te:
    24.     // let this domain use the hal service
    25.     binder_use(some_domain)
    26.     hal_client_domain(some_domain, hal_foo)
    27.     vendor/<some_hal_server_domain>.te
    28.     // let this domain serve the hal service
    29.     hal_server_domain(some_hal_server_domain, hal_foo)

    hal_attribute_service宏包括以下操作:

    allow hal_foo_server hal_foo_service:service_manager {add find}

    allow hal_foo_client hal_foo_service:service_manager {find}

  • 相关阅读:
    vue2/3 tab栏切换 可左右滑动的处理
    mysql [ERROR] mysql unknown option ‘-a‘
    Shell 运算符及语法结构
    LVS负载均衡群集+NAT部署
    springboot项目部署 + vue项目部署
    DP5340国产替代CM5340立体声音频A/D转换器芯片
    X-NAND新架构助力QLC性能飙升
    【学习笔记】 字符串基础 : 后缀自动机(基础篇)
    记录 UniApp开发中遇到的坑
    什么是神经网络?
  • 原文地址:https://blog.csdn.net/shuizhizhiyin/article/details/132807263