xref: /aosp_15_r20/system/sepolicy/prebuilts/api/31.0/public/shell.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Domain for shell processes spawned by ADB or console service.
2*e4a36f41SAndroid Build Coastguard Workertype shell, domain, mlstrustedsubject;
3*e4a36f41SAndroid Build Coastguard Workertype shell_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Worker# Create and use network sockets.
6*e4a36f41SAndroid Build Coastguard Workernet_domain(shell)
7*e4a36f41SAndroid Build Coastguard Worker
8*e4a36f41SAndroid Build Coastguard Worker# logcat
9*e4a36f41SAndroid Build Coastguard Workerread_logd(shell)
10*e4a36f41SAndroid Build Coastguard Workercontrol_logd(shell)
11*e4a36f41SAndroid Build Coastguard Worker# logcat -L (directly, or via dumpstate)
12*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:dir search;
13*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:file r_file_perms;
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Worker# Root fs.
16*e4a36f41SAndroid Build Coastguard Workerallow shell rootfs:dir r_dir_perms;
17*e4a36f41SAndroid Build Coastguard Worker
18*e4a36f41SAndroid Build Coastguard Worker# read files in /data/anr
19*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:dir r_dir_perms;
20*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:file r_file_perms;
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tmp.
23*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:dir create_dir_perms;
24*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file create_file_perms;
25*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file rx_file_perms;
26*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:lnk_file create_file_perms;
27*e4a36f41SAndroid Build Coastguard Worker
28*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tests.
29*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:dir create_dir_perms;
30*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:file create_file_perms;
31*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:file rx_file_perms;
32*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:lnk_file create_file_perms;
33*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:sock_file create_file_perms;
34*e4a36f41SAndroid Build Coastguard Worker
35*e4a36f41SAndroid Build Coastguard Worker# Read and delete from /data/local/traces.
36*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:file { r_file_perms unlink };
37*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:dir { r_dir_perms remove_name write };
38*e4a36f41SAndroid Build Coastguard Worker
39*e4a36f41SAndroid Build Coastguard Worker# Access /data/misc/profman.
40*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:dir { write remove_name r_dir_perms };
41*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:file { unlink r_file_perms };
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# Read/execute files in /data/nativetest
44*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
45*e4a36f41SAndroid Build Coastguard Worker  allow shell nativetest_data_file:dir r_dir_perms;
46*e4a36f41SAndroid Build Coastguard Worker  allow shell nativetest_data_file:file rx_file_perms;
47*e4a36f41SAndroid Build Coastguard Worker')
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker# adb bugreport
50*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(shell, dumpstate, dumpstate)
51*e4a36f41SAndroid Build Coastguard Worker
52*e4a36f41SAndroid Build Coastguard Workerallow shell devpts:chr_file rw_file_perms;
53*e4a36f41SAndroid Build Coastguard Workerallow shell tty_device:chr_file rw_file_perms;
54*e4a36f41SAndroid Build Coastguard Workerallow shell console_device:chr_file rw_file_perms;
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:dir r_dir_perms;
57*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:chr_file r_file_perms;
58*e4a36f41SAndroid Build Coastguard Worker
59*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, system_file)
60*e4a36f41SAndroid Build Coastguard Workerallow shell system_file:file x_file_perms;
61*e4a36f41SAndroid Build Coastguard Workerallow shell toolbox_exec:file rx_file_perms;
62*e4a36f41SAndroid Build Coastguard Workerallow shell tzdatacheck_exec:file rx_file_perms;
63*e4a36f41SAndroid Build Coastguard Workerallow shell shell_exec:file rx_file_perms;
64*e4a36f41SAndroid Build Coastguard Workerallow shell zygote_exec:file rx_file_perms;
65*e4a36f41SAndroid Build Coastguard Worker
66*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, apk_data_file)
67*e4a36f41SAndroid Build Coastguard Worker
68*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
69*e4a36f41SAndroid Build Coastguard Worker  # "systrace --boot" support - allow boottrace service to run
70*e4a36f41SAndroid Build Coastguard Worker  allow shell boottrace_data_file:dir rw_dir_perms;
71*e4a36f41SAndroid Build Coastguard Worker  allow shell boottrace_data_file:file create_file_perms;
72*e4a36f41SAndroid Build Coastguard Worker')
73*e4a36f41SAndroid Build Coastguard Worker
74*e4a36f41SAndroid Build Coastguard Worker# allow shell access to services
75*e4a36f41SAndroid Build Coastguard Workerallow shell servicemanager:service_manager list;
76*e4a36f41SAndroid Build Coastguard Worker# don't allow shell to access GateKeeper service
77*e4a36f41SAndroid Build Coastguard Worker# TODO: why is this so broad? Tightening candidate? It needs at list:
78*e4a36f41SAndroid Build Coastguard Worker# - dumpstate_service (so it can receive dumpstate progress updates)
79*e4a36f41SAndroid Build Coastguard Workerallow shell {
80*e4a36f41SAndroid Build Coastguard Worker  service_manager_type
81*e4a36f41SAndroid Build Coastguard Worker  -apex_service
82*e4a36f41SAndroid Build Coastguard Worker  -dnsresolver_service
83*e4a36f41SAndroid Build Coastguard Worker  -gatekeeper_service
84*e4a36f41SAndroid Build Coastguard Worker  -incident_service
85*e4a36f41SAndroid Build Coastguard Worker  -installd_service
86*e4a36f41SAndroid Build Coastguard Worker  -iorapd_service
87*e4a36f41SAndroid Build Coastguard Worker  -netd_service
88*e4a36f41SAndroid Build Coastguard Worker  -system_suspend_control_internal_service
89*e4a36f41SAndroid Build Coastguard Worker  -system_suspend_control_service
90*e4a36f41SAndroid Build Coastguard Worker  -virtual_touchpad_service
91*e4a36f41SAndroid Build Coastguard Worker  -vold_service
92*e4a36f41SAndroid Build Coastguard Worker  -vr_hwc_service
93*e4a36f41SAndroid Build Coastguard Worker  -default_android_service
94*e4a36f41SAndroid Build Coastguard Worker}:service_manager find;
95*e4a36f41SAndroid Build Coastguard Workerallow shell dumpstate:binder call;
96*e4a36f41SAndroid Build Coastguard Worker
97*e4a36f41SAndroid Build Coastguard Worker# allow shell to get information from hwservicemanager
98*e4a36f41SAndroid Build Coastguard Worker# for instance, listing hardware services with lshal
99*e4a36f41SAndroid Build Coastguard Workerhwbinder_use(shell)
100*e4a36f41SAndroid Build Coastguard Workerallow shell hwservicemanager:hwservice_manager list;
101*e4a36f41SAndroid Build Coastguard Worker
102*e4a36f41SAndroid Build Coastguard Worker# allow shell to look through /proc/ for lsmod, ps, top, netstat, vmstat.
103*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, proc_net_type)
104*e4a36f41SAndroid Build Coastguard Worker
105*e4a36f41SAndroid Build Coastguard Workerallow shell {
106*e4a36f41SAndroid Build Coastguard Worker  proc_asound
107*e4a36f41SAndroid Build Coastguard Worker  proc_filesystems
108*e4a36f41SAndroid Build Coastguard Worker  proc_interrupts
109*e4a36f41SAndroid Build Coastguard Worker  proc_loadavg # b/124024827
110*e4a36f41SAndroid Build Coastguard Worker  proc_meminfo
111*e4a36f41SAndroid Build Coastguard Worker  proc_modules
112*e4a36f41SAndroid Build Coastguard Worker  proc_pid_max
113*e4a36f41SAndroid Build Coastguard Worker  proc_slabinfo
114*e4a36f41SAndroid Build Coastguard Worker  proc_stat
115*e4a36f41SAndroid Build Coastguard Worker  proc_timer
116*e4a36f41SAndroid Build Coastguard Worker  proc_uptime
117*e4a36f41SAndroid Build Coastguard Worker  proc_version
118*e4a36f41SAndroid Build Coastguard Worker  proc_vmstat
119*e4a36f41SAndroid Build Coastguard Worker  proc_zoneinfo
120*e4a36f41SAndroid Build Coastguard Worker}:file r_file_perms;
121*e4a36f41SAndroid Build Coastguard Worker
122*e4a36f41SAndroid Build Coastguard Worker# allow listing network interfaces under /sys/class/net.
123*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_net:dir r_dir_perms;
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, cgroup)
126*e4a36f41SAndroid Build Coastguard Workerallow shell cgroup_desc_file:file r_file_perms;
127*e4a36f41SAndroid Build Coastguard Workerallow shell cgroup_desc_api_file:file r_file_perms;
128*e4a36f41SAndroid Build Coastguard Workerallow shell vendor_cgroup_desc_file:file r_file_perms;
129*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, cgroup_v2)
130*e4a36f41SAndroid Build Coastguard Workerallow shell domain:dir { search open read getattr };
131*e4a36f41SAndroid Build Coastguard Workerallow shell domain:{ file lnk_file } { open read getattr };
132*e4a36f41SAndroid Build Coastguard Worker
133*e4a36f41SAndroid Build Coastguard Worker# statvfs() of /proc and other labeled filesystems
134*e4a36f41SAndroid Build Coastguard Worker# (yaffs2, jffs2, ext2, ext3, ext4, xfs, btrfs, f2fs, squashfs, overlay)
135*e4a36f41SAndroid Build Coastguard Workerallow shell { proc labeledfs }:filesystem getattr;
136*e4a36f41SAndroid Build Coastguard Worker
137*e4a36f41SAndroid Build Coastguard Worker# stat() of /dev
138*e4a36f41SAndroid Build Coastguard Workerallow shell device:dir getattr;
139*e4a36f41SAndroid Build Coastguard Worker
140*e4a36f41SAndroid Build Coastguard Worker# allow shell to read /proc/pid/attr/current for ps -Z
141*e4a36f41SAndroid Build Coastguard Workerallow shell domain:process getattr;
142*e4a36f41SAndroid Build Coastguard Worker
143*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes
144*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:dir r_dir_perms;
145*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:file r_file_perms;
146*e4a36f41SAndroid Build Coastguard Worker
147*e4a36f41SAndroid Build Coastguard Worker# enable shell domain to read/write files/dirs for bootchart data
148*e4a36f41SAndroid Build Coastguard Worker# User will creates the start and stop file via adb shell
149*e4a36f41SAndroid Build Coastguard Worker# and read other files created by init process under /data/bootchart
150*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:dir rw_dir_perms;
151*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:file create_file_perms;
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Worker# Make sure strace works for the non-privileged shell user
154*e4a36f41SAndroid Build Coastguard Workerallow shell self:process ptrace;
155*e4a36f41SAndroid Build Coastguard Worker
156*e4a36f41SAndroid Build Coastguard Worker# allow shell to get battery info
157*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs:dir r_dir_perms;
158*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:dir r_dir_perms;
159*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:file r_file_perms;
160*e4a36f41SAndroid Build Coastguard Worker
161*e4a36f41SAndroid Build Coastguard Worker# allow shell to list /sys/class/block/ to get storage type for CTS
162*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_block:dir r_dir_perms;
163*e4a36f41SAndroid Build Coastguard Worker
164*e4a36f41SAndroid Build Coastguard Worker# Allow access to ion memory allocation device.
165*e4a36f41SAndroid Build Coastguard Workerallow shell ion_device:chr_file rw_file_perms;
166*e4a36f41SAndroid Build Coastguard Worker
167*e4a36f41SAndroid Build Coastguard Worker#
168*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insecure chr_file's is done
169*e4a36f41SAndroid Build Coastguard Worker# via a host side test
170*e4a36f41SAndroid Build Coastguard Worker#
171*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:dir r_dir_perms;
172*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:chr_file getattr;
173*e4a36f41SAndroid Build Coastguard Worker
174*e4a36f41SAndroid Build Coastguard Worker# /dev/fd is a symlink
175*e4a36f41SAndroid Build Coastguard Workerallow shell proc:lnk_file getattr;
176*e4a36f41SAndroid Build Coastguard Worker
177*e4a36f41SAndroid Build Coastguard Worker#
178*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insucre blk_file's is done
179*e4a36f41SAndroid Build Coastguard Worker# via hostside test
180*e4a36f41SAndroid Build Coastguard Worker#
181*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:blk_file getattr;
182*e4a36f41SAndroid Build Coastguard Worker
183*e4a36f41SAndroid Build Coastguard Worker# read selinux policy files
184*e4a36f41SAndroid Build Coastguard Workerallow shell file_contexts_file:file r_file_perms;
185*e4a36f41SAndroid Build Coastguard Workerallow shell property_contexts_file:file r_file_perms;
186*e4a36f41SAndroid Build Coastguard Workerallow shell seapp_contexts_file:file r_file_perms;
187*e4a36f41SAndroid Build Coastguard Workerallow shell service_contexts_file:file r_file_perms;
188*e4a36f41SAndroid Build Coastguard Workerallow shell sepolicy_file:file r_file_perms;
189*e4a36f41SAndroid Build Coastguard Worker
190*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start up vendor shell
191*e4a36f41SAndroid Build Coastguard Workerallow shell vendor_shell_exec:file rx_file_perms;
192*e4a36f41SAndroid Build Coastguard Worker
193*e4a36f41SAndroid Build Coastguard Worker# Everything is labeled as rootfs in recovery mode. Allow shell to
194*e4a36f41SAndroid Build Coastguard Worker# execute them.
195*e4a36f41SAndroid Build Coastguard Workerrecovery_only(`
196*e4a36f41SAndroid Build Coastguard Worker  allow shell rootfs:file rx_file_perms;
197*e4a36f41SAndroid Build Coastguard Worker')
198*e4a36f41SAndroid Build Coastguard Worker
199*e4a36f41SAndroid Build Coastguard Worker###
200*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
201*e4a36f41SAndroid Build Coastguard Worker###
202*e4a36f41SAndroid Build Coastguard Worker
203*e4a36f41SAndroid Build Coastguard Worker# Do not allow shell to hard link to any files.
204*e4a36f41SAndroid Build Coastguard Worker# In particular, if shell hard links to app data
205*e4a36f41SAndroid Build Coastguard Worker# files, installd will not be able to guarantee the deletion
206*e4a36f41SAndroid Build Coastguard Worker# of the linked to file. Hard links also contribute to security
207*e4a36f41SAndroid Build Coastguard Worker# bugs, so we want to ensure the shell user never has this
208*e4a36f41SAndroid Build Coastguard Worker# capability.
209*e4a36f41SAndroid Build Coastguard Workerneverallow shell file_type:file link;
210*e4a36f41SAndroid Build Coastguard Worker
211*e4a36f41SAndroid Build Coastguard Worker# Do not allow privileged socket ioctl commands
212*e4a36f41SAndroid Build Coastguard Workerneverallowxperm shell domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
213*e4a36f41SAndroid Build Coastguard Worker
214*e4a36f41SAndroid Build Coastguard Worker# limit shell access to sensitive char drivers to
215*e4a36f41SAndroid Build Coastguard Worker# only getattr required for host side test.
216*e4a36f41SAndroid Build Coastguard Workerneverallow shell {
217*e4a36f41SAndroid Build Coastguard Worker  fuse_device
218*e4a36f41SAndroid Build Coastguard Worker  hw_random_device
219*e4a36f41SAndroid Build Coastguard Worker  port_device
220*e4a36f41SAndroid Build Coastguard Worker}:chr_file ~getattr;
221*e4a36f41SAndroid Build Coastguard Worker
222*e4a36f41SAndroid Build Coastguard Worker# Limit shell to only getattr on blk devices for host side tests.
223*e4a36f41SAndroid Build Coastguard Workerneverallow shell dev_type:blk_file ~getattr;
224*e4a36f41SAndroid Build Coastguard Worker
225*e4a36f41SAndroid Build Coastguard Worker# b/30861057: Shell access to existing input devices is an abuse
226*e4a36f41SAndroid Build Coastguard Worker# vector. The shell user can inject events that look like they
227*e4a36f41SAndroid Build Coastguard Worker# originate from the touchscreen etc.
228*e4a36f41SAndroid Build Coastguard Worker# Everyone should have already moved to UiAutomation#injectInputEvent
229*e4a36f41SAndroid Build Coastguard Worker# if they are running instrumentation tests (i.e. CTS), Monkey for
230*e4a36f41SAndroid Build Coastguard Worker# their stress tests, and the input command (adb shell input ...) for
231*e4a36f41SAndroid Build Coastguard Worker# injecting swipes and things.
232*e4a36f41SAndroid Build Coastguard Workerneverallow shell input_device:chr_file no_w_file_perms;
233