blob: beee4f7fb568245aee0c789abd07843ebe556a04 [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
Chad Brubakera782a812017-02-06 10:31:45 -08008define(`all_untrusted_apps',`{ untrusted_app_all untrusted_app_25 untrusted_app ephemeral_app isolated_app }')
Chad Brubaker46e5a062017-01-27 15:53:38 -08009# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080010neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080011
12# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080013neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080014
15# Too much leaky information in debugfs. It's a security
16# best practice to ensure these files aren't readable.
Chad Brubakera782a812017-02-06 10:31:45 -080017neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080018
19# Do not allow untrusted apps to register services.
20# Only trusted components of Android should be registering
21# services.
Chad Brubakera782a812017-02-06 10:31:45 -080022neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080023
24# Do not allow untrusted apps to connect to the property service
25# or set properties. b/10243159
Chad Brubakera782a812017-02-06 10:31:45 -080026neverallow all_untrusted_apps property_socket:sock_file write;
27neverallow all_untrusted_apps init:unix_stream_socket connectto;
28neverallow all_untrusted_apps property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080029
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 Brubakera782a812017-02-06 10:31:45 -080038neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080039
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 Brubakera782a812017-02-06 10:31:45 -080046neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080047
48# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080049neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080050
51# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
52# ioctl permission, or 3. disallow the socket class.
Chad Brubakera782a812017-02-06 10:31:45 -080053neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
54neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
55neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080056 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050057 netlink_tcpdiag_socket netlink_nflog_socket
58 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080059 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 Brubakera782a812017-02-06 10:31:45 -080066neverallow all_untrusted_apps { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
67neverallow all_untrusted_apps { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080068
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 Brubakera782a812017-02-06 10:31:45 -080074neverallow all_untrusted_apps {
Chad Brubaker46e5a062017-01-27 15:53:38 -080075 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 Brubaker46e5a062017-01-27 15:53:38 -080084 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 Brubakera782a812017-02-06 10:31:45 -080091neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -080092
93# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -080094neverallow all_untrusted_apps anr_data_file:file ~{ open append };
95neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -080096
97# Avoid reads from generically labeled /proc files
98# Create a more specific label if needed
Chad Brubakera782a812017-02-06 10:31:45 -080099neverallow all_untrusted_apps proc:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700100
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700101# Avoid all access to kernel configuration
102neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
103
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700104# Do not allow untrusted apps access to preloads data files
105neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700106
107# Locking of files on /system could lead to denial of service attacks
108# against privileged system components
109neverallow all_untrusted_apps system_file:file lock;