Inseob Kim | 43b6a31 | 2021-11-30 12:04:43 +0900 | [diff] [blame] | 1 | type statsd, domain, mlstrustedsubject; |
| 2 | |
| 3 | type statsd_exec, system_file_type, exec_type, file_type; |
| 4 | binder_use(statsd) |
| 5 | |
| 6 | # Allow statsd to scan through /proc/pid for all processes. |
| 7 | r_dir_file(statsd, domain) |
| 8 | |
| 9 | # Allow executing files on system, such as running a shell or running: |
| 10 | # /system/bin/toolbox |
| 11 | # /system/bin/logcat |
| 12 | # /system/bin/dumpsys |
| 13 | allow statsd devpts:chr_file { getattr ioctl read write }; |
| 14 | allow statsd shell_exec:file rx_file_perms; |
| 15 | allow statsd system_file:file execute_no_trans; |
| 16 | allow statsd toolbox_exec:file rx_file_perms; |
| 17 | |
| 18 | userdebug_or_eng(` |
| 19 | allow statsd su:fifo_file read; |
| 20 | ') |
| 21 | |
| 22 | # Create, read, and write into /data/misc/stats-data, /data/misc/stats-system. |
| 23 | allow statsd stats_data_file:dir create_dir_perms; |
| 24 | allow statsd stats_data_file:file create_file_perms; |
| 25 | |
| 26 | # Allow statsd to make binder calls to any binder service. |
| 27 | binder_call(statsd, appdomain) |
| 28 | binder_call(statsd, healthd) |
| 29 | binder_call(statsd, incidentd) |
| 30 | binder_call(statsd, system_server) |
| 31 | |
| 32 | # Allow statsd to interact with gpuservice |
| 33 | allow statsd gpu_service:service_manager find; |
| 34 | binder_call(statsd, gpuservice) |
| 35 | |
| 36 | # Allow statsd to interact with keystore to pull atoms |
| 37 | allow statsd keystore_service:service_manager find; |
| 38 | binder_call(statsd, keystore) |
| 39 | |
| 40 | # Allow statsd to interact with mediametrics |
| 41 | allow statsd mediametrics_service:service_manager find; |
| 42 | binder_call(statsd, mediametrics) |
| 43 | |
| 44 | # Allow logd access. |
| 45 | read_logd(statsd) |
| 46 | control_logd(statsd) |
| 47 | |
| 48 | # Grant statsd with permissions to register the services. |
| 49 | allow statsd { |
| 50 | app_api_service |
| 51 | incident_service |
| 52 | system_api_service |
| 53 | }:service_manager find; |
| 54 | |
| 55 | # Grant statsd to access health hal to access battery metrics. |
| 56 | allow statsd hal_health_hwservice:hwservice_manager find; |
| 57 | |
| 58 | # Allow statsd to send dump info to dumpstate |
| 59 | allow statsd dumpstate:fd use; |
| 60 | allow statsd dumpstate:fifo_file { getattr write }; |
| 61 | |
| 62 | # Allow access to with hardware layer and process stats. |
| 63 | allow statsd proc_uid_cputime_showstat:file { getattr open read }; |
| 64 | hal_client_domain(statsd, hal_health) |
| 65 | hal_client_domain(statsd, hal_power) |
| 66 | hal_client_domain(statsd, hal_power_stats) |
| 67 | hal_client_domain(statsd, hal_thermal) |
| 68 | |
| 69 | # Allow 'adb shell cmd' to upload configs and download output. |
| 70 | allow statsd adbd:fd use; |
| 71 | allow statsd adbd:unix_stream_socket { getattr read write }; |
| 72 | allow statsd shell:fifo_file { getattr read write }; |
| 73 | |
| 74 | unix_socket_send(statsd, statsdw, statsd) |
| 75 | |
| 76 | ### |
| 77 | ### neverallow rules |
| 78 | ### |
| 79 | |
| 80 | # Only statsd and the other root services in limited circumstances. |
| 81 | # can get to the files in /data/misc/stats-data, /data/misc/stats-service. |
| 82 | # Other services are prohibitted from accessing the file. |
| 83 | neverallow { domain -statsd -system_server -init -vold } stats_data_file:file *; |
| 84 | |
| 85 | # Limited access to the directory itself. |
| 86 | neverallow { domain -statsd -system_server -init -vold } stats_data_file:dir *; |