Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 1 | # only HALs responsible for network hardware should have privileged |
| 2 | # network capabilities |
| 3 | neverallow { |
| 4 | halserverdomain |
| 5 | -hal_bluetooth_server |
Tomasz Wasilczyk | 602b303 | 2019-07-23 17:38:51 -0700 | [diff] [blame] | 6 | -hal_can_controller_server |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 7 | -hal_wifi_server |
Roshan Pius | d7b34a4 | 2017-12-22 15:03:15 -0800 | [diff] [blame] | 8 | -hal_wifi_hostapd_server |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 9 | -hal_wifi_supplicant_server |
Amit Mahajan | 3007344 | 2018-03-12 17:12:09 +0000 | [diff] [blame] | 10 | -hal_telephony_server |
Roshan Pius | 329b0c8 | 2021-10-27 12:41:38 -0700 | [diff] [blame] | 11 | -hal_uwb_server |
| 12 | # TODO(b/196225233): Remove hal_uwb_vendor_server |
Roshan Pius | 37ee61f | 2021-08-24 13:59:07 -0700 | [diff] [blame] | 13 | -hal_uwb_vendor_server |
Chris Weir | 4ac3d74 | 2021-10-05 16:53:52 -0700 | [diff] [blame] | 14 | -hal_nlinterceptor_server |
Benjamin Gordon | 9b2e0cb | 2017-11-09 15:51:26 -0700 | [diff] [blame] | 15 | } self:global_capability_class_set { net_admin net_raw }; |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 16 | |
Jeff Vander Stoep | d75a2c0 | 2017-06-21 12:46:21 -0700 | [diff] [blame] | 17 | # Unless a HAL's job is to communicate over the network, or control network |
| 18 | # hardware, it should not be using network sockets. |
Pavel Maltsev | 8d7f503 | 2018-05-15 14:16:57 -0700 | [diff] [blame] | 19 | # NOTE: HALs for automotive devices have an exemption from this rule because in |
| 20 | # a car it is common to have external modules and HALs need to communicate to |
| 21 | # those modules using network. Using this exemption for non-automotive builds |
| 22 | # will result in CTS failure. |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 23 | neverallow { |
| 24 | halserverdomain |
Pavel Maltsev | 8d7f503 | 2018-05-15 14:16:57 -0700 | [diff] [blame] | 25 | -hal_automotive_socket_exemption |
Tomasz Wasilczyk | 602b303 | 2019-07-23 17:38:51 -0700 | [diff] [blame] | 26 | -hal_can_controller_server |
Jeff Vander Stoep | d75a2c0 | 2017-06-21 12:46:21 -0700 | [diff] [blame] | 27 | -hal_tetheroffload_server |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 28 | -hal_wifi_server |
Roshan Pius | d7b34a4 | 2017-12-22 15:03:15 -0800 | [diff] [blame] | 29 | -hal_wifi_hostapd_server |
Jeff Vander Stoep | f9be765 | 2017-03-13 13:32:51 -0700 | [diff] [blame] | 30 | -hal_wifi_supplicant_server |
Amit Mahajan | 3007344 | 2018-03-12 17:12:09 +0000 | [diff] [blame] | 31 | -hal_telephony_server |
Roshan Pius | 329b0c8 | 2021-10-27 12:41:38 -0700 | [diff] [blame] | 32 | -hal_uwb_server |
| 33 | # TODO(b/196225233): Remove hal_uwb_vendor_server |
Roshan Pius | 37ee61f | 2021-08-24 13:59:07 -0700 | [diff] [blame] | 34 | -hal_uwb_vendor_server |
Chris Weir | 4ac3d74 | 2021-10-05 16:53:52 -0700 | [diff] [blame] | 35 | -hal_nlinterceptor_server |
Yanfei Zhou | 3a739f9 | 2023-07-09 18:13:15 +0530 | [diff] [blame^] | 36 | -hal_bluetooth_server |
Yifan Hong | be04b09 | 2021-06-07 12:37:31 -0700 | [diff] [blame] | 37 | } domain:{ udp_socket rawip_socket } *; |
| 38 | |
| 39 | neverallow { |
| 40 | halserverdomain |
| 41 | -hal_automotive_socket_exemption |
| 42 | -hal_can_controller_server |
| 43 | -hal_tetheroffload_server |
| 44 | -hal_wifi_server |
| 45 | -hal_wifi_hostapd_server |
| 46 | -hal_wifi_supplicant_server |
| 47 | -hal_telephony_server |
Chris Weir | 4ac3d74 | 2021-10-05 16:53:52 -0700 | [diff] [blame] | 48 | -hal_nlinterceptor_server |
Yifan Hong | be04b09 | 2021-06-07 12:37:31 -0700 | [diff] [blame] | 49 | } { |
| 50 | domain |
| 51 | userdebug_or_eng(`-su') |
| 52 | }:tcp_socket *; |
Jeff Vander Stoep | 84b96a6 | 2017-03-20 14:52:58 -0700 | [diff] [blame] | 53 | |
Michael Ayoubi | c3af662 | 2021-06-24 02:02:07 +0000 | [diff] [blame] | 54 | # The UWB HAL is not actually a networking HAL but may need to bring up and down |
| 55 | # interfaces. Restrict it to only these networking operations. |
Roshan Pius | 37ee61f | 2021-08-24 13:59:07 -0700 | [diff] [blame] | 56 | neverallow hal_uwb_vendor_server self:global_capability_class_set { net_raw }; |
Michael Ayoubi | c3af662 | 2021-06-24 02:02:07 +0000 | [diff] [blame] | 57 | |
| 58 | # Subset of socket_class_set likely to be usable for communication or accessible through net_admin. |
| 59 | # udp_socket is required to use interface ioctls. |
Roshan Pius | 37ee61f | 2021-08-24 13:59:07 -0700 | [diff] [blame] | 60 | neverallow hal_uwb_vendor_server domain:{ socket rawip_socket netlink_socket packet_socket key_socket netlink_route_socket netlink_tcpdiag_socket netlink_nflog_socket netlink_xfrm_socket netlink_selinux_socket netlink_audit_socket netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket netlink_netfilter_socket netlink_scsitransport_socket netlink_rdma_socket netlink_crypto_socket qipcrtr_socket xdp_socket } *; |
Michael Ayoubi | c3af662 | 2021-06-24 02:02:07 +0000 | [diff] [blame] | 61 | |
Jeff Vander Stoep | 84b96a6 | 2017-03-20 14:52:58 -0700 | [diff] [blame] | 62 | ### |
| 63 | # HALs are defined as an attribute and so a given domain could hypothetically |
| 64 | # have multiple HALs in it (or even all of them) with the subsequent policy of |
| 65 | # the domain comprised of the union of all the HALs. |
| 66 | # |
| 67 | # This is a problem because |
| 68 | # 1) Security sensitive components should only be accessed by specific HALs. |
| 69 | # 2) hwbinder_call and the restrictions it provides cannot be reasoned about in |
| 70 | # the platform. |
| 71 | # 3) The platform cannot reason about defense in depth if there are |
| 72 | # monolithic domains etc. |
| 73 | # |
| 74 | # As an example, hal_keymaster and hal_gatekeeper can access the TEE and while |
| 75 | # its OK for them to share a process its not OK with them to share processes |
| 76 | # with other hals. |
| 77 | # |
| 78 | # The following neverallow rules, in conjuntion with CTS tests, assert that |
| 79 | # these security principles are adhered to. |
| 80 | # |
| 81 | # Do not allow a hal to exec another process without a domain transition. |
| 82 | # TODO remove exemptions. |
| 83 | neverallow { |
| 84 | halserverdomain |
| 85 | -hal_dumpstate_server |
Amit Mahajan | 3007344 | 2018-03-12 17:12:09 +0000 | [diff] [blame] | 86 | -hal_telephony_server |
Jeff Vander Stoep | 84b96a6 | 2017-03-20 14:52:58 -0700 | [diff] [blame] | 87 | } { file_type fs_type }:file execute_no_trans; |
| 88 | # Do not allow a process other than init to transition into a HAL domain. |
| 89 | neverallow { domain -init } halserverdomain:process transition; |
| 90 | # Only allow transitioning to a domain by running its executable. Do not |
| 91 | # allow transitioning into a HAL domain by use of seclabel in an |
| 92 | # init.*.rc script. |
| 93 | neverallow * halserverdomain:process dyntransition; |