Merge "Fix bug map entry"
diff --git a/private/compat/26.0/26.0.cil b/private/compat/26.0/26.0.cil
index e58fa4e..12e5c98 100644
--- a/private/compat/26.0/26.0.cil
+++ b/private/compat/26.0/26.0.cil
@@ -467,6 +467,7 @@
     proc_page_cluster
     proc_pagetypeinfo
     proc_panic
+    proc_pid_max
     proc_pipe_conf
     proc_random
     proc_sched
diff --git a/private/genfs_contexts b/private/genfs_contexts
index 4f3a96c..09da56d 100644
--- a/private/genfs_contexts
+++ b/private/genfs_contexts
@@ -42,6 +42,7 @@
 genfscon proc /sys/kernel/panic_on_oops u:object_r:proc_panic:s0
 genfscon proc /sys/kernel/perf_event_max_sample_rate u:object_r:proc_perf:s0
 genfscon proc /sys/kernel/perf_event_paranoid u:object_r:proc_perf:s0
+genfscon proc /sys/kernel/pid_max u:object_r:proc_pid_max:s0
 genfscon proc /sys/kernel/poweroff_cmd u:object_r:usermodehelper:s0
 genfscon proc /sys/kernel/random u:object_r:proc_random:s0
 genfscon proc /sys/kernel/randomize_va_space u:object_r:proc_security:s0
diff --git a/private/system_server.te b/private/system_server.te
index c10a617..1d1b92b 100644
--- a/private/system_server.te
+++ b/private/system_server.te
@@ -720,6 +720,13 @@
   allow system_server zygote_exec:file rx_file_perms;
 ')
 
+# ART Profiles.
+# Allow system_server to open profile snapshots for read.
+# System server never reads the actual content. It passes the descriptor to
+# to privileged apps which acquire the permissions to inspect the profiles.
+allow system_server user_profile_data_file:dir { search };
+allow system_server user_profile_data_file:file { open read };
+
 ###
 ### Neverallow rules
 ###
diff --git a/public/domain.te b/public/domain.te
index 91cf8ca..0d50c38 100644
--- a/public/domain.te
+++ b/public/domain.te
@@ -238,8 +238,8 @@
 # http://www.openwall.com/lists/oss-security/2016/09/26/14
 neverallowxperm * devpts:chr_file ioctl TIOCSTI;
 
-# Do not allow any domain other than init or recovery to create unlabeled files.
-neverallow { domain -init -recovery } unlabeled:dir_file_class_set create;
+# Do not allow any domain other than init to create unlabeled files.
+neverallow { domain -init } unlabeled:dir_file_class_set create;
 
 # Limit device node creation to these whitelisted domains.
 neverallow {
@@ -269,8 +269,10 @@
 # No domain needs mac_override as it is unused by SELinux.
 neverallow * self:global_capability2_class_set mac_override;
 
-# Only recovery needs mac_admin to set contexts not defined in current policy.
-neverallow { domain -recovery } self:global_capability2_class_set mac_admin;
+# Disallow attempts to set contexts not defined in current policy
+# This helps guarantee that unknown or dangerous contents will not ever
+# be set.
+neverallow * self:global_capability2_class_set mac_admin;
 
 # Once the policy has been loaded there shall be none to modify the policy.
 # It is sealed.
@@ -376,6 +378,7 @@
     -bootanim # for oemfs
     -recovery # for /tmp/update_binary in tmpfs
 } { fs_type -rootfs }:file execute;
+
 # Files from cache should never be executed
 neverallow domain { cache_file cache_backup_file cache_private_backup_file cache_recovery_file }:file execute;
 
@@ -399,10 +402,12 @@
 neverallow { domain -init } properties_device:file { no_w_file_perms no_x_file_perms };
 neverallow { domain -init } properties_serial:file { no_w_file_perms no_x_file_perms };
 
