Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 1 | ### |
| 2 | ### neverallow rules for untrusted app domains |
| 3 | ### |
| 4 | |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 5 | define(`all_untrusted_apps',`{ |
| 6 | ephemeral_app |
| 7 | isolated_app |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 8 | isolated_app_all |
Charles Chen | 3d4a6b7 | 2023-01-17 08:16:44 +0000 | [diff] [blame] | 9 | isolated_compute_app |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 10 | mediaprovider |
Martijn Coenen | e3f1d5a | 2020-01-30 16:52:45 +0100 | [diff] [blame] | 11 | mediaprovider_app |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 12 | untrusted_app |
| 13 | untrusted_app_25 |
Jeff Vander Stoep | 3aa7ca5 | 2018-04-03 11:22:38 -0700 | [diff] [blame] | 14 | untrusted_app_27 |
Jeff Vander Stoep | 1f7ae8e | 2020-01-20 10:14:48 +0100 | [diff] [blame] | 15 | untrusted_app_29 |
Bram Bonné | ea5460a | 2021-05-12 14:19:24 +0200 | [diff] [blame] | 16 | untrusted_app_30 |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 17 | untrusted_app_all |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 18 | }') |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 19 | # Receive or send uevent messages. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 20 | neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 21 | |
| 22 | # Receive or send generic netlink messages |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 23 | neverallow all_untrusted_apps domain:netlink_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 24 | |
Alan Stokes | a0518b7 | 2020-10-27 11:28:00 +0000 | [diff] [blame] | 25 | # Read or write kernel printk buffer |
| 26 | neverallow all_untrusted_apps kmsg_device:chr_file no_rw_file_perms; |
| 27 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 28 | # Too much leaky information in debugfs. It's a security |
| 29 | # best practice to ensure these files aren't readable. |
Dan Austin | 55d9096 | 2018-11-29 10:37:18 -0800 | [diff] [blame] | 30 | neverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read; |
Jeff Vander Stoep | 0ac2eec | 2019-02-04 10:07:15 -0800 | [diff] [blame] | 31 | neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_file } read; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 32 | |
| 33 | # Do not allow untrusted apps to register services. |
| 34 | # Only trusted components of Android should be registering |
| 35 | # services. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 36 | neverallow all_untrusted_apps service_manager_type:service_manager add; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 37 | |
Alex Klyubin | 0065783 | 2017-04-25 09:27:54 -0700 | [diff] [blame] | 38 | # Do not allow untrusted apps to use VendorBinder |
| 39 | neverallow all_untrusted_apps vndbinder_device:chr_file *; |
| 40 | neverallow all_untrusted_apps vndservice_manager_type:service_manager *; |
| 41 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 42 | # Do not allow untrusted apps to connect to the property service |
| 43 | # or set properties. b/10243159 |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 44 | neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write; |
| 45 | neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto; |
| 46 | neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 47 | |
Nick Kralevich | f04db5b | 2024-09-11 14:15:44 -0700 | [diff] [blame] | 48 | # Do not allow untrusted apps to modify temporarily staged APKs. |
| 49 | neverallow all_untrusted_apps { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *; |
| 50 | neverallow all_untrusted_apps { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read map }; |
| 51 | |
Jeff Vander Stoep | 28903d9 | 2019-10-15 21:00:22 +0200 | [diff] [blame] | 52 | # net.dns properties are not a public API. Disallow untrusted apps from reading this property. |
| 53 | neverallow { all_untrusted_apps } net_dns_prop:file read; |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 54 | |
Nazanin | d65a7bf | 2021-04-29 21:52:42 -0700 | [diff] [blame] | 55 | # radio_cdma_ecm_prop properties are not a public API. Disallow untrusted apps from reading this property. |
| 56 | neverallow { all_untrusted_apps } radio_cdma_ecm_prop:file read; |
| 57 | |
Nick Kralevich | fb66c6f | 2019-01-11 09:37:46 -0800 | [diff] [blame] | 58 | # Shared libraries created by trusted components within an app home |
| 59 | # directory can be dlopen()ed. To maintain the W^X property, these files |
Nick Kralevich | 0eb0a16 | 2018-12-12 09:06:05 -0800 | [diff] [blame] | 60 | # must never be writable to the app. |
Nick Kralevich | fb66c6f | 2019-01-11 09:37:46 -0800 | [diff] [blame] | 61 | neverallow all_untrusted_apps app_exec_data_file:file |
Nick Kralevich | 0eb0a16 | 2018-12-12 09:06:05 -0800 | [diff] [blame] | 62 | { append create link relabelfrom relabelto rename setattr write }; |
| 63 | |
Nick Kralevich | 65a89c1 | 2018-12-21 10:03:50 -0800 | [diff] [blame] | 64 | # Block calling execve() on files in an apps home directory. |
Yabin Cui | 5dc2c8c | 2018-11-02 11:12:43 -0700 | [diff] [blame] | 65 | # This is a W^X violation (loading executable code from a writable |
| 66 | # home directory). For compatibility, allow for targetApi <= 28. |
| 67 | # b/112357170 |
| 68 | neverallow { |
| 69 | all_untrusted_apps |
| 70 | -untrusted_app_25 |
| 71 | -untrusted_app_27 |
Yabin Cui | ffa2b61 | 2018-11-02 14:34:06 -0700 | [diff] [blame] | 72 | -runas_app |
Yabin Cui | 5dc2c8c | 2018-11-02 11:12:43 -0700 | [diff] [blame] | 73 | } { app_data_file privapp_data_file }:file execute_no_trans; |
| 74 | |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 75 | is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, ` |
| 76 | # block apps from executing files in their storage areas |
| 77 | # this is a stronger and more desirable guarantee than blocking execute_no_trans, but |
| 78 | # execute cannot be blocked on all of app_data_file without causing |
| 79 | # backwards compatibility issues (see b/237289679) |
| 80 | neverallow appdomain storage_area_content_file:file execute; |
| 81 | ') |
| 82 | |
| 83 | is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, ` |
| 84 | # dont allow apps to modify their own directories of storage areas |
| 85 | neverallow appdomain storage_area_app_dir:dir_file_class_set { |
| 86 | create write setattr relabelfrom relabelto append unlink link rename |
| 87 | }; |
| 88 | ') |
| 89 | |
David Brazdil | 535c5d2 | 2018-11-19 23:02:49 +0000 | [diff] [blame] | 90 | # Do not allow untrusted apps to invoke dex2oat. This was historically required |
| 91 | # by ART for compiling secondary dex files but has been removed in Q. |
| 92 | # Exempt legacy apps (targetApi<=28) for compatibility. |
| 93 | neverallow { |
| 94 | all_untrusted_apps |
| 95 | -untrusted_app_25 |
| 96 | -untrusted_app_27 |
| 97 | } dex2oat_exec:file no_x_file_perms; |
| 98 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 99 | # Do not allow untrusted apps to be assigned mlstrustedsubject. |
| 100 | # This would undermine the per-user isolation model being |
| 101 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 102 | # constraints. As there is no direct way to specify a neverallow |
| 103 | # on attribute assignment, this relies on the fact that fork |
| 104 | # permission only makes sense within a domain (hence should |
| 105 | # never be granted to any other domain within mlstrustedsubject) |
| 106 | # and an untrusted app is allowed fork permission to itself. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 107 | neverallow all_untrusted_apps mlstrustedsubject:process fork; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 108 | |
| 109 | # Do not allow untrusted apps to hard link to any files. |
| 110 | # In particular, if an untrusted app links to other app data |
| 111 | # files, installd will not be able to guarantee the deletion |
| 112 | # of the linked to file. Hard links also contribute to security |
| 113 | # bugs, so we want to ensure untrusted apps never have this |
| 114 | # capability. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 115 | neverallow all_untrusted_apps file_type:file link; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 116 | |
| 117 | # Do not allow untrusted apps to access network MAC address file |
Maciej Żenczykowski | 804d99a | 2019-07-18 00:04:54 -0700 | [diff] [blame] | 118 | neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 119 | |
Jeff Vander Stoep | 06cef4f | 2017-10-04 13:12:25 -0700 | [diff] [blame] | 120 | # Do not allow any write access to files in /sys |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 121 | neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms }; |
| 122 | |
| 123 | # Apps may never access the default sysfs label. |
| 124 | neverallow all_untrusted_apps sysfs:file no_rw_file_perms; |
Jeff Vander Stoep | 06cef4f | 2017-10-04 13:12:25 -0700 | [diff] [blame] | 125 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 126 | # Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the |
| 127 | # ioctl permission, or 3. disallow the socket class. |
Jeff Vander Stoep | 0597ade | 2018-06-21 16:57:58 -0700 | [diff] [blame] | 128 | neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 129 | neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl; |
| 130 | neverallow all_untrusted_apps *:{ |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 131 | socket netlink_socket packet_socket key_socket appletalk_socket |
Stephen Smalley | 4921085 | 2017-02-06 14:14:58 -0500 | [diff] [blame] | 132 | netlink_tcpdiag_socket netlink_nflog_socket |
| 133 | netlink_xfrm_socket netlink_audit_socket |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 134 | netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket |
| 135 | netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket |
| 136 | netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket |
Jeff Vander Stoep | 0597ade | 2018-06-21 16:57:58 -0700 | [diff] [blame] | 137 | netlink_rdma_socket netlink_crypto_socket sctp_socket |
| 138 | ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket |
| 139 | atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket |
| 140 | bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 141 | alg_socket nfc_socket kcm_socket qipcrtr_socket smc_socket xdp_socket |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 142 | } *; |
| 143 | |
Alan Stokes | f96cd65 | 2021-09-07 12:25:38 +0100 | [diff] [blame] | 144 | # Apps can read/write an already open vsock (e.g. created by |
| 145 | # virtualizationservice) but nothing more than that (e.g. creating a |
| 146 | # new vsock, etc.) |
Alice Wang | 40718f4 | 2022-08-30 14:10:48 +0000 | [diff] [blame] | 147 | neverallow all_untrusted_apps *:vsock_socket ~{ getattr getopt read write }; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 148 | |
Jeff Vander Stoep | 1f7ae8e | 2020-01-20 10:14:48 +0100 | [diff] [blame] | 149 | # Disallow sending RTM_GETLINK messages on netlink sockets. |
Bram Bonné | a4433b4 | 2021-04-30 15:48:09 +0200 | [diff] [blame] | 150 | neverallow all_untrusted_apps domain:netlink_route_socket { bind nlmsg_readpriv }; |
Bram Bonne | af609b2 | 2022-05-17 14:22:02 +0200 | [diff] [blame] | 151 | neverallow priv_app domain:netlink_route_socket { bind nlmsg_readpriv }; |
Jeff Vander Stoep | 1f7ae8e | 2020-01-20 10:14:48 +0100 | [diff] [blame] | 152 | |
Bram Bonné | ea5460a | 2021-05-12 14:19:24 +0200 | [diff] [blame] | 153 | # Disallow sending RTM_GETNEIGH{TBL} messages on netlink sockets. |
| 154 | neverallow { |
| 155 | all_untrusted_apps |
| 156 | -untrusted_app_25 |
| 157 | -untrusted_app_27 |
| 158 | -untrusted_app_29 |
| 159 | -untrusted_app_30 |
| 160 | } domain:netlink_route_socket nlmsg_getneigh; |
| 161 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 162 | # Do not allow untrusted apps access to /cache |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 163 | neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms }; |
| 164 | neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr }; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 165 | |
| 166 | # Do not allow untrusted apps to create/unlink files outside of its sandbox, |
| 167 | # internal storage or sdcard. |
| 168 | # World accessible data locations allow application to fill the device |
| 169 | # with unaccounted for data. This data will not get removed during |
| 170 | # application un-installation. |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 171 | neverallow { all_untrusted_apps -mediaprovider } { |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 172 | fs_type |
Jeff Sharkey | 000cafc | 2018-03-30 12:22:54 -0600 | [diff] [blame] | 173 | -sdcard_type |
Thiébaud Weksteen | 9ec5327 | 2021-06-23 10:21:49 +0200 | [diff] [blame] | 174 | -fuse |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 175 | file_type |
| 176 | -app_data_file # The apps sandbox itself |
Nick Kralevich | 23c9d91 | 2018-08-02 15:54:23 -0700 | [diff] [blame] | 177 | -privapp_data_file |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 178 | is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `-storage_area_content_file') |
Nick Kralevich | fb66c6f | 2019-01-11 09:37:46 -0800 | [diff] [blame] | 179 | -app_exec_data_file # stored within the app sandbox directory |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 180 | -media_rw_data_file # Internal storage. Known that apps can |
| 181 | # leave artfacts here after uninstall. |
| 182 | -user_profile_data_file # Access to profile files |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 183 | userdebug_or_eng(` |
| 184 | -method_trace_data_file # only on ro.debuggable=1 |
| 185 | -coredump_file # userdebug/eng only |
| 186 | ') |
| 187 | }:dir_file_class_set { create unlink }; |
| 188 | |
Martijn Coenen | e3f1d5a | 2020-01-30 16:52:45 +0100 | [diff] [blame] | 189 | # No untrusted component except mediaprovider_app should be touching /dev/fuse |
| 190 | neverallow { all_untrusted_apps -mediaprovider_app } fuse_device:chr_file *; |
Nick Kralevich | 45766d4 | 2017-04-26 11:40:48 -0700 | [diff] [blame] | 191 | |
Nick Kralevich | 3b2df19 | 2018-11-15 06:14:07 -0800 | [diff] [blame] | 192 | # Do not allow untrusted apps to directly open the tun_device |
| 193 | neverallow all_untrusted_apps tun_device:chr_file open; |
| 194 | # The tun_device ioctls below are not allowed, to prove equivalence |
| 195 | # to the kernel patch at |
Nick Kralevich | 619c1ef | 2018-10-30 20:12:41 -0700 | [diff] [blame] | 196 | # https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21 |
Maciej Żenczykowski | e346fbc | 2020-07-07 17:39:22 -0700 | [diff] [blame] | 197 | neverallowxperm all_untrusted_apps tun_device:chr_file ioctl ~{ FIOCLEX FIONCLEX TUNGETIFF }; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 198 | |
| 199 | # Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553) |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 200 | neverallow all_untrusted_apps anr_data_file:file ~{ open append }; |
| 201 | neverallow all_untrusted_apps anr_data_file:dir ~search; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 202 | |
| 203 | # Avoid reads from generically labeled /proc files |
| 204 | # Create a more specific label if needed |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 205 | neverallow all_untrusted_apps { |
| 206 | proc |
Tri Vo | 464f59a | 2017-10-06 10:20:53 -0700 | [diff] [blame] | 207 | proc_asound |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 208 | proc_kmsg |
| 209 | proc_loadavg |
| 210 | proc_mounts |
| 211 | proc_pagetypeinfo |
Mark Salyzyn | d6eaed8 | 2018-06-14 07:34:19 -0700 | [diff] [blame] | 212 | proc_slabinfo |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 213 | proc_stat |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 214 | proc_swaps |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 215 | proc_uptime |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 216 | proc_version |
| 217 | proc_vmallocinfo |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 218 | proc_vmstat |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 219 | }:file { no_rw_file_perms no_x_file_perms }; |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 220 | |
Martijn Coenen | fd54803 | 2020-02-19 17:10:43 +0100 | [diff] [blame] | 221 | # /proc/filesystems is accessible to mediaprovider_app only since it handles |
| 222 | # external storage |
| 223 | neverallow { all_untrusted_apps - mediaprovider_app } proc_filesystems:file { no_rw_file_perms no_x_file_perms }; |
| 224 | |
Sandeep Patil | 2da9cfd | 2017-04-21 11:25:29 -0700 | [diff] [blame] | 225 | # Avoid all access to kernel configuration |
| 226 | neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms }; |
| 227 | |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 228 | # Do not allow untrusted apps access to preloads data files |
| 229 | neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms; |
Nick Kralevich | 92c44a5 | 2017-03-22 10:35:24 -0700 | [diff] [blame] | 230 | |
| 231 | # Locking of files on /system could lead to denial of service attacks |
| 232 | # against privileged system components |
| 233 | neverallow all_untrusted_apps system_file:file lock; |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 234 | |
Alex Klyubin | 5c5b626 | 2017-04-24 15:09:19 -0700 | [diff] [blame] | 235 | # Do not permit untrusted apps to perform actions on HwBinder service_manager |
| 236 | # other than find actions for services listed below |
| 237 | neverallow all_untrusted_apps *:hwservice_manager ~find; |
| 238 | |
Steven Moreland | a43e26e | 2020-10-21 21:47:00 +0000 | [diff] [blame] | 239 | # Do not permit access from apps which host arbitrary code to the protected services |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 240 | # The two main reasons for this are: |
Steven Moreland | a43e26e | 2020-10-21 21:47:00 +0000 | [diff] [blame] | 241 | # 1. Protected HwBinder servers do not perform client authentication because |
| 242 | # vendor code does not have a way to understand apps or their relation to |
| 243 | # caller UID information and, even if it did, those services either operate |
| 244 | # at a level below that of apps (e.g., HALs) or must not rely on app identity |
| 245 | # for authorization. Thus, to be safe, the default assumption for all added |
| 246 | # vendor services is that they treat all their clients as equally authorized |
| 247 | # to perform operations offered by the service. |
| 248 | # 2. HAL servers contain code with higher incidence rate of security issues |
| 249 | # than system/core components and have access to lower layes of the stack |
| 250 | # (all the way down to hardware) thus increasing opportunities for bypassing |
| 251 | # the Android security model. |
Jiyong Park | e95c704 | 2019-08-22 00:04:50 +0900 | [diff] [blame] | 252 | neverallow all_untrusted_apps protected_hwservice:hwservice_manager find; |
Steven Moreland | a43e26e | 2020-10-21 21:47:00 +0000 | [diff] [blame] | 253 | neverallow all_untrusted_apps protected_service:service_manager find; |
Steven Moreland | b75b047 | 2019-08-20 22:42:58 +0000 | [diff] [blame] | 254 | |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 255 | # SELinux is not an API for untrusted apps to use |
| 256 | neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms; |
| 257 | |
Jeff Vander Stoep | ff511cb | 2018-09-07 07:39:28 -0700 | [diff] [blame] | 258 | # Access to /proc/tty/drivers, to allow apps to determine if they |
| 259 | # are running in an emulated environment. |
| 260 | # b/33214085 b/33814662 b/33791054 b/33211769 |
| 261 | # https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java |
| 262 | # This will go away in a future Android release |
| 263 | neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms; |
| 264 | neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms; |
Tri Vo | f55c989 | 2018-10-10 22:48:15 +0000 | [diff] [blame] | 265 | |
| 266 | # Untrusted apps are not allowed to use cgroups. |
| 267 | neverallow all_untrusted_apps cgroup:file *; |
Marco Ballesio | aa4ce95 | 2021-02-11 15:18:11 -0800 | [diff] [blame] | 268 | neverallow all_untrusted_apps cgroup_v2:file *; |
Tri Vo | 73d0a67 | 2019-01-27 13:39:19 -0800 | [diff] [blame] | 269 | |
Tri Vo | 8eff3e2 | 2019-04-11 15:23:24 -0700 | [diff] [blame] | 270 | # /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps |
| 271 | # must not use it. |
| 272 | neverallow { |
| 273 | all_untrusted_apps |
| 274 | -untrusted_app_25 |
| 275 | -untrusted_app_27 |
| 276 | } mnt_sdcard_file:lnk_file *; |
Jeff Vander Stoep | 2aa8042 | 2020-05-13 14:40:49 +0200 | [diff] [blame] | 277 | |
| 278 | # Only privileged apps may find the incident service |
| 279 | neverallow all_untrusted_apps incident_service:service_manager find; |
Alessandra Loro | d0e108f | 2022-07-14 11:52:21 +0000 | [diff] [blame] | 280 | |
Tej Singh | 000b251 | 2024-02-13 23:27:00 -0800 | [diff] [blame] | 281 | # Only privileged apps may find stats service |
| 282 | neverallow all_untrusted_apps stats_service:service_manager find; |
| 283 | |
Alessandra Loro | 8a7dcb5 | 2022-08-18 13:09:36 +0000 | [diff] [blame] | 284 | # Do not allow untrusted app to read hidden system proprerties. |
| 285 | # We do not include in the exclusions other normally untrusted applications such as mediaprovider |
| 286 | # due to the specific logging use cases. |
Alessandra Loro | d0e108f | 2022-07-14 11:52:21 +0000 | [diff] [blame] | 287 | # Context: b/193912100 |
| 288 | neverallow { |
Alessandra Loro | 24d90e7 | 2022-11-18 14:09:41 +0000 | [diff] [blame] | 289 | all_untrusted_apps |
| 290 | -mediaprovider |
| 291 | -mediaprovider_app |
Alessandra Loro | d0e108f | 2022-07-14 11:52:21 +0000 | [diff] [blame] | 292 | } { userdebug_or_eng_prop }:file read; |
Yuyang Huang | cfdea5f | 2023-01-18 16:52:43 +0900 | [diff] [blame] | 293 | |
Yuyang Huang | cfdea5f | 2023-01-18 16:52:43 +0900 | [diff] [blame] | 294 | # Do not allow untrusted app to access /dev/socket/mdnsd since U. The socket is |
| 295 | # used to communicate to the mdnsd responder. The mdnsd responder will be |
| 296 | # replaced by a java implementation which is integrated into the system server. |
| 297 | # For untrusted apps running with API level 33-, they still have access to |
| 298 | # /dev/socket/mdnsd for backward compatibility. |
| 299 | neverallow { |
| 300 | all_untrusted_apps |
| 301 | -untrusted_app_25 |
| 302 | -untrusted_app_27 |
| 303 | -untrusted_app_29 |
| 304 | -untrusted_app_30 |
| 305 | -untrusted_app_32 |
| 306 | } mdnsd_socket:sock_file write; |
| 307 | neverallow { |
| 308 | all_untrusted_apps |
| 309 | -untrusted_app_25 |
| 310 | -untrusted_app_27 |
| 311 | -untrusted_app_29 |
| 312 | -untrusted_app_30 |
| 313 | -untrusted_app_32 |
| 314 | } mdnsd:unix_stream_socket connectto; |
Gil Cukierman | 214294c | 2022-11-14 17:06:36 -0500 | [diff] [blame] | 315 | |
| 316 | # Do not allow untrusted apps to use anonymous inodes. At the moment, |
| 317 | # type transitions are the only way to distinguish between different |
| 318 | # anon_inode usages like userfaultfd and io_uring. This prevents us from |
| 319 | # creating a more fine-grained neverallow policy for each anon_inode usage. |
| 320 | neverallow all_untrusted_apps domain:anon_inode *; |
Daniel Norman | 4245d04 | 2023-11-30 23:28:04 +0000 | [diff] [blame] | 321 | |
| 322 | # Do not allow untrusted app access to hidraw devices. |
| 323 | neverallow all_untrusted_apps hidraw_device:chr_file *; |