Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame^] | 1 | typeattribute incidentd coredomain; |
| 2 | typeattribute incidentd mlstrustedsubject; |
| 3 | |
| 4 | init_daemon_domain(incidentd) |
| 5 | type incidentd_exec, system_file_type, exec_type, file_type; |
| 6 | binder_use(incidentd) |
| 7 | wakelock_use(incidentd) |
| 8 | |
| 9 | # Allow incidentd to scan through /proc/pid for all processes |
| 10 | r_dir_file(incidentd, domain) |
| 11 | |
| 12 | # Allow incidentd to kill incident_helper when timeout |
| 13 | allow incidentd incident_helper:process sigkill; |
| 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 | |
| 22 | # section id 1002, allow reading kernel version /proc/version |
| 23 | allow incidentd proc_version:file r_file_perms; |
| 24 | |
| 25 | # section id 1116, allow accessing statsd socket |
| 26 | unix_socket_send(incidentd, statsdw, statsd) |
| 27 | |
| 28 | # section id 2001, allow reading /proc/pagetypeinfo |
| 29 | allow incidentd proc_pagetypeinfo:file r_file_perms; |
| 30 | |
| 31 | # section id 2002, allow reading /d/wakeup_sources |
| 32 | no_debugfs_restriction(` |
| 33 | allow incidentd debugfs_wakeup_sources:file r_file_perms; |
| 34 | ') |
| 35 | |
| 36 | # section id 2003, allow executing top |
| 37 | allow incidentd proc_meminfo:file { open read }; |
| 38 | |
| 39 | # section id 2004, allow reading /sys/devices/system/cpu/cpufreq/all_time_in_state |
| 40 | allow incidentd sysfs_devices_system_cpu:file r_file_perms; |
| 41 | |
| 42 | # section id 2005, allow reading ps dump in full |
| 43 | allow incidentd domain:process getattr; |
| 44 | |
| 45 | # section id 2006, allow reading /sys/class/power_supply/bms/battery_type |
| 46 | allow incidentd sysfs_batteryinfo:dir { search }; |
| 47 | allow incidentd sysfs_batteryinfo:file r_file_perms; |
| 48 | |
| 49 | # section id 2007, allow reading LAST_KMSG /sys/fs/pstore/console-ramoops |
| 50 | userdebug_or_eng(`allow incidentd pstorefs:dir search'); |
| 51 | userdebug_or_eng(`allow incidentd pstorefs:file r_file_perms'); |
| 52 | |
| 53 | # section id 3023, allow obtaining stats report |
| 54 | allow incidentd stats_service:service_manager find; |
| 55 | binder_call(incidentd, statsd) |
| 56 | |
| 57 | # section id 3026, allow reading /data/misc/perfetto-traces. |
| 58 | allow incidentd perfetto_traces_data_file:dir r_dir_perms; |
| 59 | allow incidentd perfetto_traces_data_file:file r_file_perms; |
| 60 | |
| 61 | # section id 3052, allow accessing nfc_service |
| 62 | allow incidentd nfc_service:service_manager find; |
| 63 | |
| 64 | # Create and write into /data/misc/incidents |
| 65 | allow incidentd incident_data_file:dir rw_dir_perms; |
| 66 | allow incidentd incident_data_file:file create_file_perms; |
| 67 | |
| 68 | # Enable incidentd to get stack traces. |
| 69 | binder_use(incidentd) |
| 70 | hwbinder_use(incidentd) |
| 71 | allow incidentd hwservicemanager:hwservice_manager { list }; |
| 72 | get_prop(incidentd, hwservicemanager_prop) |
| 73 | allow incidentd hidl_manager_hwservice:hwservice_manager { find }; |
| 74 | |
| 75 | # Read files in /proc |
| 76 | allow incidentd { |
| 77 | proc_cmdline |
| 78 | proc_pid_max |
| 79 | proc_pipe_conf |
| 80 | proc_stat |
| 81 | }:file r_file_perms; |
| 82 | |
| 83 | # Signal java processes to dump their stack and get the results |
| 84 | allow incidentd { appdomain ephemeral_app system_server }:process signal; |
| 85 | |
| 86 | # Signal native processes to dump their stack. |
| 87 | # This list comes from native_processes_to_dump in incidentd/utils.c |
| 88 | allow incidentd { |
| 89 | # This list comes from native_processes_to_dump in dumputils/dump_utils.cpp |
| 90 | audioserver |
| 91 | cameraserver |
| 92 | drmserver |
| 93 | inputflinger |
| 94 | mediadrmserver |
| 95 | mediaextractor |
| 96 | mediametrics |
| 97 | mediaserver |
| 98 | sdcardd |
| 99 | statsd |
| 100 | surfaceflinger |
| 101 | |
| 102 | # This list comes from hal_interfaces_to_dump in dumputils/dump_utils.cpp |
| 103 | hal_audio_server |
| 104 | hal_bluetooth_server |
| 105 | hal_camera_server |
| 106 | hal_codec2_server |
| 107 | hal_face_server |
| 108 | hal_graphics_allocator_server |
| 109 | hal_graphics_composer_server |
| 110 | hal_health_server |
| 111 | hal_omx_server |
| 112 | hal_sensors_server |
| 113 | hal_vr_server |
| 114 | }:process signal; |
| 115 | |
| 116 | # Allow incidentd to make binder calls to any binder service |
| 117 | binder_call(incidentd, system_server) |
| 118 | binder_call(incidentd, appdomain) |
| 119 | |
| 120 | # Reading /proc/PID/maps of other processes |
| 121 | userdebug_or_eng(`allow incidentd self:global_capability_class_set { sys_ptrace }'); |
| 122 | # incidentd has capability sys_ptrace, but should only use that capability for |
| 123 | # accessing sensitive /proc/PID files, never for using ptrace attach. |
| 124 | neverallow incidentd *:process ptrace; |
| 125 | |
| 126 | allow incidentd self:global_capability_class_set { |
| 127 | # Send signals to processes |
| 128 | kill |
| 129 | }; |
| 130 | |
| 131 | # Connect to tombstoned to intercept dumps. |
| 132 | unix_socket_connect(incidentd, tombstoned_intercept, tombstoned) |
| 133 | |
| 134 | # Run a shell. |
| 135 | allow incidentd shell_exec:file rx_file_perms; |
| 136 | |
| 137 | # For running am, incident-helper-cmd and similar framework commands. |
| 138 | # Run /system/bin/app_process. |
| 139 | allow incidentd zygote_exec:file { rx_file_perms }; |
| 140 | # Access the runtime feature flag properties. |
| 141 | get_prop(incidentd, device_config_runtime_native_prop) |
| 142 | get_prop(incidentd, device_config_runtime_native_boot_prop) |
| 143 | # ART locks profile files. |
| 144 | allow incidentd system_file:file lock; |
| 145 | # Incidentd should never exec from the memory (e.g. JIT cache). These denials are expected. |
| 146 | dontaudit incidentd dalvikcache_data_file:dir r_dir_perms; |
| 147 | dontaudit incidentd apex_module_data_file:dir r_dir_perms; |
| 148 | dontaudit incidentd apex_art_data_file:dir r_dir_perms; |
| 149 | dontaudit incidentd tmpfs:file rwx_file_perms; |
| 150 | |
| 151 | # logd access - work to be done is a PII safe log (possibly an event log?) |
| 152 | userdebug_or_eng(`read_logd(incidentd)') |
| 153 | # TODO control_logd(incidentd) |
| 154 | |
| 155 | # Access /data/misc/logd |
| 156 | r_dir_file(incidentd, misc_logd_file) |
| 157 | |
| 158 | # Allow incidentd to find these standard groups of services. |
| 159 | # Others can be allowlisted individually. |
| 160 | allow incidentd { |
| 161 | system_server_service |
| 162 | app_api_service |
| 163 | system_api_service |
| 164 | }:service_manager find; |
| 165 | |
| 166 | # Only incidentd can publish the binder service |
| 167 | add_service(incidentd, incident_service) |
| 168 | |
| 169 | # Allow pipes only from dumpstate and incident |
| 170 | allow incidentd { dumpstate incident }:fd use; |
| 171 | allow incidentd { dumpstate incident }:fifo_file write; |
| 172 | |
| 173 | # Allow incident to call back to incident with status updates. |
| 174 | binder_call(incidentd, incident) |
| 175 | |
| 176 | # Read device serial number from system properties |
| 177 | # This is used to track reports from lab testing devices |
| 178 | userdebug_or_eng(` |
| 179 | get_prop(incidentd, serialno_prop) |
| 180 | ') |
| 181 | |
| 182 | # Read ro.boot.bootreason, persist.sys.boot.bootreason |
| 183 | # This is used to track reports from lab testing devices |
| 184 | userdebug_or_eng(` |
| 185 | get_prop(incidentd, bootloader_boot_reason_prop); |
| 186 | get_prop(incidentd, system_boot_reason_prop); |
| 187 | get_prop(incidentd, last_boot_reason_prop); |
| 188 | ') |
| 189 | |
| 190 | ### |
| 191 | ### neverallow rules |
| 192 | ### |
| 193 | # only incidentd and the other root services in limited circumstances |
| 194 | # can get to the files in /data/misc/incidents |
| 195 | # |
| 196 | # write, execute, append are forbidden almost everywhere |
| 197 | neverallow { domain -incidentd -init -vold } incident_data_file:file { |
| 198 | w_file_perms |
| 199 | x_file_perms |
| 200 | create |
| 201 | rename |
| 202 | setattr |
| 203 | unlink |
| 204 | append |
| 205 | }; |
| 206 | # read is also allowed by system_server, for when the file is handed to dropbox |
| 207 | neverallow { domain -incidentd -init -vold -system_server } incident_data_file:file r_file_perms; |
| 208 | # limited access to the directory itself |
| 209 | neverallow { domain -incidentd -init -vold } incident_data_file:dir create_dir_perms; |
| 210 | |