1*e4a36f41SAndroid Build Coastguard Workertypeattribute statsd coredomain; 2*e4a36f41SAndroid Build Coastguard Worker 3*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(statsd) 4*e4a36f41SAndroid Build Coastguard Worker 5*e4a36f41SAndroid Build Coastguard Worker# Allow to exec the perfetto cmdline client and pass it the trace config on 6*e4a36f41SAndroid Build Coastguard Worker# stdint through a pipe. It allows statsd to capture traces and hand them 7*e4a36f41SAndroid Build Coastguard Worker# to Android dropbox. 8*e4a36f41SAndroid Build Coastguard Workerallow statsd perfetto_exec:file rx_file_perms; 9*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(statsd, perfetto_exec, perfetto) 10*e4a36f41SAndroid Build Coastguard Worker 11*e4a36f41SAndroid Build Coastguard Worker# Grant statsd with permissions to register the services. 12*e4a36f41SAndroid Build Coastguard Workerallow statsd { 13*e4a36f41SAndroid Build Coastguard Worker statscompanion_service 14*e4a36f41SAndroid Build Coastguard Worker}:service_manager find; 15*e4a36f41SAndroid Build Coastguard Worker 16*e4a36f41SAndroid Build Coastguard Worker# Allow incidentd to obtain the statsd incident section. 17*e4a36f41SAndroid Build Coastguard Workerallow statsd incidentd:fifo_file write; 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker# Allow StatsCompanionService to pipe data to statsd. 20*e4a36f41SAndroid Build Coastguard Workerallow statsd system_server:fifo_file { read write getattr }; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Allow any app to pipe data to statsd. 23*e4a36f41SAndroid Build Coastguard Worker# Access control to all statsd APIs inherit from system_api_service, so 24*e4a36f41SAndroid Build Coastguard Worker# appdomain permissions are granted to avoid listing each individual 25*e4a36f41SAndroid Build Coastguard Worker# service that can access system_api_service. 26*e4a36f41SAndroid Build Coastguard Workerallow statsd appdomain:fifo_file { read write getattr }; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to retrieve SF statistics over binder 29*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, surfaceflinger); 30*e4a36f41SAndroid Build Coastguard Worker 31*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to read its system properties 32*e4a36f41SAndroid Build Coastguard Workerget_prop(statsd, device_config_statsd_native_prop) 33*e4a36f41SAndroid Build Coastguard Workerget_prop(statsd, device_config_statsd_native_boot_prop) 34*e4a36f41SAndroid Build Coastguard Worker 35*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to read misctl properties (for 16 KB) 36*e4a36f41SAndroid Build Coastguard Workerget_prop(statsd, misctrl_prop) 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to write uprobestats configs. 39*e4a36f41SAndroid Build Coastguard Workerallow statsd uprobestats_configs_data_file:dir rw_dir_perms; 40*e4a36f41SAndroid Build Coastguard Workerallow statsd uprobestats_configs_data_file:file create_file_perms; 41*e4a36f41SAndroid Build Coastguard Worker 42*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to trigger uprobestats via property. 43*e4a36f41SAndroid Build Coastguard Workerset_prop(statsd, uprobestats_start_with_config_prop); 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to use io_uring 46*e4a36f41SAndroid Build Coastguard Workerio_uring_use(statsd) 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to start the uprobestats service. 49*e4a36f41SAndroid Build Coastguard Workerset_prop(statsd, ctl_uprobestats_prop) 50*e4a36f41SAndroid Build Coastguard Workerbinder_use(statsd) 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to scan through /proc/pid for all processes. 53*e4a36f41SAndroid Build Coastguard Workerr_dir_file(statsd, domain) 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Allow executing files on system, such as running a shell or running: 56*e4a36f41SAndroid Build Coastguard Worker# /system/bin/toolbox 57*e4a36f41SAndroid Build Coastguard Worker# /system/bin/logcat 58*e4a36f41SAndroid Build Coastguard Worker# /system/bin/dumpsys 59*e4a36f41SAndroid Build Coastguard Workerallow statsd devpts:chr_file { getattr ioctl read write }; 60*e4a36f41SAndroid Build Coastguard Workerallow statsd shell_exec:file rx_file_perms; 61*e4a36f41SAndroid Build Coastguard Workerallow statsd system_file:file execute_no_trans; 62*e4a36f41SAndroid Build Coastguard Workerallow statsd toolbox_exec:file rx_file_perms; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 65*e4a36f41SAndroid Build Coastguard Worker allow statsd su:fifo_file read; 66*e4a36f41SAndroid Build Coastguard Worker') 67*e4a36f41SAndroid Build Coastguard Worker 68*e4a36f41SAndroid Build Coastguard Worker# Create, read, and write into 69*e4a36f41SAndroid Build Coastguard Worker# /data/misc/stats-active-metric 70*e4a36f41SAndroid Build Coastguard Worker# /data/misc/stats-data 71*e4a36f41SAndroid Build Coastguard Worker# /data/misc/stats-metadata 72*e4a36f41SAndroid Build Coastguard Worker# /data/misc/stats-service 73*e4a36f41SAndroid Build Coastguard Worker# /data/misc/train-info 74*e4a36f41SAndroid Build Coastguard Workerallow statsd stats_data_file:dir create_dir_perms; 75*e4a36f41SAndroid Build Coastguard Workerallow statsd stats_data_file:file create_file_perms; 76*e4a36f41SAndroid Build Coastguard Workerallow statsd stats_config_data_file:dir create_dir_perms; 77*e4a36f41SAndroid Build Coastguard Workerallow statsd stats_config_data_file:file create_file_perms; 78*e4a36f41SAndroid Build Coastguard Worker 79*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to make binder calls to any binder service. 80*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, appdomain) 81*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, incidentd) 82*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, system_server) 83*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, traced_probes) 84*e4a36f41SAndroid Build Coastguard Worker 85*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to interact with gpuservice 86*e4a36f41SAndroid Build Coastguard Workerallow statsd gpu_service:service_manager find; 87*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, gpuservice) 88*e4a36f41SAndroid Build Coastguard Worker 89*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to interact with keystore to pull atoms 90*e4a36f41SAndroid Build Coastguard Workerallow statsd keystore_service:service_manager find; 91*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, keystore) 92*e4a36f41SAndroid Build Coastguard Worker 93*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to interact with mediametrics 94*e4a36f41SAndroid Build Coastguard Workerallow statsd mediametrics_service:service_manager find; 95*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, mediametrics) 96*e4a36f41SAndroid Build Coastguard Worker 97*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to interact with mediametrics 98*e4a36f41SAndroid Build Coastguard Workerallow statsd mediaserver_service:service_manager find; 99*e4a36f41SAndroid Build Coastguard Workerbinder_call(statsd, mediaserver) 100*e4a36f41SAndroid Build Coastguard Worker 101*e4a36f41SAndroid Build Coastguard Worker# Allow logd access. 102*e4a36f41SAndroid Build Coastguard Workerread_logd(statsd) 103*e4a36f41SAndroid Build Coastguard Workercontrol_logd(statsd) 104*e4a36f41SAndroid Build Coastguard Worker 105*e4a36f41SAndroid Build Coastguard Worker# Grant statsd with permissions to register the services. 106*e4a36f41SAndroid Build Coastguard Workerallow statsd { 107*e4a36f41SAndroid Build Coastguard Worker app_api_service 108*e4a36f41SAndroid Build Coastguard Worker incident_service 109*e4a36f41SAndroid Build Coastguard Worker system_api_service 110*e4a36f41SAndroid Build Coastguard Worker}:service_manager find; 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker# Grant statsd to access health hal to access battery metrics. 113*e4a36f41SAndroid Build Coastguard Workerallow statsd hal_health_hwservice:hwservice_manager find; 114*e4a36f41SAndroid Build Coastguard Worker 115*e4a36f41SAndroid Build Coastguard Worker# Allow statsd to send dump info to dumpstate 116*e4a36f41SAndroid Build Coastguard Workerallow statsd dumpstate:fd use; 117*e4a36f41SAndroid Build Coastguard Workerallow statsd dumpstate:fifo_file { getattr write }; 118*e4a36f41SAndroid Build Coastguard Worker 119*e4a36f41SAndroid Build Coastguard Worker# Allow access to with hardware layer and process stats. 120*e4a36f41SAndroid Build Coastguard Workerallow statsd proc_uid_cputime_showstat:file { getattr open read }; 121*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(statsd, hal_health) 122*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(statsd, hal_power) 123*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(statsd, hal_power_stats) 124*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(statsd, hal_thermal) 125*e4a36f41SAndroid Build Coastguard Worker 126*e4a36f41SAndroid Build Coastguard Worker# Allow 'adb shell cmd' to upload configs and download output. 127*e4a36f41SAndroid Build Coastguard Workerallow statsd adbd:fd use; 128*e4a36f41SAndroid Build Coastguard Workerallow statsd adbd:unix_stream_socket { getattr read write }; 129*e4a36f41SAndroid Build Coastguard Workerallow statsd shell:fifo_file { getattr read write }; 130*e4a36f41SAndroid Build Coastguard Worker 131*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(statsd, statsdw, statsd) 132*e4a36f41SAndroid Build Coastguard Worker 133*e4a36f41SAndroid Build Coastguard Worker### 134*e4a36f41SAndroid Build Coastguard Worker### neverallow rules 135*e4a36f41SAndroid Build Coastguard Worker### 136*e4a36f41SAndroid Build Coastguard Worker 137*e4a36f41SAndroid Build Coastguard Worker# Only statsd and the other root services in limited circumstances. 138*e4a36f41SAndroid Build Coastguard Worker# can get to the files in /data/misc/stats-data, /data/misc/stats-service. 139*e4a36f41SAndroid Build Coastguard Worker# Other services are prohibitted from accessing the file. 140*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -statsd -init -vold } stats_data_file:file *; 141*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -statsd -system_server -init -vold } stats_config_data_file:file *; 142*e4a36f41SAndroid Build Coastguard Worker 143*e4a36f41SAndroid Build Coastguard Worker 144*e4a36f41SAndroid Build Coastguard Worker# Limited access to the directory itself. 145*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -statsd -init -vold } stats_data_file:dir *; 146*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -statsd -system_server -init -vold } stats_config_data_file:dir *; 147