2012-01-04 09:33:27 -08:00
|
|
|
# Life begins with the kernel.
|
2016-09-11 21:18:05 -07:00
|
|
|
type kernel, domain, mlstrustedsubject;
|
2014-10-24 12:56:15 -07:00
|
|
|
|
2017-11-09 14:51:26 -08:00
|
|
|
allow kernel self:global_capability_class_set sys_nice;
|
2014-01-24 20:43:07 -08:00
|
|
|
|
2016-01-27 19:15:41 -08:00
|
|
|
# Root fs.
|
2016-09-09 16:27:17 -07:00
|
|
|
r_dir_file(kernel, rootfs)
|
2017-09-26 12:58:29 -07:00
|
|
|
allow kernel proc_cmdline:file r_file_perms;
|
2016-01-27 19:15:41 -08:00
|
|
|
|
|
|
|
# Get SELinux enforcing status.
|
|
|
|
allow kernel selinuxfs:dir r_dir_perms;
|
|
|
|
allow kernel selinuxfs:file r_file_perms;
|
|
|
|
|
2017-03-24 15:02:13 -07:00
|
|
|
# Get file contexts during first stage
|
|
|
|
allow kernel file_contexts_file:file r_file_perms;
|
|
|
|
|
2015-04-24 11:38:10 -07:00
|
|
|
# Allow init relabel itself.
|
|
|
|
allow kernel rootfs:file relabelfrom;
|
|
|
|
allow kernel init_exec:file relabelto;
|
|
|
|
# TODO: investigate why we need this.
|
|
|
|
allow kernel init:process share;
|
2014-01-24 20:43:07 -08:00
|
|
|
|
2014-05-30 06:53:00 -07:00
|
|
|
# cgroup filesystem initialization prior to setting the cgroup root directory label.
|
|
|
|
allow kernel unlabeled:dir search;
|
|
|
|
|
2014-06-18 07:31:27 -07:00
|
|
|
# Mount usbfs.
|
|
|
|
allow kernel usbfs:filesystem mount;
|
2015-03-28 02:48:46 -07:00
|
|
|
allow kernel usbfs:dir search;
|
2014-06-18 07:31:27 -07:00
|
|
|
|
2013-12-06 05:05:53 -08:00
|
|
|
# Initial setenforce by init prior to switching to init domain.
|
2014-05-12 14:32:59 -07:00
|
|
|
# We use dontaudit instead of allow to prevent a kernel spawned userspace
|
|
|
|
# process from turning off SELinux once enabled.
|
|
|
|
dontaudit kernel self:security setenforce;
|
2014-01-08 06:29:30 -08:00
|
|
|
|
2014-10-24 12:56:15 -07:00
|
|
|
# Write to /proc/1/oom_adj prior to switching to init domain.
|
2017-11-09 14:51:26 -08:00
|
|
|
allow kernel self:global_capability_class_set sys_resource;
|
2014-10-24 12:56:15 -07:00
|
|
|
|
2015-05-05 17:40:07 -07:00
|
|
|
# Init reboot before switching selinux domains under certain error
|
|
|
|
# conditions. Allow it.
|
|
|
|
# As part of rebooting, init writes "u" to /proc/sysrq-trigger to
|
|
|
|
# remount filesystems read-only. /data is not mounted at this point,
|
|
|
|
# so we could ignore this. For now, we allow it.
|
2017-11-09 14:51:26 -08:00
|
|
|
allow kernel self:global_capability_class_set sys_boot;
|
2015-05-05 17:40:07 -07:00
|
|
|
allow kernel proc_sysrq:file w_file_perms;
|
|
|
|
|
2016-07-26 09:46:20 -07:00
|
|
|
# Allow writing to /dev/kmsg which was created prior to loading policy.
|
2015-05-05 17:40:07 -07:00
|
|
|
allow kernel tmpfs:chr_file write;
|
|
|
|
|
2014-01-08 06:29:30 -08:00
|
|
|
# Set checkreqprot by init.rc prior to switching to init domain.
|
2014-10-24 12:56:15 -07:00
|
|
|
allow kernel selinuxfs:file write;
|
2014-01-08 06:29:30 -08:00
|
|
|
allow kernel self:security setcheckreqprot;
|
2014-06-18 07:09:35 -07:00
|
|
|
|
2014-08-27 12:13:28 -07:00
|
|
|
# kernel thread "loop0", used by the loop block device, for ASECs (b/17158723)
|
|
|
|
allow kernel sdcard_type:file { read write };
|
2014-06-24 10:18:02 -07:00
|
|
|
|
2017-04-26 10:18:30 -07:00
|
|
|
# f_mtp driver accesses files from kernel context.
|
|
|
|
allow kernel mediaprovider:fd use;
|
|
|
|
|
2014-09-09 14:12:18 -07:00
|
|
|
# Allow the kernel to read OBB files from app directories. (b/17428116)
|
|
|
|
# Kernel thread "loop0" reads a vold supplied file descriptor.
|
|
|
|
# Fixes CTS tests:
|
|
|
|
# * android.os.storage.cts.StorageManagerTest#testMountAndUnmountObbNormal
|
|
|
|
# * android.os.storage.cts.StorageManagerTest#testMountAndUnmountTwoObbs
|
2015-02-26 20:33:40 -08:00
|
|
|
allow kernel vold:fd use;
|
2018-08-02 15:54:23 -07:00
|
|
|
allow kernel { app_data_file privapp_data_file }:file read;
|
2015-03-26 12:40:07 -07:00
|
|
|
allow kernel asec_image_file:file read;
|
2014-09-09 14:12:18 -07:00
|
|
|
|
2016-05-03 11:07:11 -07:00
|
|
|
# Allow reading loop device in update_engine_unittests. (b/28319454)
|
2018-02-20 12:41:30 -08:00
|
|
|
# and for LTP kernel tests (b/73220071)
|
2016-05-03 11:07:11 -07:00
|
|
|
userdebug_or_eng(`
|
|
|
|
allow kernel update_engine_data_file:file read;
|
2018-05-09 06:12:50 -07:00
|
|
|
allow kernel nativetest_data_file:file { read write };
|
2016-05-03 11:07:11 -07:00
|
|
|
')
|
|
|
|
|
2016-03-31 13:53:42 -07:00
|
|
|
# Access to /data/media.
|
|
|
|
# This should be removed if sdcardfs is modified to alter the secontext for its
|
|
|
|
# accesses to the underlying FS.
|
|
|
|
allow kernel media_rw_data_file:dir create_dir_perms;
|
|
|
|
allow kernel media_rw_data_file:file create_file_perms;
|
|
|
|
|
2017-03-26 13:50:59 -07:00
|
|
|
# Access to /data/misc/vold/virtual_disk.
|
2018-10-09 19:47:38 -07:00
|
|
|
allow kernel vold_data_file:file { read write };
|
2017-03-26 13:50:59 -07:00
|
|
|
|
2019-01-16 04:52:50 -08:00
|
|
|
# Allow the kernel to read APEX file descriptors and (staged) data files;
|
2018-11-08 01:37:36 -08:00
|
|
|
# Needed because APEX uses the loopback driver, which issues requests from
|
|
|
|
# a kernel thread in earlier kernel version.
|
|
|
|
allow kernel apexd:fd use;
|
2019-04-23 18:45:40 -07:00
|
|
|
allow kernel {
|
|
|
|
apex_data_file
|
|
|
|
staging_data_file
|
|
|
|
vendor_apex_file
|
|
|
|
}:file read;
|
2018-11-08 01:37:36 -08:00
|
|
|
|
2018-09-13 11:07:14 -07:00
|
|
|
# Allow the first-stage init (which is running in the kernel domain) to execute the
|
|
|
|
# dynamic linker when it re-executes /init to switch into the second stage.
|
|
|
|
# Until Linux 4.8, the program interpreter (dynamic linker in this case) is executed
|
|
|
|
# before the domain is switched to the target domain. So, we need to allow the kernel
|
|
|
|
# domain (the source domain) to execute the dynamic linker (system_file type).
|
|
|
|
# TODO(b/110147943) remove these allow rules when we no longer need to support Linux
|
|
|
|
# kernel older than 4.8.
|
|
|
|
allow kernel system_file:file execute;
|
|
|
|
# The label for the dynamic linker is rootfs in the recovery partition. This is because
|
|
|
|
# the recovery partition which is rootfs does not support xattr and thus labeling can't be
|
|
|
|
# done at build-time. All files are by default labeled as rootfs upon booting.
|
|
|
|
recovery_only(`
|
|
|
|
allow kernel rootfs:file execute;
|
|
|
|
')
|
|
|
|
|
2019-06-17 10:06:56 -07:00
|
|
|
# required by VTS lidbm unit test
|
2019-11-01 11:38:06 -07:00
|
|
|
allow kernel appdomain_tmpfs:file { read write };
|
2019-06-17 10:06:56 -07:00
|
|
|
|
2014-06-18 07:09:35 -07:00
|
|
|
###
|
|
|
|
### neverallow rules
|
|
|
|
###
|
|
|
|
|
|
|
|
# The initial task starts in the kernel domain (assigned via
|
|
|
|
# initial_sid_contexts), but nothing ever transitions to it.
|
2016-02-05 14:48:03 -08:00
|
|
|
neverallow * kernel:process { transition dyntransition };
|
2014-06-19 06:07:17 -07:00
|
|
|
|
|
|
|
# The kernel domain is never entered via an exec, nor should it
|
|
|
|
# ever execute a program outside the rootfs without changing to another domain.
|
|
|
|
# If you encounter an execute_no_trans denial on the kernel domain, then
|
|
|
|
# possible causes include:
|
|
|
|
# - The program is a kernel usermodehelper. In this case, define a domain
|
|
|
|
# for the program and domain_auto_trans() to it.
|
|
|
|
# - You are running an exploit which switched to the init task credentials
|
|
|
|
# and is then trying to exec a shell or other program. You lose!
|
2016-10-30 18:42:17 -07:00
|
|
|
neverallow kernel *:file { entrypoint execute_no_trans };
|
2017-02-22 14:30:47 -08:00
|
|
|
|
|
|
|
# the kernel should not be accessing files owned by other users.
|
|
|
|
# Instead of adding dac_{read_search,override}, fix the unix permissions
|
|
|
|
# on files being accessed.
|
2017-11-09 14:51:26 -08:00
|
|
|
neverallow kernel self:global_capability_class_set { dac_override dac_read_search };
|
2018-06-01 03:28:59 -07:00
|
|
|
|
2018-09-13 11:07:14 -07:00
|
|
|
# Nobody should be ptracing kernel threads
|
|
|
|
neverallow * kernel:process ptrace;
|