Allow coredomain access to only approved categories of vendor heaps

One of the advantages of the DMA-BUF heaps framework over
ION is that each heap is a separate char device and hence
it is possible to create separate sepolicy permissions to restrict
access to each heap.
In the case of ION, allocation in every heap had to be done through
/dev/ion which meant that there was no away to restrict allocations in
a specific heap.

This patch intends to restrict coredomain access to only approved
categories of vendor heaps. Currently, the only identified category
as per partner feedback is the system-secure heap which is defined
as a heap that allocates from protected memory.

Test: Build, video playback works on CF with ION disabled and
without sepolicy denials
Bug: 175697666

Change-Id: I923d2931c631d05d569e97f6e49145ef71324f3b
diff --git a/private/compat/30.0/30.0.ignore.cil b/private/compat/30.0/30.0.ignore.cil
index d1d5f0f..4cc8e7d 100644
--- a/private/compat/30.0/30.0.ignore.cil
+++ b/private/compat/30.0/30.0.ignore.cil
@@ -16,7 +16,9 @@
     device_config_profcollect_native_boot_prop
     device_state_service
     dm_user_device
+    dmabuf_heap_device
     dmabuf_system_heap_device
+    dmabuf_system_secure_heap_device
     framework_watchdog_config_prop
     gki_apex_prepostinstall
     gki_apex_prepostinstall_exec
diff --git a/private/coredomain.te b/private/coredomain.te
index fe3e1ae..bac494f 100644
--- a/private/coredomain.te
+++ b/private/coredomain.te
@@ -211,6 +211,17 @@
     coredomain
     -init
   }{ usbfs binfmt_miscfs }:file no_rw_file_perms;
+
+  # dmabuf heaps
+  neverallow {
+    coredomain
+    -init
+    -ueventd
+  }{
+    dmabuf_heap_device_type
+    -dmabuf_system_heap_device
+    -dmabuf_system_secure_heap_device
+  }:chr_file no_rw_file_perms;
 ')
 
 # Following /dev nodes must not be directly accessed by coredomain, but should
diff --git a/private/file_contexts b/private/file_contexts
index 79b16b1..8c9d331 100644
--- a/private/file_contexts
+++ b/private/file_contexts
@@ -93,8 +93,10 @@
 /dev/bus/usb(.*)?       u:object_r:usb_device:s0
 /dev/console		u:object_r:console_device:s0
 /dev/cpu_variant:.*     u:object_r:dev_cpu_variant:s0
+/dev/dma_heap(/.*)?     u:object_r:dmabuf_heap_device:s0
 /dev/dma_heap/system    u:object_r:dmabuf_system_heap_device:s0
 /dev/dma_heap/system-uncached    u:object_r:dmabuf_system_heap_device:s0
+/dev/dma_heap/system-secure	 u:object_r:dmabuf_system_secure_heap_device:s0
 /dev/dm-user(/.*)?	u:object_r:dm_user_device:s0
 /dev/device-mapper	u:object_r:dm_device:s0
 /dev/eac		u:object_r:audio_device:s0