SELinux
SELinux, or Security-Enhanced Linux, is a mandatory access control (MAC) security mechanism integrated into the Linux kernel and, consequently, the Android operating system.
It is a set of rules that are enforced by the kernel.
It restricts the actions that processes and users can perform on the system.
SELinux depends on lables to enforce access control.
SELinux operates on the priciple of Default Denial. That is, everything is denied unless explicitly allowed.
Syntax
Example 1:
Meaning:
Example 2:
Meaning:
Example
Imagine we have an Android application that attempts to control the device’s flashlight by writing to the file /sys/class/leds/flashlight/brightness.
However, SELinux steps in and prevents this action, resulting in an AVC denial.
neverallow
Example:
Meaning:
Build fails if violated.
SELinux Policy Files
Policies live in:
Operation Modes
SELinux can operate on two global modes:
Permissive Mode: Violations are logged but not blocked.
Enforcing Mode: Violations are logged and are blocked.
Types of Access Control Models
MAC (Mandatory Access Control): The system determines which subjects (android processes) can access which objects (files, sockets, ports, etc.).
DAC (Discretionary Access Control): The owner of an object specifies which subjects can access the object.