Skip to content
Snippets Groups Projects
  • Nick Kralevich's avatar
    Revisit kernel setenforce · abae8a9b
    Nick Kralevich authored
    Kernel userspace helpers may be spawned running in the kernel
    SELinux domain. Those userspace helpers shouldn't be able to turn
    SELinux off.
    
    This change revisits the discussion in
    https://android-review.googlesource.com/#/c/71184/
    
    At the time, we were debating whether or not to have an allow rule,
    or a dontaudit rule. Both have the same effect, as at the time we
    switch to enforcing mode, the kernel is in permissive and the operation
    will be allowed.
    
    Change-Id: If335a5cf619125806c700780fcf91f8602083824
    abae8a9b
kernel.te 978 B
# Life begins with the kernel.
type kernel, domain;

allow kernel init:process dyntransition;

# The kernel is unconfined.
unconfined_domain(kernel)

allow kernel {fs_type dev_type file_type}:dir_file_class_set relabelto;
allow kernel unlabeled:filesystem mount;
allow kernel fs_type:filesystem *;

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

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

# For operations performed by kernel or init prior to switching to init domain.
## TODO: Investigate whether it is safe to remove these
allow kernel self:capability { sys_rawio mknod };
auditallow kernel self:capability { sys_rawio mknod };
allow kernel dev_type:blk_file rw_file_perms;
auditallow kernel dev_type:blk_file rw_file_perms;