Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 1 | ### |
| 2 | ### neverallow rules for untrusted app domains |
| 3 | ### |
| 4 | |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 5 | # Only allow domains in AOSP to use the untrusted_app_all attribute. |
| 6 | neverallow { untrusted_app_all -untrusted_app -untrusted_app_25 } domain:process fork; |
| 7 | |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 8 | define(`all_untrusted_apps',`{ untrusted_app_all untrusted_app_25 untrusted_app ephemeral_app isolated_app }') |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 9 | # Receive or send uevent messages. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 10 | neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 11 | |
| 12 | # Receive or send generic netlink messages |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 13 | neverallow all_untrusted_apps domain:netlink_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 14 | |
| 15 | # Too much leaky information in debugfs. It's a security |
| 16 | # best practice to ensure these files aren't readable. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 17 | neverallow all_untrusted_apps debugfs_type:file read; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 18 | |
| 19 | # Do not allow untrusted apps to register services. |
| 20 | # Only trusted components of Android should be registering |
| 21 | # services. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 22 | neverallow all_untrusted_apps service_manager_type:service_manager add; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 23 | |
| 24 | # Do not allow untrusted apps to connect to the property service |
| 25 | # or set properties. b/10243159 |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 26 | neverallow all_untrusted_apps property_socket:sock_file write; |
| 27 | neverallow all_untrusted_apps init:unix_stream_socket connectto; |
| 28 | neverallow all_untrusted_apps property_type:property_service set; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 29 | |
| 30 | # Do not allow untrusted apps to be assigned mlstrustedsubject. |
| 31 | # This would undermine the per-user isolation model being |
| 32 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 33 | # constraints. As there is no direct way to specify a neverallow |
| 34 | # on attribute assignment, this relies on the fact that fork |
| 35 | # permission only makes sense within a domain (hence should |
| 36 | # never be granted to any other domain within mlstrustedsubject) |
| 37 | # and an untrusted app is allowed fork permission to itself. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 38 | neverallow all_untrusted_apps mlstrustedsubject:process fork; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 39 | |
| 40 | # Do not allow untrusted apps to hard link to any files. |
| 41 | # In particular, if an untrusted app links to other app data |
| 42 | # files, installd will not be able to guarantee the deletion |
| 43 | # of the linked to file. Hard links also contribute to security |
| 44 | # bugs, so we want to ensure untrusted apps never have this |
| 45 | # capability. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 46 | neverallow all_untrusted_apps file_type:file link; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 47 | |
| 48 | # Do not allow untrusted apps to access network MAC address file |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 49 | neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 50 | |
| 51 | # Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the |
| 52 | # ioctl permission, or 3. disallow the socket class. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 53 | neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; |
| 54 | neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl; |
| 55 | neverallow all_untrusted_apps *:{ |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 56 | socket netlink_socket packet_socket key_socket appletalk_socket |
Stephen Smalley | 4921085 | 2017-02-06 14:14:58 -0500 | [diff] [blame] | 57 | netlink_tcpdiag_socket netlink_nflog_socket |
| 58 | netlink_xfrm_socket netlink_audit_socket |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 59 | netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket |
| 60 | netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket |
| 61 | netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket |
| 62 | netlink_rdma_socket netlink_crypto_socket |
| 63 | } *; |
| 64 | |
| 65 | # Do not allow untrusted apps access to /cache |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 66 | neverallow all_untrusted_apps { cache_file cache_recovery_file }:dir ~{ r_dir_perms }; |
| 67 | neverallow all_untrusted_apps { cache_file cache_recovery_file }:file ~{ read getattr }; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 68 | |
| 69 | # Do not allow untrusted apps to create/unlink files outside of its sandbox, |
| 70 | # internal storage or sdcard. |
| 71 | # World accessible data locations allow application to fill the device |
| 72 | # with unaccounted for data. This data will not get removed during |
| 73 | # application un-installation. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 74 | neverallow all_untrusted_apps { |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 75 | fs_type |
| 76 | -fuse # sdcard |
| 77 | -sdcardfs # sdcard |
| 78 | -vfat |
| 79 | file_type |
| 80 | -app_data_file # The apps sandbox itself |
| 81 | -media_rw_data_file # Internal storage. Known that apps can |
| 82 | # leave artfacts here after uninstall. |
| 83 | -user_profile_data_file # Access to profile files |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 84 | userdebug_or_eng(` |
| 85 | -method_trace_data_file # only on ro.debuggable=1 |
| 86 | -coredump_file # userdebug/eng only |
| 87 | ') |
| 88 | }:dir_file_class_set { create unlink }; |
| 89 | |
| 90 | # Do not allow untrusted apps to directly open tun_device |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 91 | neverallow all_untrusted_apps tun_device:chr_file open; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 92 | |
| 93 | # Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553) |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 94 | neverallow all_untrusted_apps anr_data_file:file ~{ open append }; |
| 95 | neverallow all_untrusted_apps anr_data_file:dir ~search; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 96 | |
| 97 | # Avoid reads from generically labeled /proc files |
| 98 | # Create a more specific label if needed |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 99 | neverallow all_untrusted_apps proc:file { no_rw_file_perms no_x_file_perms }; |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 100 | |
Sandeep Patil | 2da9cfd | 2017-04-21 11:25:29 -0700 | [diff] [blame] | 101 | # Avoid all access to kernel configuration |
| 102 | neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms }; |
| 103 | |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 104 | # Do not allow untrusted apps access to preloads data files |
| 105 | neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms; |
Nick Kralevich | 92c44a5 | 2017-03-22 10:35:24 -0700 | [diff] [blame] | 106 | |
| 107 | # Locking of files on /system could lead to denial of service attacks |
| 108 | # against privileged system components |
| 109 | neverallow all_untrusted_apps system_file:file lock; |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame^] | 110 | |
| 111 | # Do not permit access from apps which host arbitrary code to HwBinder services, |
| 112 | # except those considered sufficiently safe for access from such apps. |
| 113 | # The two main reasons for this are: |
| 114 | # 1. HwBinder servers do not perform client authentication because HIDL |
| 115 | # currently does not expose caller UID information and, even if it did, many |
| 116 | # HwBinder services either operate at a level below that of apps (e.g., HALs) |
| 117 | # or must not rely on app identity for authorization. Thus, to be safe, the |
| 118 | # default assumption is that every HwBinder service treats all its clients as |
| 119 | # equally authorized to perform operations offered by the service. |
| 120 | # 2. HAL servers (a subset of HwBinder services) contain code with higher |
| 121 | # incidence rate of security issues than system/core components and have |
| 122 | # access to lower layes of the stack (all the way down to hardware) thus |
| 123 | # increasing opportunities for bypassing the Android security model. |
| 124 | neverallow all_untrusted_apps { |
| 125 | hwservice_manager_type |
| 126 | # Same process services are safe because they by definition run in the process |
| 127 | # of the client and thus have the same access as the client domain in which |
| 128 | # the process runs |
| 129 | -same_process_hwservice |
| 130 | -coredomain_hwservice # neverallows for coredomain HwBinder services are below |
| 131 | -hal_configstore_ISurfaceFlingerConfigs # Designed for use by any domain |
| 132 | # These operations are also offered by surfaceflinger Binder service which |
| 133 | # apps are permitted to access |
| 134 | -hal_graphics_allocator_hwservice |
| 135 | # HwBinder version of mediacodec Binder service which apps were permitted to |
| 136 | # access |
| 137 | -hal_omx_hwservice |
| 138 | }:hwservice_manager find; |
| 139 | # HwBinder services offered by core components (as opposed to vendor components) |
| 140 | # are considered somewhat safer due to point #2 above. |
| 141 | neverallow all_untrusted_apps { |
| 142 | coredomain_hwservice |
| 143 | -same_process_hwservice |
| 144 | -hidl_allocator_hwservice # Designed for use by any domain |
| 145 | -hidl_manager_hwservice # Designed for use by any domain |
| 146 | -hidl_memory_hwservice # Designed for use by any domain |
| 147 | -hidl_token_hwservice # Designed for use by any domain |
| 148 | }:hwservice_manager find; |
| 149 | |
| 150 | # Restrict *Binder access from apps to HAL domains. We can only do this on full |
| 151 | # Treble devices where *Binder communications between apps and HALs are tightly |
| 152 | # restricted. |
| 153 | full_treble_only(` |
| 154 | neverallow all_untrusted_apps { |
| 155 | halserverdomain |
| 156 | -coredomain |
| 157 | -hal_configstore_server |
| 158 | -hal_graphics_allocator_server |
| 159 | -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone |
| 160 | }:binder { call transfer }; |
| 161 | ') |