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 | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 8 | # Receive or send uevent messages. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 9 | neverallow { untrusted_app_all ephemeral_app isolated_app } domain:netlink_kobject_uevent_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 10 | |
| 11 | # Receive or send generic netlink messages |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 12 | neverallow { untrusted_app_all ephemeral_app isolated_app } domain:netlink_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 13 | |
| 14 | # Too much leaky information in debugfs. It's a security |
| 15 | # best practice to ensure these files aren't readable. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 16 | neverallow { untrusted_app_all ephemeral_app isolated_app } debugfs_type:file read; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 17 | |
| 18 | # Do not allow untrusted apps to register services. |
| 19 | # Only trusted components of Android should be registering |
| 20 | # services. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 21 | neverallow { untrusted_app_all ephemeral_app isolated_app } service_manager_type:service_manager add; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 22 | |
| 23 | # Do not allow untrusted apps to connect to the property service |
| 24 | # or set properties. b/10243159 |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 25 | neverallow { untrusted_app_all ephemeral_app isolated_app } property_socket:sock_file write; |
| 26 | neverallow { untrusted_app_all ephemeral_app isolated_app } init:unix_stream_socket connectto; |
| 27 | neverallow { untrusted_app_all ephemeral_app isolated_app } property_type:property_service set; |
| 28 | |
| 29 | # b/34115651 - net.dns* properties read |
| 30 | # This will go away in a future Android release |
| 31 | neverallow { appdomain -untrusted_app_25 } net_dns_prop:file r_file_perms; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 32 | |
| 33 | # Do not allow untrusted apps to be assigned mlstrustedsubject. |
| 34 | # This would undermine the per-user isolation model being |
| 35 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 36 | # constraints. As there is no direct way to specify a neverallow |
| 37 | # on attribute assignment, this relies on the fact that fork |
| 38 | # permission only makes sense within a domain (hence should |
| 39 | # never be granted to any other domain within mlstrustedsubject) |
| 40 | # and an untrusted app is allowed fork permission to itself. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 41 | neverallow { untrusted_app_all ephemeral_app isolated_app } mlstrustedsubject:process fork; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 42 | |
| 43 | # Do not allow untrusted apps to hard link to any files. |
| 44 | # In particular, if an untrusted app links to other app data |
| 45 | # files, installd will not be able to guarantee the deletion |
| 46 | # of the linked to file. Hard links also contribute to security |
| 47 | # bugs, so we want to ensure untrusted apps never have this |
| 48 | # capability. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 49 | neverallow { untrusted_app_all ephemeral_app isolated_app } file_type:file link; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 50 | |
| 51 | # Do not allow untrusted apps to access network MAC address file |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 52 | neverallow { untrusted_app_all ephemeral_app isolated_app } sysfs_mac_address:file no_rw_file_perms; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 53 | |
| 54 | # Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the |
| 55 | # ioctl permission, or 3. disallow the socket class. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 56 | neverallowxperm { untrusted_app_all ephemeral_app isolated_app } domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; |
| 57 | neverallow { untrusted_app_all ephemeral_app isolated_app } *:{ netlink_route_socket netlink_selinux_socket } ioctl; |
| 58 | neverallow { untrusted_app_all ephemeral_app isolated_app } *:{ |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 59 | socket netlink_socket packet_socket key_socket appletalk_socket |
Stephen Smalley | 4921085 | 2017-02-06 14:14:58 -0500 | [diff] [blame] | 60 | netlink_tcpdiag_socket netlink_nflog_socket |
| 61 | netlink_xfrm_socket netlink_audit_socket |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 62 | netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket |
| 63 | netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket |
| 64 | netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket |
| 65 | netlink_rdma_socket netlink_crypto_socket |
| 66 | } *; |
| 67 | |
| 68 | # Do not allow untrusted apps access to /cache |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 69 | neverallow { untrusted_app_all ephemeral_app isolated_app } { cache_file cache_recovery_file }:dir ~{ r_dir_perms }; |
| 70 | neverallow { untrusted_app_all ephemeral_app isolated_app } { cache_file cache_recovery_file }:file ~{ read getattr }; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 71 | |
| 72 | # Do not allow untrusted apps to create/unlink files outside of its sandbox, |
| 73 | # internal storage or sdcard. |
| 74 | # World accessible data locations allow application to fill the device |
| 75 | # with unaccounted for data. This data will not get removed during |
| 76 | # application un-installation. |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 77 | neverallow { untrusted_app_all ephemeral_app isolated_app } { |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 78 | fs_type |
| 79 | -fuse # sdcard |
| 80 | -sdcardfs # sdcard |
| 81 | -vfat |
| 82 | file_type |
| 83 | -app_data_file # The apps sandbox itself |
| 84 | -media_rw_data_file # Internal storage. Known that apps can |
| 85 | # leave artfacts here after uninstall. |
| 86 | -user_profile_data_file # Access to profile files |
| 87 | -user_profile_foreign_dex_data_file # Access to profile files |
| 88 | userdebug_or_eng(` |
| 89 | -method_trace_data_file # only on ro.debuggable=1 |
| 90 | -coredump_file # userdebug/eng only |
| 91 | ') |
| 92 | }:dir_file_class_set { create unlink }; |
| 93 | |
| 94 | # Do not allow untrusted apps to directly open tun_device |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 95 | neverallow { untrusted_app_all ephemeral_app isolated_app } tun_device:chr_file open; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 96 | |
| 97 | # Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553) |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 98 | neverallow { untrusted_app_all ephemeral_app isolated_app } anr_data_file:file ~{ open append }; |
| 99 | neverallow { untrusted_app_all ephemeral_app isolated_app } anr_data_file:dir ~search; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 100 | |
| 101 | # Avoid reads from generically labeled /proc files |
| 102 | # Create a more specific label if needed |
Jeff Vander Stoep | bacb6d7 | 2017-02-13 13:33:27 -0800 | [diff] [blame] | 103 | neverallow { untrusted_app_all ephemeral_app isolated_app } proc:file { no_rw_file_perms no_x_file_perms }; |