blob: dfaee86e1ba097f608f1adc9ead164df05920ae5 [file] [log] [blame]
Chad Brubaker46e5a062017-01-27 15:53:38 -08001###
2### neverallow rules for untrusted app domains
3###
4
Jeff Vander Stoepbacb6d72017-02-13 13:33:27 -08005# Only allow domains in AOSP to use the untrusted_app_all attribute.
6neverallow { untrusted_app_all -untrusted_app -untrusted_app_25 } domain:process fork;
7
Nick Kralevichdb5962c2017-04-26 16:14:40 -07008define(`all_untrusted_apps',`{
9 ephemeral_app
10 isolated_app
11 mediaprovider
12 untrusted_app
13 untrusted_app_25
14 untrusted_app_all
15 untrusted_v2_app
16}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080017# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080018neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080019
20# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080021neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080022
23# Too much leaky information in debugfs. It's a security
24# best practice to ensure these files aren't readable.
Chad Brubakera782a812017-02-06 10:31:45 -080025neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080026
27# Do not allow untrusted apps to register services.
28# Only trusted components of Android should be registering
29# services.
Chad Brubakera782a812017-02-06 10:31:45 -080030neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080031
32# Do not allow untrusted apps to connect to the property service
33# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070034neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
35neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
36neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080037
38# Do not allow untrusted apps to be assigned mlstrustedsubject.
39# This would undermine the per-user isolation model being
40# enforced via levelFrom=user in seapp_contexts and the mls
41# constraints. As there is no direct way to specify a neverallow
42# on attribute assignment, this relies on the fact that fork
43# permission only makes sense within a domain (hence should
44# never be granted to any other domain within mlstrustedsubject)
45# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080046neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080047
48# Do not allow untrusted apps to hard link to any files.
49# In particular, if an untrusted app links to other app data
50# files, installd will not be able to guarantee the deletion
51# of the linked to file. Hard links also contribute to security
52# bugs, so we want to ensure untrusted apps never have this
53# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080054neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080055
56# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080057neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080058
59# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
60# ioctl permission, or 3. disallow the socket class.
Chad Brubakera782a812017-02-06 10:31:45 -080061neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
62neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
63neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080064 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050065 netlink_tcpdiag_socket netlink_nflog_socket
66 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080067 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
68 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
69 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
70 netlink_rdma_socket netlink_crypto_socket
71} *;
72
73# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -070074neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
75neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080076
77# Do not allow untrusted apps to create/unlink files outside of its sandbox,
78# internal storage or sdcard.
79# World accessible data locations allow application to fill the device
80# with unaccounted for data. This data will not get removed during
81# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -070082neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -080083 fs_type
84 -fuse # sdcard
85 -sdcardfs # sdcard
86 -vfat
87 file_type
88 -app_data_file # The apps sandbox itself
89 -media_rw_data_file # Internal storage. Known that apps can
90 # leave artfacts here after uninstall.
91 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -080092 userdebug_or_eng(`
93 -method_trace_data_file # only on ro.debuggable=1
94 -coredump_file # userdebug/eng only
95 ')
96}:dir_file_class_set { create unlink };
97
98# Do not allow untrusted apps to directly open tun_device
Chad Brubakera782a812017-02-06 10:31:45 -080099neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800100
101# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800102neverallow all_untrusted_apps anr_data_file:file ~{ open append };
103neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800104
105# Avoid reads from generically labeled /proc files
106# Create a more specific label if needed
Chad Brubakera782a812017-02-06 10:31:45 -0800107neverallow all_untrusted_apps proc:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700108
109# Do not allow untrusted apps access to preloads data files
110neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700111
112# Locking of files on /system could lead to denial of service attacks
113# against privileged system components
114neverallow all_untrusted_apps system_file:file lock;