-# Only recovery should be doing writes to /system & /vendor
+# Nobody should be doing writes to /system & /vendor
+# These partitions are intended to be read-only and must never be
+# modified. Doing so would violate important Android security guarantees
+# and invalidate dm-verity signatures.
 neverallow {
     domain
-    -recovery
     with_asan(`-asan_extract')
 } {
     system_file
@@ -410,7 +415,7 @@
     exec_type
 }:dir_file_class_set { create write setattr relabelfrom append unlink link rename };
 
-neverallow { domain -recovery -kernel with_asan(`-asan_extract') } { system_file vendor_file_type exec_type }:dir_file_class_set relabelto;
+neverallow { domain -kernel with_asan(`-asan_extract') } { system_file vendor_file_type exec_type }:dir_file_class_set relabelto;
 
 # Don't allow mounting on top of /system files or directories
 neverallow * exec_type:dir_file_class_set mounton;
@@ -426,7 +431,7 @@
 # Ensure that context mount types are not writable, to ensure that
 # the write to /system restriction above is not bypassed via context=
 # mount to another type.
-neverallow { domain -recovery } contextmount_type:dir_file_class_set
+neverallow * contextmount_type:dir_file_class_set
     { create write setattr relabelfrom relabelto append unlink link rename };
 
 # Do not allow service_manager add for default service labels.
@@ -1091,12 +1096,9 @@
 # vendor, and boot partitions.
 neverallow * ~{ system_file vendor_file rootfs }:system module_load;
 
-# Only allow filesystem caps to be set at build time or
-# during upgrade by recovery.
-neverallow {
-  domain
-  -recovery
-} self:global_capability_class_set setfcap;
+# Only allow filesystem caps to be set at build time. Runtime changes
+# to filesystem capabilities are not permitted.
+neverallow * self:global_capability_class_set setfcap;
 
 # Enforce AT_SECURE for executing crash_dump.
 neverallow domain crash_dump:process noatsecure;
diff --git a/public/file.te b/public/file.te
index 29bf9be..6c11b81 100644
--- a/public/file.te
+++ b/public/file.te
@@ -38,6 +38,7 @@
 type proc_pagetypeinfo, fs_type;
 type proc_panic, fs_type;
 type proc_perf, fs_type;
+type proc_pid_max, fs_type;
 type proc_pipe_conf, fs_type;
 type proc_random, fs_type;
 type proc_sched, fs_type;
diff --git a/public/recovery.te b/public/recovery.te
index 3e3c28e..f6ad47f 100644
--- a/public/recovery.te
+++ b/public/recovery.te
@@ -12,10 +12,7 @@
   # Recovery can only use HALs in passthrough mode
   passthrough_hal_client_domain(recovery, hal_bootctl)
 
-  allow recovery self:global_capability_class_set { chown dac_override fowner fsetid setfcap setuid setgid sys_admin sys_tty_config };
-
-  # Set security contexts on files that are not known to the loaded policy.
-  allow recovery self:global_capability2_class_set mac_admin;
+  allow recovery self:global_capability_class_set { dac_override fowner setuid setgid sys_admin sys_tty_config };
 
   # Run helpers from / or /system without changing domain.
   r_dir_file(recovery, rootfs)
@@ -29,26 +26,9 @@
   allow recovery unlabeled:filesystem ~relabelto;
   allow recovery contextmount_type:filesystem relabelto;
 
-  # Create and relabel files and directories under /system.
-  allow recovery exec_type:{ file lnk_file } { create_file_perms relabelfrom relabelto };
-  allow recovery { system_file }:{ file lnk_file } { create_file_perms relabelfrom relabelto };
-  allow recovery system_file:dir { create_dir_perms relabelfrom relabelto };
-
-  # We may be asked to set an SELinux label for a type not known to the
-  # currently loaded policy. Allow it.
-  allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto };
-  allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto };
   # Get file contexts
   allow recovery file_contexts_file:file r_file_perms;
 
-  # 0eb17d944704b3eb140bb9dded299d3be3aed77e in build/ added SELinux
-  # support to OTAs. However, that code has a bug. When an update occurs,
-  # some directories are inappropriately labeled as exec_type. This is
-  # only transient, and subsequent steps in the OTA script correct this
-  # mistake. New devices are moving to block based OTAs, so this is not
-  # worth fixing. b/15575013
-  allow recovery exec_type:dir { create_dir_perms relabelfrom relabelto };
-
   # Write to /proc/sys/vm/drop_caches
   allow recovery proc_drop_caches:file w_file_perms;
 
diff --git a/public/shell.te b/public/shell.te
index cac84d4..1318c35 100644
--- a/public/shell.te
+++ b/public/shell.te
@@ -115,6 +115,7 @@
   proc_interrupts
   proc_meminfo
   proc_modules
+  proc_pid_max
   proc_stat
   proc_timer
   proc_uptime
diff --git a/tools/sepolicy-analyze/Android.mk b/tools/sepolicy-analyze/Android.mk
index 1754fc7..2af1494 100644
--- a/tools/sepolicy-analyze/Android.mk
+++ b/tools/sepolicy-analyze/Android.mk
@@ -10,6 +10,6 @@
 LOCAL_STATIC_LIBRARIES := libsepol
 LOCAL_CXX_STL := none
 
-LOCAL_COMPATIBILITY_SUITE := cts gts
+LOCAL_COMPATIBILITY_SUITE := ats cts gts
 
 include $(BUILD_HOST_EXECUTABLE)