Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 1 | typeattribute incidentd coredomain; |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 2 | typeattribute incidentd mlstrustedsubject; |
Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 3 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 4 | init_daemon_domain(incidentd) |
| 5 | type incidentd_exec, exec_type, file_type; |
| 6 | binder_use(incidentd) |
| 7 | wakelock_use(incidentd) |
| 8 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 9 | # Allow incidentd to scan through /proc/pid for all processes |
| 10 | r_dir_file(incidentd, domain) |
| 11 | |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 12 | # Allow incidentd to kill incident_helper when timeout |
| 13 | allow incidentd incident_helper:process sigkill; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 14 | |
| 15 | # Allow executing files on system, such as: |
| 16 | # /system/bin/toolbox |
| 17 | # /system/bin/logcat |
| 18 | # /system/bin/dumpsys |
| 19 | allow incidentd system_file:file execute_no_trans; |
| 20 | allow incidentd toolbox_exec:file rx_file_perms; |
| 21 | |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 22 | # section id 2001, allow reading /proc/pagetypeinfo |
| 23 | allow incidentd proc_pagetypeinfo:file r_file_perms; |
| 24 | |
| 25 | # section id 2002, allow reading /d/wakeup_sources |
| 26 | allow incidentd debugfs_wakeup_sources:file r_file_perms; |
| 27 | |
| 28 | # section id 2003, allow executing top |
| 29 | allow incidentd proc_meminfo:file { open read }; |
| 30 | |
| 31 | # section id 2004, allow reading /sys/devices/system/cpu/cpufreq/all_time_in_state |
| 32 | allow incidentd sysfs_devices_system_cpu:file r_file_perms; |
| 33 | |
Kweku Adams | 06ac7db | 2018-03-06 17:42:35 -0800 | [diff] [blame] | 34 | # section id 2005, allow reading ps dump in full |
| 35 | allow incidentd domain:process getattr; |
| 36 | |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 37 | # section id 2006, allow reading /sys/class/power_supply/bms/battery_type |
| 38 | allow incidentd sysfs_batteryinfo:dir { search }; |
| 39 | allow incidentd sysfs_batteryinfo:file r_file_perms; |
| 40 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 41 | # Create and write into /data/misc/incidents |
| 42 | allow incidentd incident_data_file:dir rw_dir_perms; |
| 43 | allow incidentd incident_data_file:file create_file_perms; |
| 44 | |
| 45 | # Get process attributes |
| 46 | # TODO allow incidentd domain:process getattr; |
| 47 | |
Kweku Adams | 06ac7db | 2018-03-06 17:42:35 -0800 | [diff] [blame] | 48 | # Read files in /proc |
| 49 | allow incidentd { |
| 50 | proc_stat |
| 51 | }:file r_file_perms; |
| 52 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 53 | # Signal java processes to dump their stack and get the results |
| 54 | # TODO allow incidentd { appdomain ephemeral_app system_server }:process signal; |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 55 | # TODO allow incidentd anr_data_file:dir create_dir_perms; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 56 | # TODO allow incidentd anr_data_file:file create_file_perms; |
| 57 | |
| 58 | # Signal native processes to dump their stack. |
| 59 | # This list comes from native_processes_to_dump in incidentd/utils.c |
| 60 | allow incidentd { |
| 61 | audioserver |
| 62 | cameraserver |
| 63 | drmserver |
| 64 | inputflinger |
| 65 | mediacodec |
| 66 | mediadrmserver |
| 67 | mediaextractor |
| 68 | mediaserver |
| 69 | sdcardd |
| 70 | surfaceflinger |
| 71 | }:process signal; |
| 72 | |
| 73 | # Allow incidentd to make binder calls to any binder service |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 74 | binder_call(incidentd, system_server) |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 75 | binder_call(incidentd, appdomain) |
| 76 | |
| 77 | # Reading /proc/PID/maps of other processes |
Benjamin Gordon | 9b2e0cb | 2017-11-09 15:51:26 -0700 | [diff] [blame] | 78 | # TODO allow incidentd self:global_capability_class_set sys_ptrace; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 79 | |
| 80 | # Run a shell. |
| 81 | allow incidentd shell_exec:file rx_file_perms; |
| 82 | |
| 83 | # logd access - work to be done is a PII safe log (possibly an event log?) |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 84 | userdebug_or_eng(`read_logd(incidentd)') |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 85 | # TODO control_logd(incidentd) |
| 86 | |
| 87 | # Allow incidentd to find these standard groups of services. |
| 88 | # Others can be whitelisted individually. |
| 89 | allow incidentd { |
| 90 | system_server_service |
| 91 | app_api_service |
| 92 | system_api_service |
| 93 | }:service_manager find; |
| 94 | |
| 95 | # Only incidentd can publish the binder service |
| 96 | add_service(incidentd, incident_service) |
| 97 | |
| 98 | # Allow pipes from (and only from) incident |
| 99 | allow incidentd incident:fd use; |
| 100 | allow incidentd incident:fifo_file write; |
| 101 | |
| 102 | # Allow incident to call back to incident with status updates. |
| 103 | binder_call(incidentd, incident) |
| 104 | |
| 105 | ### |
| 106 | ### neverallow rules |
| 107 | ### |
| 108 | |
| 109 | # only system_server, system_app and incident command can find the incident service |
yro | cf38ca5 | 2018-01-22 13:56:41 -0800 | [diff] [blame] | 110 | neverallow { |
| 111 | domain |
| 112 | -incident |
| 113 | -incidentd |
| 114 | -statsd |
| 115 | -system_app |
| 116 | -system_server |
| 117 | } incident_service:service_manager find; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 118 | |
| 119 | # only incidentd and the other root services in limited circumstances |
| 120 | # can get to the files in /data/misc/incidents |
| 121 | # |
| 122 | # write, execute, append are forbidden almost everywhere |
| 123 | neverallow { domain -incidentd -init -vold } incident_data_file:file { |
| 124 | w_file_perms |
| 125 | x_file_perms |
| 126 | create |
| 127 | rename |
| 128 | setattr |
| 129 | unlink |
| 130 | append |
| 131 | }; |
| 132 | # read is also allowed by system_server, for when the file is handed to dropbox |
| 133 | neverallow { domain -incidentd -init -vold -system_server } incident_data_file:file r_file_perms; |
| 134 | # limited access to the directory itself |
| 135 | neverallow { domain -incidentd -init -vold } incident_data_file:dir create_dir_perms; |
| 136 | |