xref: /aosp_15_r20/system/sepolicy/private/sdk_sandbox_all.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker###
2*e4a36f41SAndroid Build Coastguard Worker### sdk_sandbox_all
3*e4a36f41SAndroid Build Coastguard Worker###
4*e4a36f41SAndroid Build Coastguard Worker### This file defines the rules shared by all sdk_sandbox_all domains.
5*e4a36f41SAndroid Build Coastguard Worker### Apps are labeled based on mac_permissions.xml (maps signer and
6*e4a36f41SAndroid Build Coastguard Worker### optionally package name to seinfo value) and seapp_contexts (maps UID
7*e4a36f41SAndroid Build Coastguard Worker### and optionally seinfo value to domain for process and type for data
8*e4a36f41SAndroid Build Coastguard Worker### directory).  The sdk_sandbox_all_all attribute is assigned to all default
9*e4a36f41SAndroid Build Coastguard Worker### seapp_contexts for any app with UID between FIRST_SDK_SANDBOX_UID (20000)
10*e4a36f41SAndroid Build Coastguard Worker### and LAST_SDK_SANDBOX_UID (29999) if the app has no specific seinfo
11*e4a36f41SAndroid Build Coastguard Worker### value as determined from mac_permissions.xml.
12*e4a36f41SAndroid Build Coastguard Worker
13*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all system_linker_exec:file execute_no_trans;
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Worker# Required to read CTS tests data from the shell_data_file location.
16*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all shell_data_file:file r_file_perms;
17*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all shell_data_file:dir r_dir_perms;
18*e4a36f41SAndroid Build Coastguard Worker
19*e4a36f41SAndroid Build Coastguard Worker# allow sdk sandbox to use UDP sockets provided by the system server but not
20*e4a36f41SAndroid Build Coastguard Worker# modify them other than to connect
21*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all system_server:udp_socket {
22*e4a36f41SAndroid Build Coastguard Worker        connect getattr read recvfrom sendto write getopt setopt };
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Worker# allow sandbox to search in sdk system server directory
25*e4a36f41SAndroid Build Coastguard Worker# additionally, for webview to work, getattr has been permitted
26*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all sdk_sandbox_system_data_file:dir { getattr search };
27*e4a36f41SAndroid Build Coastguard Worker# allow sandbox to create files and dirs in sdk data directory
28*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all sdk_sandbox_data_file:dir create_dir_perms;
29*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all sdk_sandbox_data_file:file create_file_perms;
30*e4a36f41SAndroid Build Coastguard Worker
31*e4a36f41SAndroid Build Coastguard Worker# allow apps to pass open fds to the sdk sandbox
32*e4a36f41SAndroid Build Coastguard Workerallow sdk_sandbox_all { app_data_file privapp_data_file }:file { getattr read };
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker###
35*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
36*e4a36f41SAndroid Build Coastguard Worker###
37*e4a36f41SAndroid Build Coastguard Worker
38*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all app_data_file_type:file { execute execute_no_trans };
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker# Receive or send uevent messages.
41*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all domain:netlink_kobject_uevent_socket *;
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# Receive or send generic netlink messages
44*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all domain:netlink_socket *;
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker# Too much leaky information in debugfs. It's a security
47*e4a36f41SAndroid Build Coastguard Worker# best practice to ensure these files aren't readable.
48*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all debugfs_type:file read;
49*e4a36f41SAndroid Build Coastguard Worker
50*e4a36f41SAndroid Build Coastguard Worker# execute gpu_device
51*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all gpu_device:chr_file execute;
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# access files in /sys with the default sysfs label
54*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all sysfs:file *;
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# Avoid reads from generically labeled /proc files
57*e4a36f41SAndroid Build Coastguard Worker# Create a more specific label if needed
58*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all proc:file { no_rw_file_perms no_x_file_perms };
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# Directly access external storage
61*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { sdcard_type media_rw_data_file }:file {open create};
62*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { sdcard_type media_rw_data_file }:dir search;
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker# Avoid reads to proc_net, it contains too much device wide information about
65*e4a36f41SAndroid Build Coastguard Worker# ongoing connections.
66*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all proc_net:file no_rw_file_perms;
67*e4a36f41SAndroid Build Coastguard Worker
68*e4a36f41SAndroid Build Coastguard Worker# SDK sandbox processes have their own storage not related to app_data_file or privapp_data_file
69*e4a36f41SAndroid Build Coastguard Worker# TODO(b/280514080): shell_data_file shouldn't be allowed here
70*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { app_data_file_type -sdk_sandbox_data_file -shell_data_file -radio_data_file }:dir no_rw_file_perms;
71*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { app_data_file_type -sdk_sandbox_data_file -shell_data_file -radio_data_file }:file ~{ getattr read };
72*e4a36f41SAndroid Build Coastguard Worker
73*e4a36f41SAndroid Build Coastguard Worker# SDK sandbox processes don't  have any access to external storage
74*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { media_rw_data_file }:dir no_rw_file_perms;
75*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all { media_rw_data_file }:file no_rw_file_perms;
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Workerneverallow { sdk_sandbox_all } tmpfs:dir no_rw_file_perms;
78*e4a36f41SAndroid Build Coastguard Worker
79*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all hal_drm_service:service_manager find;
80*e4a36f41SAndroid Build Coastguard Worker
81*e4a36f41SAndroid Build Coastguard Worker# Only certain system components should have access to sdk_sandbox_system_data_file
82*e4a36f41SAndroid Build Coastguard Worker# sdk_sandbox only needs search. Restricted in follow up neverallow rule.
83*e4a36f41SAndroid Build Coastguard Workerneverallow {
84*e4a36f41SAndroid Build Coastguard Worker    domain
85*e4a36f41SAndroid Build Coastguard Worker    -init
86*e4a36f41SAndroid Build Coastguard Worker    -installd
87*e4a36f41SAndroid Build Coastguard Worker    -system_server
88*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
89*e4a36f41SAndroid Build Coastguard Worker} sdk_sandbox_system_data_file:dir { relabelfrom };
90*e4a36f41SAndroid Build Coastguard Worker
91*e4a36f41SAndroid Build Coastguard Workerneverallow {
92*e4a36f41SAndroid Build Coastguard Worker    domain
93*e4a36f41SAndroid Build Coastguard Worker    -init
94*e4a36f41SAndroid Build Coastguard Worker    -installd
95*e4a36f41SAndroid Build Coastguard Worker    -sdk_sandbox_all
96*e4a36f41SAndroid Build Coastguard Worker    -system_server
97*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
98*e4a36f41SAndroid Build Coastguard Worker    -zygote
99*e4a36f41SAndroid Build Coastguard Worker} sdk_sandbox_system_data_file:dir { create_dir_perms relabelto };
100*e4a36f41SAndroid Build Coastguard Worker
101*e4a36f41SAndroid Build Coastguard Worker# Only certain system components should have access to sdk_sandbox_all_system_data_file
102*e4a36f41SAndroid Build Coastguard Worker# sdk_sandbox_all only needs search. Restricted in follow up neverallow rule.
103*e4a36f41SAndroid Build Coastguard Workerneverallow {
104*e4a36f41SAndroid Build Coastguard Worker    domain
105*e4a36f41SAndroid Build Coastguard Worker    -init
106*e4a36f41SAndroid Build Coastguard Worker    -installd
107*e4a36f41SAndroid Build Coastguard Worker    -system_server
108*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
109*e4a36f41SAndroid Build Coastguard Worker} sdk_sandbox_system_data_file:dir { relabelfrom };
110*e4a36f41SAndroid Build Coastguard Worker
111*e4a36f41SAndroid Build Coastguard Workerneverallow {
112*e4a36f41SAndroid Build Coastguard Worker    domain
113*e4a36f41SAndroid Build Coastguard Worker    -init
114*e4a36f41SAndroid Build Coastguard Worker    -installd
115*e4a36f41SAndroid Build Coastguard Worker    -sdk_sandbox_all
116*e4a36f41SAndroid Build Coastguard Worker    -system_server
117*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
118*e4a36f41SAndroid Build Coastguard Worker    -zygote
119*e4a36f41SAndroid Build Coastguard Worker} sdk_sandbox_system_data_file:dir { create_dir_perms relabelto };
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# sdk_sandbox_all only needs to traverse through the sdk_sandbox_all_system_data_file
122*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all sdk_sandbox_system_data_file:dir ~{ getattr search };
123*e4a36f41SAndroid Build Coastguard Worker
124*e4a36f41SAndroid Build Coastguard Worker# Only dirs should be created at sdk_sandbox_all_system_data_file level
125*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } sdk_sandbox_system_data_file:file *;
126*e4a36f41SAndroid Build Coastguard Worker
127*e4a36f41SAndroid Build Coastguard Worker# Restrict unix stream sockets for IPC.
128*e4a36f41SAndroid Build Coastguard Workerneverallow sdk_sandbox_all {
129*e4a36f41SAndroid Build Coastguard Worker    domain
130*e4a36f41SAndroid Build Coastguard Worker    -sdk_sandbox_all
131*e4a36f41SAndroid Build Coastguard Worker    -netd
132*e4a36f41SAndroid Build Coastguard Worker    -logd
133*e4a36f41SAndroid Build Coastguard Worker    -adbd
134*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
135*e4a36f41SAndroid Build Coastguard Worker    # needed for profiling
136*e4a36f41SAndroid Build Coastguard Worker    -traced
137*e4a36f41SAndroid Build Coastguard Worker    -traced_perf
138*e4a36f41SAndroid Build Coastguard Worker    -heapprofd
139*e4a36f41SAndroid Build Coastguard Worker    # fallback crash handling for processes that can't exec crash_dump.
140*e4a36f41SAndroid Build Coastguard Worker    -tombstoned
141*e4a36f41SAndroid Build Coastguard Worker    # needed to connect to PRNG seeder daemon.
142*e4a36f41SAndroid Build Coastguard Worker    -prng_seeder
143*e4a36f41SAndroid Build Coastguard Worker}:unix_stream_socket connectto;
144*e4a36f41SAndroid Build Coastguard Workerneverallow {
145*e4a36f41SAndroid Build Coastguard Worker    domain
146*e4a36f41SAndroid Build Coastguard Worker    -adbd
147*e4a36f41SAndroid Build Coastguard Worker    -sdk_sandbox_all
148*e4a36f41SAndroid Build Coastguard Worker} sdk_sandbox_all:unix_stream_socket connectto;
149