huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
typeattribute incidentd coredomain;
typeattribute incidentd mlstrustedsubject;
 
init_daemon_domain(incidentd)
type incidentd_exec, system_file_type, exec_type, file_type;
binder_use(incidentd)
wakelock_use(incidentd)
 
# Allow incidentd to scan through /proc/pid for all processes
r_dir_file(incidentd, domain)
 
# Allow incidentd to kill incident_helper when timeout
allow incidentd incident_helper:process sigkill;
 
# Allow executing files on system, such as:
#   /system/bin/toolbox
#   /system/bin/logcat
#   /system/bin/dumpsys
allow incidentd system_file:file execute_no_trans;
allow incidentd toolbox_exec:file rx_file_perms;
 
# section id 1002, allow reading kernel version /proc/version
allow incidentd proc_version:file r_file_perms;
 
# section id 2001, allow reading /proc/pagetypeinfo
allow incidentd proc_pagetypeinfo:file r_file_perms;
 
# section id 2002, allow reading /d/wakeup_sources
allow incidentd debugfs_wakeup_sources:file r_file_perms;
 
# section id 2003, allow executing top
allow incidentd proc_meminfo:file { open read };
 
# section id 2004, allow reading /sys/devices/system/cpu/cpufreq/all_time_in_state
allow incidentd sysfs_devices_system_cpu:file r_file_perms;
 
# section id 2005, allow reading ps dump in full
allow incidentd domain:process getattr;
 
# section id 2006, allow reading /sys/class/power_supply/bms/battery_type
allow incidentd sysfs_batteryinfo:dir { search };
allow incidentd sysfs_batteryinfo:file r_file_perms;
 
# section id 2007, allow reading LAST_KMSG /sys/fs/pstore/console-ramoops
userdebug_or_eng(`allow incidentd pstorefs:dir search');
userdebug_or_eng(`allow incidentd pstorefs:file r_file_perms');
 
# section id 3023, allow obtaining stats report
allow incidentd stats_service:service_manager find;
binder_call(incidentd, statsd)
 
# section id 3026, allow reading /data/misc/perfetto-traces.
# TODO(b/134706389): remove when no longer used.
userdebug_or_eng(`
  allow incidentd perfetto_traces_data_file:dir r_dir_perms;
  allow incidentd perfetto_traces_data_file:file r_file_perms;
');
 
# Create and write into /data/misc/incidents
allow incidentd incident_data_file:dir rw_dir_perms;
allow incidentd incident_data_file:file create_file_perms;
 
# Enable incidentd to get stack traces.
binder_use(incidentd)
hwbinder_use(incidentd)
allow incidentd hwservicemanager:hwservice_manager { list };
get_prop(incidentd, hwservicemanager_prop)
allow incidentd hidl_manager_hwservice:hwservice_manager { find };
 
# Read files in /proc
allow incidentd {
  proc_cmdline
  proc_pipe_conf
  proc_stat
}:file r_file_perms;
 
# Signal java processes to dump their stack and get the results
allow incidentd { appdomain ephemeral_app system_server }:process signal;
 
# Signal native processes to dump their stack.
# This list comes from native_processes_to_dump in incidentd/utils.c
allow incidentd {
  # This list comes from native_processes_to_dump in dumputils/dump_utils.cpp
  audioserver
  cameraserver
  drmserver
  inputflinger
  mediadrmserver
  mediaextractor
  mediametrics
  mediaserver
  sdcardd
  statsd
  surfaceflinger
 
  # This list comes from hal_interfaces_to_dump in dumputils/dump_utils.cpp
  hal_audio_server
  hal_bluetooth_server
  hal_camera_server
  hal_codec2_server
  hal_face_server
  hal_graphics_allocator_server
  hal_graphics_composer_server
  hal_health_server
  hal_omx_server
  hal_sensors_server
  hal_vr_server
}:process signal;
 
# Allow incidentd to make binder calls to any binder service
binder_call(incidentd, system_server)
binder_call(incidentd, appdomain)
 
# Reading /proc/PID/maps of other processes
userdebug_or_eng(`allow incidentd self:global_capability_class_set { sys_ptrace }');
# incidentd has capability sys_ptrace, but should only use that capability for
# accessing sensitive /proc/PID files, never for using ptrace attach.
neverallow incidentd *:process ptrace;
 
allow incidentd self:global_capability_class_set {
    # Send signals to processes
    kill
};
 
# Connect to tombstoned to intercept dumps.
unix_socket_connect(incidentd, tombstoned_intercept, tombstoned)
 
# Run a shell.
allow incidentd shell_exec:file rx_file_perms;
 
# logd access - work to be done is a PII safe log (possibly an event log?)
userdebug_or_eng(`read_logd(incidentd)')
# TODO control_logd(incidentd)
 
# Allow incidentd to find these standard groups of services.
# Others can be whitelisted individually.
allow incidentd {
  system_server_service
  app_api_service
  system_api_service
}:service_manager find;
 
# Only incidentd can publish the binder service
add_service(incidentd, incident_service)
 
# Allow pipes only from dumpstate and incident
allow incidentd { dumpstate incident }:fd use;
allow incidentd { dumpstate incident }:fifo_file write;
 
# Allow incident to call back to incident with status updates.
binder_call(incidentd, incident)
 
###
### neverallow rules
###
 
# only specific domains can find the incident service
# TODO(b/134706389): remove "perfetto" when no longer used.
neverallow {
  domain
  -dumpstate
  -incident
  -incidentd
  userdebug_or_eng(`-perfetto')
  -priv_app
  -statsd
  -system_app
  -system_server
} incident_service:service_manager find;
 
# only incidentd and the other root services in limited circumstances
# can get to the files in /data/misc/incidents
#
# write, execute, append are forbidden almost everywhere
neverallow { domain -incidentd -init -vold } incident_data_file:file {
  w_file_perms
  x_file_perms
  create
  rename
  setattr
  unlink
  append
};
# read is also allowed by system_server, for when the file is handed to dropbox
neverallow { domain -incidentd -init -vold -system_server } incident_data_file:file r_file_perms;
# limited access to the directory itself
neverallow { domain -incidentd -init -vold } incident_data_file:dir create_dir_perms;