xref: /aosp_15_r20/system/sepolicy/private/hal_neverallows.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# only HALs responsible for network hardware should have privileged
2*e4a36f41SAndroid Build Coastguard Worker# network capabilities
3*e4a36f41SAndroid Build Coastguard Workerneverallow {
4*e4a36f41SAndroid Build Coastguard Worker  halserverdomain
5*e4a36f41SAndroid Build Coastguard Worker  -hal_bluetooth_server
6*e4a36f41SAndroid Build Coastguard Worker  -hal_can_controller_server
7*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_server
8*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_hostapd_server
9*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_supplicant_server
10*e4a36f41SAndroid Build Coastguard Worker  -hal_telephony_server
11*e4a36f41SAndroid Build Coastguard Worker  -hal_uwb_server
12*e4a36f41SAndroid Build Coastguard Worker  # TODO(b/196225233): Remove hal_uwb_vendor_server
13*e4a36f41SAndroid Build Coastguard Worker  -hal_uwb_vendor_server
14*e4a36f41SAndroid Build Coastguard Worker  -hal_nlinterceptor_server
15*e4a36f41SAndroid Build Coastguard Worker  -hal_tv_tuner_server
16*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set { net_admin net_raw };
17*e4a36f41SAndroid Build Coastguard Worker
18*e4a36f41SAndroid Build Coastguard Worker# Unless a HAL's job is to communicate over the network, or control network
19*e4a36f41SAndroid Build Coastguard Worker# hardware, it should not be using network sockets.
20*e4a36f41SAndroid Build Coastguard Worker# NOTE: HALs for automotive devices have an exemption from this rule because in
21*e4a36f41SAndroid Build Coastguard Worker# a car it is common to have external modules and HALs need to communicate to
22*e4a36f41SAndroid Build Coastguard Worker# those modules using network.  Using this exemption for non-automotive builds
23*e4a36f41SAndroid Build Coastguard Worker# will result in CTS failure.
24*e4a36f41SAndroid Build Coastguard Workerneverallow {
25*e4a36f41SAndroid Build Coastguard Worker  halserverdomain
26*e4a36f41SAndroid Build Coastguard Worker  -hal_automotive_socket_exemption
27*e4a36f41SAndroid Build Coastguard Worker  -hal_can_controller_server
28*e4a36f41SAndroid Build Coastguard Worker  -hal_tetheroffload_server
29*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_server
30*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_hostapd_server
31*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_supplicant_server
32*e4a36f41SAndroid Build Coastguard Worker  -hal_telephony_server
33*e4a36f41SAndroid Build Coastguard Worker  -hal_uwb_server
34*e4a36f41SAndroid Build Coastguard Worker  # TODO(b/196225233): Remove hal_uwb_vendor_server
35*e4a36f41SAndroid Build Coastguard Worker  -hal_uwb_vendor_server
36*e4a36f41SAndroid Build Coastguard Worker  -hal_nlinterceptor_server
37*e4a36f41SAndroid Build Coastguard Worker  -hal_bluetooth_server
38*e4a36f41SAndroid Build Coastguard Worker  -hal_tv_tuner_server
39*e4a36f41SAndroid Build Coastguard Worker} domain:{ udp_socket rawip_socket } *;
40*e4a36f41SAndroid Build Coastguard Worker
41*e4a36f41SAndroid Build Coastguard Workerneverallow {
42*e4a36f41SAndroid Build Coastguard Worker  halserverdomain
43*e4a36f41SAndroid Build Coastguard Worker  -hal_automotive_socket_exemption
44*e4a36f41SAndroid Build Coastguard Worker  -hal_can_controller_server
45*e4a36f41SAndroid Build Coastguard Worker  -hal_tetheroffload_server
46*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_server
47*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_hostapd_server
48*e4a36f41SAndroid Build Coastguard Worker  -hal_wifi_supplicant_server
49*e4a36f41SAndroid Build Coastguard Worker  -hal_telephony_server
50*e4a36f41SAndroid Build Coastguard Worker  -hal_nlinterceptor_server
51*e4a36f41SAndroid Build Coastguard Worker  -hal_bluetooth_server
52*e4a36f41SAndroid Build Coastguard Worker  -hal_tv_tuner_server
53*e4a36f41SAndroid Build Coastguard Worker} {
54*e4a36f41SAndroid Build Coastguard Worker  domain
55*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-su')
56*e4a36f41SAndroid Build Coastguard Worker}:tcp_socket *;
57*e4a36f41SAndroid Build Coastguard Worker
58*e4a36f41SAndroid Build Coastguard Worker# The UWB HAL is not actually a networking HAL but may need to bring up and down
59*e4a36f41SAndroid Build Coastguard Worker# interfaces. Restrict it to only these networking operations.
60*e4a36f41SAndroid Build Coastguard Workerneverallow hal_uwb_vendor_server self:global_capability_class_set { net_raw };
61*e4a36f41SAndroid Build Coastguard Worker
62*e4a36f41SAndroid Build Coastguard Worker# Subset of socket_class_set likely to be usable for communication or accessible through net_admin.
63*e4a36f41SAndroid Build Coastguard Worker# udp_socket is required to use interface ioctls.
64*e4a36f41SAndroid Build Coastguard Workerneverallow 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 } *;
65*e4a36f41SAndroid Build Coastguard Worker
66*e4a36f41SAndroid Build Coastguard Worker###
67*e4a36f41SAndroid Build Coastguard Worker# HALs are defined as an attribute and so a given domain could hypothetically
68*e4a36f41SAndroid Build Coastguard Worker# have multiple HALs in it (or even all of them) with the subsequent policy of
69*e4a36f41SAndroid Build Coastguard Worker# the domain comprised of the union of all the HALs.
70*e4a36f41SAndroid Build Coastguard Worker#
71*e4a36f41SAndroid Build Coastguard Worker# This is a problem because
72*e4a36f41SAndroid Build Coastguard Worker# 1) Security sensitive components should only be accessed by specific HALs.
73*e4a36f41SAndroid Build Coastguard Worker# 2) hwbinder_call and the restrictions it provides cannot be reasoned about in
74*e4a36f41SAndroid Build Coastguard Worker#    the platform.
75*e4a36f41SAndroid Build Coastguard Worker# 3) The platform cannot reason about defense in depth if there are
76*e4a36f41SAndroid Build Coastguard Worker#    monolithic domains etc.
77*e4a36f41SAndroid Build Coastguard Worker#
78*e4a36f41SAndroid Build Coastguard Worker# As an example, hal_keymaster and hal_gatekeeper can access the TEE and while
79*e4a36f41SAndroid Build Coastguard Worker# its OK for them to share a process its not OK with them to share processes
80*e4a36f41SAndroid Build Coastguard Worker# with other hals.
81*e4a36f41SAndroid Build Coastguard Worker#
82*e4a36f41SAndroid Build Coastguard Worker# The following neverallow rules, in conjuntion with CTS tests, assert that
83*e4a36f41SAndroid Build Coastguard Worker# these security principles are adhered to.
84*e4a36f41SAndroid Build Coastguard Worker#
85*e4a36f41SAndroid Build Coastguard Worker# Do not allow a hal to exec another process without a domain transition.
86*e4a36f41SAndroid Build Coastguard Worker# TODO remove exemptions.
87*e4a36f41SAndroid Build Coastguard Workerneverallow {
88*e4a36f41SAndroid Build Coastguard Worker  halserverdomain
89*e4a36f41SAndroid Build Coastguard Worker  -hal_dumpstate_server
90*e4a36f41SAndroid Build Coastguard Worker  -hal_telephony_server
91*e4a36f41SAndroid Build Coastguard Worker} {
92*e4a36f41SAndroid Build Coastguard Worker  file_type
93*e4a36f41SAndroid Build Coastguard Worker  fs_type
94*e4a36f41SAndroid Build Coastguard Worker  # May invoke shell commands via /system/bin/sh
95*e4a36f41SAndroid Build Coastguard Worker  -shell_exec
96*e4a36f41SAndroid Build Coastguard Worker  -toolbox_exec
97*e4a36f41SAndroid Build Coastguard Worker}:file execute_no_trans;
98*e4a36f41SAndroid Build Coastguard Worker# Do not allow a process other than init to transition into a HAL domain.
99*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } halserverdomain:process transition;
100*e4a36f41SAndroid Build Coastguard Worker# Only allow transitioning to a domain by running its executable. Do not
101*e4a36f41SAndroid Build Coastguard Worker# allow transitioning into a HAL domain by use of seclabel in an
102*e4a36f41SAndroid Build Coastguard Worker# init.*.rc script.
103*e4a36f41SAndroid Build Coastguard Workerneverallow * halserverdomain:process dyntransition;
104