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