1# Life begins with the kernel.
2type kernel, domain, domain_deprecated, mlstrustedsubject;
3
4allow kernel self:capability sys_nice;
5
6# Root fs.
7allow kernel rootfs:dir r_dir_perms;
8allow kernel rootfs:file r_file_perms;
9allow kernel rootfs:lnk_file r_file_perms;
10
11# Get SELinux enforcing status.
12allow kernel selinuxfs:dir r_dir_perms;
13allow kernel selinuxfs:file r_file_perms;
14
15# Allow init relabel itself.
16allow kernel rootfs:file relabelfrom;
17allow kernel init_exec:file relabelto;
18# TODO: investigate why we need this.
19allow kernel init:process share;
20
21# cgroup filesystem initialization prior to setting the cgroup root directory label.
22allow kernel unlabeled:dir search;
23
24# Mount usbfs.
25allow kernel usbfs:filesystem mount;
26allow kernel usbfs:dir search;
27
28# Initial setenforce by init prior to switching to init domain.
29# We use dontaudit instead of allow to prevent a kernel spawned userspace
30# process from turning off SELinux once enabled.
31dontaudit kernel self:security setenforce;
32
33# Write to /proc/1/oom_adj prior to switching to init domain.
34allow kernel self:capability sys_resource;
35
36# Init reboot before switching selinux domains under certain error
37# conditions. Allow it.
38# As part of rebooting, init writes "u" to /proc/sysrq-trigger to
39# remount filesystems read-only. /data is not mounted at this point,
40# so we could ignore this. For now, we allow it.
41allow kernel self:capability sys_boot;
42allow kernel proc_sysrq:file w_file_perms;
43
44# Allow writing to /dev/__kmsg__ which was created prior to
45# loading policy
46allow kernel tmpfs:chr_file write;
47
48# Set checkreqprot by init.rc prior to switching to init domain.
49allow kernel selinuxfs:file write;
50allow kernel self:security setcheckreqprot;
51
52# MTP sync (b/15835289)
53# kernel thread "loop0", used by the loop block device, for ASECs (b/17158723)
54allow kernel priv_app:fd use;
55allow kernel sdcard_type:file { read write };
56
57# Allow the kernel to read OBB files from app directories. (b/17428116)
58# Kernel thread "loop0" reads a vold supplied file descriptor.
59# Fixes CTS tests:
60#  * android.os.storage.cts.StorageManagerTest#testMountAndUnmountObbNormal
61#  * android.os.storage.cts.StorageManagerTest#testMountAndUnmountTwoObbs
62allow kernel vold:fd use;
63allow kernel app_data_file:file read;
64allow kernel asec_image_file:file read;
65
66domain_auto_trans(kernel, init_exec, init)
67
68# Access to /data/media.
69# This should be removed if sdcardfs is modified to alter the secontext for its
70# accesses to the underlying FS.
71allow kernel media_rw_data_file:dir create_dir_perms;
72allow kernel media_rw_data_file:file create_file_perms;
73
74###
75### neverallow rules
76###
77
78# The initial task starts in the kernel domain (assigned via
79# initial_sid_contexts), but nothing ever transitions to it.
80neverallow * kernel:process { transition dyntransition };
81
82# The kernel domain is never entered via an exec, nor should it
83# ever execute a program outside the rootfs without changing to another domain.
84# If you encounter an execute_no_trans denial on the kernel domain, then
85# possible causes include:
86# - The program is a kernel usermodehelper.  In this case, define a domain
87#   for the program and domain_auto_trans() to it.
88# - You failed to setcon u:r:init:s0 in your init.rc and thus your init
89#   program was left in the kernel domain and is now trying to execute
90#   some other program.  Fix your init.rc file.
91# - You are running an exploit which switched to the init task credentials
92#   and is then trying to exec a shell or other program.  You lose!
93neverallow kernel { file_type fs_type -rootfs }:file { entrypoint execute_no_trans };
94