1# Life begins with the kernel. 2type kernel, domain, mlstrustedsubject; 3 4allow kernel self:global_capability_class_set sys_nice; 5 6# Root fs. 7r_dir_file(kernel, rootfs) 8 9# Used to read androidboot.selinux property 10allow kernel { 11 proc_bootconfig 12 proc_cmdline 13}:file r_file_perms; 14 15# Get SELinux enforcing status. 16allow kernel selinuxfs:dir r_dir_perms; 17allow kernel selinuxfs:file r_file_perms; 18 19# Get file contexts during first stage 20allow kernel file_contexts_file:file r_file_perms; 21 22# Allow init relabel itself. 23allow kernel rootfs:file relabelfrom; 24allow kernel init_exec:file relabelto; 25# TODO: investigate why we need this. 26allow kernel init:process share; 27 28# cgroup filesystem initialization prior to setting the cgroup root directory label. 29allow kernel unlabeled:dir search; 30 31# Mount usbfs. 32allow kernel usbfs:filesystem mount; 33allow kernel usbfs:dir search; 34 35# Initial setenforce by init prior to switching to init domain. 36# We use dontaudit instead of allow to prevent a kernel spawned userspace 37# process from turning off SELinux once enabled. 38dontaudit kernel self:security setenforce; 39 40# Write to /proc/1/oom_adj prior to switching to init domain. 41allow kernel self:global_capability_class_set sys_resource; 42 43# Init reboot before switching selinux domains under certain error 44# conditions. Allow it. 45# As part of rebooting, init writes "u" to /proc/sysrq-trigger to 46# remount filesystems read-only. /data is not mounted at this point, 47# so we could ignore this. For now, we allow it. 48allow kernel self:global_capability_class_set sys_boot; 49allow kernel proc_sysrq:file w_file_perms; 50 51# Allow writing to /dev/kmsg which was created prior to loading policy. 52allow kernel tmpfs:chr_file write; 53 54# Set checkreqprot by init.rc prior to switching to init domain. 55allow kernel selinuxfs:file write; 56allow kernel self:security setcheckreqprot; 57 58# kernel thread "loop0", used by the loop block device, for ASECs (b/17158723) 59allow kernel sdcard_type:file { read write }; 60 61# f_mtp driver accesses files from kernel context. 62allow kernel mediaprovider:fd use; 63 64# Allow the kernel to read OBB files from app directories. (b/17428116) 65# Kernel thread "loop0" reads a vold supplied file descriptor. 66# Fixes CTS tests: 67# * android.os.storage.cts.StorageManagerTest#testMountAndUnmountObbNormal 68# * android.os.storage.cts.StorageManagerTest#testMountAndUnmountTwoObbs 69allow kernel vold:fd use; 70allow kernel { app_data_file privapp_data_file }:file read; 71allow kernel asec_image_file:file read; 72 73# Allow mounting loop device in update_engine_unittests. (b/28319454) 74# and for LTP kernel tests (b/73220071) 75userdebug_or_eng(` 76 allow kernel update_engine_data_file:file { read write }; 77 allow kernel nativetest_data_file:file { read write }; 78') 79 80# Access to /data/media. 81# This should be removed if sdcardfs is modified to alter the secontext for its 82# accesses to the underlying FS. 83allow kernel media_rw_data_file:dir create_dir_perms; 84allow kernel media_rw_data_file:file create_file_perms; 85 86# Access to /data/misc/vold/virtual_disk. 87allow kernel vold_data_file:file { read write }; 88 89# Allow the kernel to read APEX file descriptors and (staged) data files; 90# Needed because APEX uses the loopback driver, which issues requests from 91# a kernel thread in earlier kernel version. 92allow kernel apexd:fd use; 93allow kernel { 94 apex_data_file 95 staging_data_file 96 vendor_apex_file 97}:file read; 98 99# Allow the first-stage init (which is running in the kernel domain) to execute the 100# dynamic linker when it re-executes /init to switch into the second stage. 101# Until Linux 4.8, the program interpreter (dynamic linker in this case) is executed 102# before the domain is switched to the target domain. So, we need to allow the kernel 103# domain (the source domain) to execute the dynamic linker (system_file type). 104# TODO(b/110147943) remove these allow rules when we no longer need to support Linux 105# kernel older than 4.8. 106allow kernel system_file:file execute; 107# The label for the dynamic linker is rootfs in the recovery partition. This is because 108# the recovery partition which is rootfs does not support xattr and thus labeling can't be 109# done at build-time. All files are by default labeled as rootfs upon booting. 110recovery_only(` 111 allow kernel rootfs:file execute; 112') 113 114# required by VTS lidbm unit test 115allow kernel appdomain_tmpfs:file { read write }; 116 117### 118### neverallow rules 119### 120 121# The initial task starts in the kernel domain (assigned via 122# initial_sid_contexts), but nothing ever transitions to it. 123neverallow * kernel:process { transition dyntransition }; 124 125# The kernel domain is never entered via an exec, nor should it 126# ever execute a program outside the rootfs without changing to another domain. 127# If you encounter an execute_no_trans denial on the kernel domain, then 128# possible causes include: 129# - The program is a kernel usermodehelper. In this case, define a domain 130# for the program and domain_auto_trans() to it. 131# - You are running an exploit which switched to the init task credentials 132# and is then trying to exec a shell or other program. You lose! 133neverallow kernel *:file { entrypoint execute_no_trans }; 134 135# the kernel should not be accessing files owned by other users. 136# Instead of adding dac_{read_search,override}, fix the unix permissions 137# on files being accessed. 138neverallow kernel self:global_capability_class_set { dac_override dac_read_search }; 139 140# Nobody should be ptracing kernel threads 141neverallow * kernel:process ptrace; 142