Bram Bonne | b93f26f | 2022-03-15 18:28:02 +0100 | [diff] [blame] | 1 | ### |
| 2 | ### SDK Sandbox process. |
| 3 | ### |
| 4 | ### This file defines the security policy for the sdk sandbox processes. |
| 5 | |
Lokesh Gidra | 1269a17 | 2022-08-01 17:20:38 +0000 | [diff] [blame] | 6 | type sdk_sandbox, domain; |
| 7 | |
| 8 | typeattribute sdk_sandbox coredomain; |
| 9 | |
| 10 | net_domain(sdk_sandbox) |
| 11 | app_domain(sdk_sandbox) |
| 12 | |
Lokesh Gidra | 1269a17 | 2022-08-01 17:20:38 +0000 | [diff] [blame] | 13 | # Write app-specific trace data to the Perfetto traced damon. This requires |
| 14 | # connecting to its producer socket and obtaining a (per-process) tmpfs fd. |
| 15 | perfetto_producer(sdk_sandbox) |
| 16 | |
| 17 | # Allow profiling if the app opts in by being marked profileable/debuggable. |
| 18 | can_profile_heap(sdk_sandbox) |
| 19 | can_profile_perf(sdk_sandbox) |
| 20 | |
| 21 | # allow sdk sandbox to use UDP sockets provided by the system server but not |
| 22 | # modify them other than to connect |
| 23 | allow sdk_sandbox system_server:udp_socket { |
| 24 | connect getattr read recvfrom sendto write getopt setopt }; |
| 25 | |
| 26 | # allow sandbox to search in sdk system server directory |
| 27 | # additionally, for webview to work, getattr has been permitted |
| 28 | allow sdk_sandbox sdk_sandbox_system_data_file:dir { getattr search }; |
| 29 | # allow sandbox to create files and dirs in sdk data directory |
| 30 | allow sdk_sandbox sdk_sandbox_data_file:dir create_dir_perms; |
| 31 | allow sdk_sandbox sdk_sandbox_data_file:file create_file_perms; |
Bram Bonne | b93f26f | 2022-03-15 18:28:02 +0100 | [diff] [blame] | 32 | |
| 33 | ### |
| 34 | ### neverallow rules |
| 35 | ### |
| 36 | |
Bram Bonne | 078b43c | 2022-04-25 13:28:52 +0200 | [diff] [blame] | 37 | neverallow sdk_sandbox { app_data_file privapp_data_file sdk_sandbox_data_file }:file { execute execute_no_trans }; |
Bram Bonne | b93f26f | 2022-03-15 18:28:02 +0100 | [diff] [blame] | 38 | |
| 39 | # Receive or send uevent messages. |
| 40 | neverallow sdk_sandbox domain:netlink_kobject_uevent_socket *; |
| 41 | |
| 42 | # Receive or send generic netlink messages |
| 43 | neverallow sdk_sandbox domain:netlink_socket *; |
| 44 | |
| 45 | # Too much leaky information in debugfs. It's a security |
| 46 | # best practice to ensure these files aren't readable. |
| 47 | neverallow sdk_sandbox debugfs:file read; |
| 48 | |
| 49 | # execute gpu_device |
| 50 | neverallow sdk_sandbox gpu_device:chr_file execute; |
| 51 | |
| 52 | # access files in /sys with the default sysfs label |
| 53 | neverallow sdk_sandbox sysfs:file *; |
| 54 | |
| 55 | # Avoid reads from generically labeled /proc files |
| 56 | # Create a more specific label if needed |
| 57 | neverallow sdk_sandbox proc:file { no_rw_file_perms no_x_file_perms }; |
| 58 | |
| 59 | # Directly access external storage |
| 60 | neverallow sdk_sandbox { sdcard_type media_rw_data_file }:file {open create}; |
| 61 | neverallow sdk_sandbox { sdcard_type media_rw_data_file }:dir search; |
| 62 | |
| 63 | # Avoid reads to proc_net, it contains too much device wide information about |
| 64 | # ongoing connections. |
| 65 | neverallow sdk_sandbox proc_net:file no_rw_file_perms; |
| 66 | |
| 67 | # SDK sandbox processes have their own storage not related to app_data_file or privapp_data_file |
| 68 | neverallow sdk_sandbox { app_data_file privapp_data_file }:dir no_rw_file_perms; |
| 69 | neverallow sdk_sandbox { app_data_file privapp_data_file }:file no_rw_file_perms; |
| 70 | |
| 71 | # SDK sandbox processes don't have any access to external storage |
| 72 | neverallow sdk_sandbox { media_rw_data_file }:dir no_rw_file_perms; |
| 73 | neverallow sdk_sandbox { media_rw_data_file }:file no_rw_file_perms; |
| 74 | |
| 75 | neverallow { sdk_sandbox } tmpfs:dir no_rw_file_perms; |
Bram Bonne | 85dfe31 | 2022-03-23 17:48:48 +0100 | [diff] [blame] | 76 | |
| 77 | neverallow sdk_sandbox hal_drm_service:service_manager find; |
Mohammad Samiul Islam | d2ffd35 | 2022-05-11 21:43:54 +0100 | [diff] [blame] | 78 | |
| 79 | # Only certain system components should have access to sdk_sandbox_system_data_file |
| 80 | # sdk_sandbox only needs search. Restricted in follow up neverallow rule. |
| 81 | neverallow { |
| 82 | domain |
| 83 | -init |
| 84 | -installd |
Sanjana Sunil | 5630163 | 2022-05-20 11:24:32 +0000 | [diff] [blame] | 85 | -system_server |
| 86 | -vold_prepare_subdirs |
| 87 | } sdk_sandbox_system_data_file:dir { relabelfrom }; |
| 88 | |
| 89 | neverallow { |
| 90 | domain |
| 91 | -init |
| 92 | -installd |
Mohammad Samiul Islam | d2ffd35 | 2022-05-11 21:43:54 +0100 | [diff] [blame] | 93 | -sdk_sandbox |
| 94 | -system_server |
| 95 | -vold_prepare_subdirs |
Sanjana Sunil | 5630163 | 2022-05-20 11:24:32 +0000 | [diff] [blame] | 96 | -zygote |
| 97 | } sdk_sandbox_system_data_file:dir { create_dir_perms relabelto }; |
Mohammad Samiul Islam | d2ffd35 | 2022-05-11 21:43:54 +0100 | [diff] [blame] | 98 | |
| 99 | # sdk_sandbox only needs to traverse through the sdk_sandbox_system_data_file |
| 100 | neverallow sdk_sandbox sdk_sandbox_system_data_file:dir ~{ getattr search }; |
| 101 | |
| 102 | # Only dirs should be created at sdk_sandbox_system_data_file level |
| 103 | neverallow { domain -init } sdk_sandbox_system_data_file:file *; |