SELinux policy demo

1.Add new service started by init

情景:定义一个init 启动的service -- demo_service,对应的执行档为/system/bin/demo。

  • 在/device/mediatke/sepolicy 下创建一个demo.te(例如:Android T中的/device/mediatke/sepolicy/base/private/demo.te)
  • 在demo.te中定义demo 类型,init 启动service 时类型转换:
    type  demo, domain, coredomain;
    type  demo_exec, system_file_type, exec_type, file_type;
    init_daemon_domain(demo)
    
  • 在file_contexts中绑定执行档:
    /system/bin/demo  u:object_r:demo_exec:s0
    
  • 根据demo 需要访问的文件以及设备,在demo.te中定义其它的权限。
    注: Android O 版本后, 需要根据service 本身是放在vendor 还是 system 选择不同的存放sepolicy 存放位置。

2.Access system device

情景:一个native service 需要访问一个专属的char device -- /dev/demo ---- demo 设备名

  • 在device.te中定义device类型:
type demo_device, dev_type;
  • 在file_contexts中绑定demo device:
/dev/demo u:object_r:demo_device:s0
  • 在demo.te中授权demo使用demo device的权限:
allow demo demo_device:chr_file rw_file_perms;
posted @ 2022-11-14 15:32  caseyzz  阅读(77)  评论(0)    收藏  举报