Skip to content
Snippets Groups Projects
  • Jeff Vander Stoep's avatar
    Create attribute for moving perms out of domain · d22987b4
    Jeff Vander Stoep authored
    Motivation: Domain is overly permissive. Start removing permissions
    from domain and assign them to the domain_deprecated attribute.
    Domain_deprecated and domain can initially be assigned to all
    domains. The goal is to not assign domain_deprecated to new domains
    and to start removing domain_deprecated where it is not required or
    reassigning the appropriate permissions to the inheriting domain
    when necessary.
    
    Bug: 25433265
    Change-Id: I8b11cb137df7bdd382629c98d916a73fe276413c
    d22987b4
kernel.te 3.20 KiB
# Life begins with the kernel.
type kernel, domain, domain_deprecated, mlstrustedsubject;

allow kernel self:capability sys_nice;

# 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;

# cgroup filesystem initialization prior to setting the cgroup root directory label.
allow kernel unlabeled:dir search;

# Mount usbfs.
allow kernel usbfs:filesystem mount;
allow kernel usbfs:dir search;

# Initial setenforce by init prior to switching to init domain.
# We use dontaudit instead of allow to prevent a kernel spawned userspace
# process from turning off SELinux once enabled.
dontaudit kernel self:security setenforce;

# Write to /proc/1/oom_adj prior to switching to init domain.
allow kernel self:capability sys_resource;

# 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.
allow kernel self:capability sys_boot;
allow kernel proc_sysrq:file w_file_perms;

# Allow writing to /dev/__kmsg__ which was created prior to
# loading policy
allow kernel tmpfs:chr_file write;

# Set checkreqprot by init.rc prior to switching to init domain.
allow kernel selinuxfs:file write;
allow kernel self:security setcheckreqprot;

# MTP sync (b/15835289)
# kernel thread "loop0", used by the loop block device, for ASECs (b/17158723)
allow kernel { priv_app untrusted_app }:fd use;
# privileged apps have moved to the priv_app domain. Determine
# if this permission is still needed. b/25331459
auditallow kernel untrusted_app:fd use;
allow kernel sdcard_type:file { read write };

# 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
allow kernel vold:fd use;
allow kernel app_data_file:file read;
allow kernel asec_image_file:file read;

domain_auto_trans(kernel, init_exec, init)

###
### neverallow rules
###

# The initial task starts in the kernel domain (assigned via
# initial_sid_contexts), but nothing ever transitions to it.
neverallow domain kernel:process { transition dyntransition };

# 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 failed to setcon u:r:init:s0 in your init.rc and thus your init
#   program was left in the kernel domain and is now trying to execute
#   some other program.  Fix your init.rc file.
# - 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!
neverallow kernel { file_type fs_type -rootfs }:file { entrypoint execute_no_trans };