From c7e6074c0d4b9a404832cf4d13562c1c5821b822 Mon Sep 17 00:00:00 2001
From: Jeff Vander Stoep <jeffv@google.com>
Date: Sun, 2 Oct 2016 20:20:52 -0700
Subject: [PATCH] Create unique labels for /dev/snd/{seq,timer}

No core android component needs access to /dev/snd/{seq,timer}, but
currently audioserver, bootanim, init, system_server and ueventd have
access. Seq and timer have been the source of many bugs in the past
[1]. Giving these files new labels without explicitly granting access
removes access from audioserver, bootanim, and system_server.
Init and ueventd still require access for /dev setup.

TODO: Explore unsetting CONFIG_SND_TIMER device kernels.

[1] https://github.com/google/syzkaller/wiki/Found-Bugs

Test: media CTS "cts-tradefed run cts -m CtsMediaTestCases" on Bullhead
and Dragon completed with no denials.

Bug: 29045223
(cherry picked from commit db4510d87a70784ce469f05180956cd057424ae2)
Change-Id: I2d069920e792ce8eef70c7b4a038b9e7000f39f5
---
 device.te     | 2 ++
 file_contexts | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/device.te b/device.te
index 7e0073f7b..b4ca6188d 100644
--- a/device.te
+++ b/device.te
@@ -4,6 +4,8 @@ type alarm_device, dev_type, mlstrustedobject;
 type adb_device, dev_type;
 type ashmem_device, dev_type, mlstrustedobject;
 type audio_device, dev_type;
+type audio_timer_device, dev_type;
+type audio_seq_device, dev_type;
 type binder_device, dev_type, mlstrustedobject;
 type hwbinder_device, dev_type, mlstrustedobject;
 type block_device, dev_type;
diff --git a/file_contexts b/file_contexts
index 41ab94938..768af8d64 100644
--- a/file_contexts
+++ b/file_contexts
@@ -95,6 +95,8 @@
 /dev/rproc_user	u:object_r:rpmsg_device:s0
 /dev/rtc[0-9]      u:object_r:rtc_device:s0
 /dev/snd(/.*)?		u:object_r:audio_device:s0
+/dev/snd/audio_timer_device	u:object_r:audio_timer_device:s0
+/dev/snd/audio_seq_device	u:object_r:audio_seq_device:s0
 /dev/socket(/.*)?	u:object_r:socket_device:s0
 /dev/socket/adbd	u:object_r:adbd_socket:s0
 /dev/socket/sap_uim_socket[0-9]        u:object_r:sap_uim_socket:s0
-- 
GitLab