file contexts and .te files

selinux-implementation
good-question-SO
visual_guide_to_sepolicy


Policy files

Files that end with *.te are SELinux policy source files, which define domains and their labels. You may need to create new policy files in /device/manufacturer/device-name/sepolicy, but you should try to update existing files where possible.

 Context files

Context files are where you specify labels for your objects.
  • file_contexts assigns labels to files and is used by various userspace components. As you create new policies, create or update this file to assign new labels to files. To apply new file_contexts, rebuild the filesystem image or run restorecon on the file to be relabeled. On upgrades, changes to file_contexts are automatically applied to the system and userdata partitions as part of the upgrade. Changes can also be automatically applied on upgrade to other partitions by adding restorecon_recursive calls to your init.board.rc file after the partition has been mounted read-write.
  • seapp_contexts assigns labels to app processes and /data/data directories. This configuration is read by the zygote process on each app launch and by installd during startup.
  • mac_permissions.xml assigns a seinfo tag to apps based on their signature and optionally their package name. The seinfo tag can then be used as a key in the seapp_contexts file to assign a specific label to all apps with that seinfo tag. This configuration is read by system_server during startup.

formate to understand sepolicy:

1.

file_contexts
            /dev/foo     u:object_r:source_type:s0


policy.te
           allow ​ source_type ​ ​ target_type: target_class ​ ​ permission(s)

So this means
"allow source_type to do permitted actions on target_class of target_type "

2.

file_context
          /dev/catfile      u:object_r:cat_chow:s0

cat.te
          type cat, domain
          allow cat cat_chow:food eat

"allow cat to eat food of type cat_chow "

3.

file_contexts
          /dev/mma8x5x   u:object_r:sensors_device:s0

sensors.te
          type sensors, domain
          allow sensors sensors_device:chr_file  rw_file_perms

"allow sensors to do rw on chr_file of type sensors_device"



Comments

Popular posts from this blog

dev_get_platdata understanding

Getting started with pinctrl subsystem linux

How to take systrace in android