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 | |
Yi Jin | 76238cd | 2018-03-30 10:14:08 -0700 | [diff] [blame] | 41 | # section id 2007, allow reading LAST_KMSG /sys/fs/pstore/console-ramoops |
| 42 | userdebug_or_eng(`allow incidentd pstorefs:dir search'); |
| 43 | userdebug_or_eng(`allow incidentd pstorefs:file r_file_perms'); |
| 44 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 45 | # Create and write into /data/misc/incidents |
| 46 | allow incidentd incident_data_file:dir rw_dir_perms; |
| 47 | allow incidentd incident_data_file:file create_file_perms; |
| 48 | |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 49 | # Enable incidentd to get stack traces. |
| 50 | binder_use(incidentd) |
| 51 | hwbinder_use(incidentd) |
| 52 | allow incidentd hwservicemanager:hwservice_manager { list }; |
| 53 | get_prop(incidentd, hwservicemanager_prop) |
| 54 | allow incidentd hidl_manager_hwservice:hwservice_manager { find }; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 55 | |
Kweku Adams | 06ac7db | 2018-03-06 17:42:35 -0800 | [diff] [blame] | 56 | # Read files in /proc |
| 57 | allow incidentd { |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 58 | proc_cmdline |
| 59 | proc_pipe_conf |
Kweku Adams | 06ac7db | 2018-03-06 17:42:35 -0800 | [diff] [blame] | 60 | proc_stat |
| 61 | }:file r_file_perms; |
| 62 | |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 63 | # Signal java processes to dump their stack and get the results |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 64 | allow incidentd { appdomain ephemeral_app system_server }:process signal; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 65 | |
| 66 | # Signal native processes to dump their stack. |
| 67 | # This list comes from native_processes_to_dump in incidentd/utils.c |
| 68 | allow incidentd { |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 69 | # This list comes from native_processes_to_dump in dumputils/dump_utils.cpp |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 70 | audioserver |
| 71 | cameraserver |
| 72 | drmserver |
| 73 | inputflinger |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 74 | mediadrmserver |
| 75 | mediaextractor |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 76 | mediametrics |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 77 | mediaserver |
| 78 | sdcardd |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 79 | statsd |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 80 | surfaceflinger |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 81 | |
| 82 | # This list comes from hal_interfaces_to_dump in dumputils/dump_utils.cpp |
| 83 | hal_audio_server |
| 84 | hal_bluetooth_server |
| 85 | hal_camera_server |
| 86 | hal_graphics_composer_server |
| 87 | hal_sensors_server |
| 88 | hal_vr_server |
| 89 | mediacodec # TODO(b/36375899): hal_omx_server |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 90 | }:process signal; |
| 91 | |
| 92 | # Allow incidentd to make binder calls to any binder service |
Yi Jin | bc24ba7 | 2018-01-22 14:00:46 -0800 | [diff] [blame] | 93 | binder_call(incidentd, system_server) |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 94 | binder_call(incidentd, appdomain) |
| 95 | |
| 96 | # Reading /proc/PID/maps of other processes |
Kweku Adams | 985db6d | 2018-03-12 16:21:40 -0700 | [diff] [blame^] | 97 | userdebug_or_eng(`allow incidentd self:global_capability_class_set { sys_ptrace }'); |
| 98 | # incidentd has capability sys_ptrace, but should only use that capability for |
| 99 | # accessing sensitive /proc/PID files, never for using ptrace attach. |
| 100 | neverallow incidentd *:process ptrace; |
| 101 | |
| 102 | allow incidentd self:global_capability_class_set { |
| 103 | # Send signals to processes |
| 104 | kill |
| 105 | }; |
| 106 | |
| 107 | # Connect to tombstoned to intercept dumps. |
| 108 | unix_socket_connect(incidentd, tombstoned_intercept, tombstoned) |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 109 | |
| 110 | # Run a shell. |
| 111 | allow incidentd shell_exec:file rx_file_perms; |
| 112 | |
| 113 | # 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] | 114 | userdebug_or_eng(`read_logd(incidentd)') |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 115 | # TODO control_logd(incidentd) |
| 116 | |
| 117 | # Allow incidentd to find these standard groups of services. |
| 118 | # Others can be whitelisted individually. |
| 119 | allow incidentd { |
| 120 | system_server_service |
| 121 | app_api_service |
| 122 | system_api_service |
| 123 | }:service_manager find; |
| 124 | |
| 125 | # Only incidentd can publish the binder service |
| 126 | add_service(incidentd, incident_service) |
| 127 | |
| 128 | # Allow pipes from (and only from) incident |
| 129 | allow incidentd incident:fd use; |
| 130 | allow incidentd incident:fifo_file write; |
| 131 | |
| 132 | # Allow incident to call back to incident with status updates. |
| 133 | binder_call(incidentd, incident) |
| 134 | |
| 135 | ### |
| 136 | ### neverallow rules |
| 137 | ### |
| 138 | |
| 139 | # only system_server, system_app and incident command can find the incident service |
yro | cf38ca5 | 2018-01-22 13:56:41 -0800 | [diff] [blame] | 140 | neverallow { |
| 141 | domain |
| 142 | -incident |
| 143 | -incidentd |
| 144 | -statsd |
| 145 | -system_app |
| 146 | -system_server |
| 147 | } incident_service:service_manager find; |
Joe Onorato | 41f93db | 2016-11-20 23:23:04 -0800 | [diff] [blame] | 148 | |
| 149 | # only incidentd and the other root services in limited circumstances |
| 150 | # can get to the files in /data/misc/incidents |
| 151 | # |
| 152 | # write, execute, append are forbidden almost everywhere |
| 153 | neverallow { domain -incidentd -init -vold } incident_data_file:file { |
| 154 | w_file_perms |
| 155 | x_file_perms |
| 156 | create |
| 157 | rename |
| 158 | setattr |
| 159 | unlink |
| 160 | append |
| 161 | }; |
| 162 | # read is also allowed by system_server, for when the file is handed to dropbox |
| 163 | neverallow { domain -incidentd -init -vold -system_server } incident_data_file:file r_file_perms; |
| 164 | # limited access to the directory itself |
| 165 | neverallow { domain -incidentd -init -vold } incident_data_file:dir create_dir_perms; |
| 166 | |