Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 19 | import static android.net.BpfNetMapsConstants.CONFIGURATION_MAP_PATH; |
| 20 | import static android.net.BpfNetMapsConstants.COOKIE_TAG_MAP_PATH; |
| 21 | import static android.net.BpfNetMapsConstants.CURRENT_STATS_MAP_CONFIGURATION_KEY; |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 22 | import static android.net.BpfNetMapsConstants.DATA_SAVER_DISABLED; |
| 23 | import static android.net.BpfNetMapsConstants.DATA_SAVER_ENABLED; |
| 24 | import static android.net.BpfNetMapsConstants.DATA_SAVER_ENABLED_KEY; |
| 25 | import static android.net.BpfNetMapsConstants.DATA_SAVER_ENABLED_MAP_PATH; |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 26 | import static android.net.BpfNetMapsConstants.HAPPY_BOX_MATCH; |
| 27 | import static android.net.BpfNetMapsConstants.IIF_MATCH; |
| 28 | import static android.net.BpfNetMapsConstants.LOCKDOWN_VPN_MATCH; |
| 29 | import static android.net.BpfNetMapsConstants.PENALTY_BOX_MATCH; |
| 30 | import static android.net.BpfNetMapsConstants.UID_OWNER_MAP_PATH; |
| 31 | import static android.net.BpfNetMapsConstants.UID_PERMISSION_MAP_PATH; |
| 32 | import static android.net.BpfNetMapsConstants.UID_RULES_CONFIGURATION_KEY; |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 33 | import static android.net.BpfNetMapsUtils.PRE_T; |
Junyu Lai | 29b7b63 | 2023-08-23 17:35:17 +0800 | [diff] [blame] | 34 | import static android.net.BpfNetMapsUtils.getMatchByFirewallChain; |
| 35 | import static android.net.BpfNetMapsUtils.matchToString; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 36 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE; |
| 37 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY; |
| 38 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1; |
| 39 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2; |
| 40 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3; |
| 41 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE; |
| 42 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED; |
| 43 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY; |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 44 | import static android.net.ConnectivityManager.FIREWALL_RULE_ALLOW; |
| 45 | import static android.net.ConnectivityManager.FIREWALL_RULE_DENY; |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 46 | import static android.net.INetd.PERMISSION_INTERNET; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 47 | import static android.net.INetd.PERMISSION_NONE; |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 48 | import static android.net.INetd.PERMISSION_UNINSTALLED; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 49 | import static android.net.INetd.PERMISSION_UPDATE_DEVICE_STATS; |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 50 | import static android.system.OsConstants.EINVAL; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 51 | import static android.system.OsConstants.ENODEV; |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 52 | import static android.system.OsConstants.ENOENT; |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 53 | import static android.system.OsConstants.EOPNOTSUPP; |
| 54 | |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 55 | import static com.android.server.ConnectivityStatsLog.NETWORK_BPF_MAP_INFO; |
| 56 | |
| 57 | import android.app.StatsManager; |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 58 | import android.content.Context; |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 59 | import android.net.BpfNetMapsReader; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 60 | import android.net.INetd; |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 61 | import android.net.UidOwnerValue; |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 62 | import android.os.Build; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 63 | import android.os.RemoteException; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 64 | import android.os.ServiceSpecificException; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 65 | import android.system.ErrnoException; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 66 | import android.system.Os; |
Motomu Utsumi | 1a477b0 | 2022-08-23 15:14:56 +0900 | [diff] [blame] | 67 | import android.util.ArraySet; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 68 | import android.util.IndentingPrintWriter; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 69 | import android.util.Log; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 70 | import android.util.Pair; |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 71 | import android.util.StatsEvent; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 72 | |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 73 | import androidx.annotation.RequiresApi; |
| 74 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 75 | import com.android.internal.annotations.VisibleForTesting; |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 76 | import com.android.modules.utils.BackgroundThread; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 77 | import com.android.modules.utils.build.SdkLevel; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 78 | import com.android.net.module.util.BpfDump; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 79 | import com.android.net.module.util.BpfMap; |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 80 | import com.android.net.module.util.DeviceConfigUtils; |
Motomu Utsumi | 73599a5 | 2022-08-24 11:59:21 +0900 | [diff] [blame] | 81 | import com.android.net.module.util.IBpfMap; |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 82 | import com.android.net.module.util.Struct; |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 83 | import com.android.net.module.util.Struct.S32; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 84 | import com.android.net.module.util.Struct.U32; |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 85 | import com.android.net.module.util.Struct.U8; |
Motomu Utsumi | b954886 | 2022-09-06 16:30:05 +0900 | [diff] [blame] | 86 | import com.android.net.module.util.bpf.CookieTagMapKey; |
| 87 | import com.android.net.module.util.bpf.CookieTagMapValue; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 88 | |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 89 | import java.io.FileDescriptor; |
| 90 | import java.io.IOException; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 91 | import java.util.Arrays; |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 92 | import java.util.List; |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame] | 93 | import java.util.Set; |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 94 | import java.util.StringJoiner; |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 95 | |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 96 | /** |
| 97 | * BpfNetMaps is responsible for providing traffic controller relevant functionality. |
| 98 | * |
| 99 | * {@hide} |
| 100 | */ |
| 101 | public class BpfNetMaps { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 102 | static { |
| 103 | if (!PRE_T) { |
| 104 | System.loadLibrary("service-connectivity"); |
| 105 | } |
| 106 | } |
| 107 | |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 108 | private static final String TAG = "BpfNetMaps"; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 109 | private final INetd mNetd; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 110 | private final Dependencies mDeps; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 111 | // Use legacy netd for releases before T. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 112 | private static boolean sInitialized = false; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 113 | |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 114 | private static Boolean sEnableJavaBpfMap = null; |
Motomu Utsumi | 7628ea3 | 2023-08-14 11:09:02 +0900 | [diff] [blame] | 115 | private static final String BPF_NET_MAPS_FORCE_DISABLE_JAVA_BPF_MAP = |
| 116 | "bpf_net_maps_force_disable_java_bpf_map"; |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 117 | |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 118 | // Lock for sConfigurationMap entry for UID_RULES_CONFIGURATION_KEY. |
| 119 | // This entry is not accessed by others. |
| 120 | // BpfNetMaps acquires this lock while sequence of read, modify, and write. |
| 121 | private static final Object sUidRulesConfigBpfMapLock = new Object(); |
| 122 | |
Motomu Utsumi | 7abeaa4 | 2022-07-20 07:54:18 +0000 | [diff] [blame] | 123 | // Lock for sConfigurationMap entry for CURRENT_STATS_MAP_CONFIGURATION_KEY. |
| 124 | // BpfNetMaps acquires this lock while sequence of read, modify, and write. |
| 125 | // BpfNetMaps is an only writer of this entry. |
| 126 | private static final Object sCurrentStatsMapConfigLock = new Object(); |
| 127 | |
Motomu Utsumi | ba2fa15 | 2022-07-25 01:57:23 +0000 | [diff] [blame] | 128 | private static final long UID_RULES_DEFAULT_CONFIGURATION = 0; |
| 129 | private static final long STATS_SELECT_MAP_A = 0; |
| 130 | private static final long STATS_SELECT_MAP_B = 1; |
| 131 | |
Maciej Żenczykowski | dc88622 | 2022-09-17 06:09:22 +0000 | [diff] [blame] | 132 | private static IBpfMap<S32, U32> sConfigurationMap = null; |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 133 | // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others. |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 134 | private static IBpfMap<S32, UidOwnerValue> sUidOwnerMap = null; |
| 135 | private static IBpfMap<S32, U8> sUidPermissionMap = null; |
Motomu Utsumi | b954886 | 2022-09-06 16:30:05 +0900 | [diff] [blame] | 136 | private static IBpfMap<CookieTagMapKey, CookieTagMapValue> sCookieTagMap = null; |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 137 | // TODO: Add BOOL class and replace U8? |
| 138 | private static IBpfMap<S32, U8> sDataSaverEnabledMap = null; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 139 | |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 140 | private static final List<Pair<Integer, String>> PERMISSION_LIST = Arrays.asList( |
| 141 | Pair.create(PERMISSION_INTERNET, "PERMISSION_INTERNET"), |
| 142 | Pair.create(PERMISSION_UPDATE_DEVICE_STATS, "PERMISSION_UPDATE_DEVICE_STATS") |
| 143 | ); |
| 144 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 145 | /** |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 146 | * Set sEnableJavaBpfMap for test. |
| 147 | */ |
| 148 | @VisibleForTesting |
| 149 | public static void setEnableJavaBpfMapForTest(boolean enable) { |
| 150 | sEnableJavaBpfMap = enable; |
| 151 | } |
| 152 | |
| 153 | /** |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 154 | * Set configurationMap for test. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 155 | */ |
| 156 | @VisibleForTesting |
Maciej Żenczykowski | dc88622 | 2022-09-17 06:09:22 +0000 | [diff] [blame] | 157 | public static void setConfigurationMapForTest(IBpfMap<S32, U32> configurationMap) { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 158 | sConfigurationMap = configurationMap; |
| 159 | } |
| 160 | |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 161 | /** |
| 162 | * Set uidOwnerMap for test. |
| 163 | */ |
| 164 | @VisibleForTesting |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 165 | public static void setUidOwnerMapForTest(IBpfMap<S32, UidOwnerValue> uidOwnerMap) { |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 166 | sUidOwnerMap = uidOwnerMap; |
| 167 | } |
| 168 | |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 169 | /** |
| 170 | * Set uidPermissionMap for test. |
| 171 | */ |
| 172 | @VisibleForTesting |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 173 | public static void setUidPermissionMapForTest(IBpfMap<S32, U8> uidPermissionMap) { |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 174 | sUidPermissionMap = uidPermissionMap; |
| 175 | } |
| 176 | |
Motomu Utsumi | b954886 | 2022-09-06 16:30:05 +0900 | [diff] [blame] | 177 | /** |
| 178 | * Set cookieTagMap for test. |
| 179 | */ |
| 180 | @VisibleForTesting |
| 181 | public static void setCookieTagMapForTest( |
| 182 | IBpfMap<CookieTagMapKey, CookieTagMapValue> cookieTagMap) { |
| 183 | sCookieTagMap = cookieTagMap; |
| 184 | } |
| 185 | |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 186 | /** |
| 187 | * Set dataSaverEnabledMap for test. |
| 188 | */ |
| 189 | @VisibleForTesting |
| 190 | public static void setDataSaverEnabledMapForTest(IBpfMap<S32, U8> dataSaverEnabledMap) { |
| 191 | sDataSaverEnabledMap = dataSaverEnabledMap; |
| 192 | } |
| 193 | |
Maciej Żenczykowski | dc88622 | 2022-09-17 06:09:22 +0000 | [diff] [blame] | 194 | private static IBpfMap<S32, U32> getConfigurationMap() { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 195 | try { |
| 196 | return new BpfMap<>( |
Maciej Żenczykowski | dc88622 | 2022-09-17 06:09:22 +0000 | [diff] [blame] | 197 | CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, S32.class, U32.class); |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 198 | } catch (ErrnoException e) { |
| 199 | throw new IllegalStateException("Cannot open netd configuration map", e); |
| 200 | } |
| 201 | } |
| 202 | |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 203 | private static IBpfMap<S32, UidOwnerValue> getUidOwnerMap() { |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 204 | try { |
| 205 | return new BpfMap<>( |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 206 | UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, S32.class, UidOwnerValue.class); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 207 | } catch (ErrnoException e) { |
| 208 | throw new IllegalStateException("Cannot open uid owner map", e); |
| 209 | } |
| 210 | } |
| 211 | |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 212 | private static IBpfMap<S32, U8> getUidPermissionMap() { |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 213 | try { |
| 214 | return new BpfMap<>( |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 215 | UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, S32.class, U8.class); |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 216 | } catch (ErrnoException e) { |
| 217 | throw new IllegalStateException("Cannot open uid permission map", e); |
| 218 | } |
| 219 | } |
| 220 | |
Motomu Utsumi | b954886 | 2022-09-06 16:30:05 +0900 | [diff] [blame] | 221 | private static IBpfMap<CookieTagMapKey, CookieTagMapValue> getCookieTagMap() { |
| 222 | try { |
| 223 | return new BpfMap<>(COOKIE_TAG_MAP_PATH, BpfMap.BPF_F_RDWR, |
| 224 | CookieTagMapKey.class, CookieTagMapValue.class); |
| 225 | } catch (ErrnoException e) { |
| 226 | throw new IllegalStateException("Cannot open cookie tag map", e); |
| 227 | } |
| 228 | } |
| 229 | |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 230 | private static IBpfMap<S32, U8> getDataSaverEnabledMap() { |
| 231 | try { |
| 232 | return new BpfMap<>( |
| 233 | DATA_SAVER_ENABLED_MAP_PATH, BpfMap.BPF_F_RDWR, S32.class, U8.class); |
| 234 | } catch (ErrnoException e) { |
| 235 | throw new IllegalStateException("Cannot open data saver enabled map", e); |
| 236 | } |
| 237 | } |
| 238 | |
Motomu Utsumi | ba2fa15 | 2022-07-25 01:57:23 +0000 | [diff] [blame] | 239 | private static void initBpfMaps() { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 240 | if (sConfigurationMap == null) { |
| 241 | sConfigurationMap = getConfigurationMap(); |
| 242 | } |
Motomu Utsumi | ba2fa15 | 2022-07-25 01:57:23 +0000 | [diff] [blame] | 243 | try { |
| 244 | sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, |
| 245 | new U32(UID_RULES_DEFAULT_CONFIGURATION)); |
| 246 | } catch (ErrnoException e) { |
| 247 | throw new IllegalStateException("Failed to initialize uid rules configuration", e); |
| 248 | } |
| 249 | try { |
| 250 | sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY, |
| 251 | new U32(STATS_SELECT_MAP_A)); |
| 252 | } catch (ErrnoException e) { |
| 253 | throw new IllegalStateException("Failed to initialize current stats configuration", e); |
| 254 | } |
| 255 | |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 256 | if (sUidOwnerMap == null) { |
| 257 | sUidOwnerMap = getUidOwnerMap(); |
| 258 | } |
Motomu Utsumi | ba2fa15 | 2022-07-25 01:57:23 +0000 | [diff] [blame] | 259 | try { |
| 260 | sUidOwnerMap.clear(); |
| 261 | } catch (ErrnoException e) { |
| 262 | throw new IllegalStateException("Failed to initialize uid owner map", e); |
| 263 | } |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 264 | |
| 265 | if (sUidPermissionMap == null) { |
| 266 | sUidPermissionMap = getUidPermissionMap(); |
| 267 | } |
Motomu Utsumi | b954886 | 2022-09-06 16:30:05 +0900 | [diff] [blame] | 268 | |
| 269 | if (sCookieTagMap == null) { |
| 270 | sCookieTagMap = getCookieTagMap(); |
| 271 | } |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 272 | |
| 273 | if (sDataSaverEnabledMap == null) { |
| 274 | sDataSaverEnabledMap = getDataSaverEnabledMap(); |
| 275 | } |
| 276 | try { |
| 277 | sDataSaverEnabledMap.updateEntry(DATA_SAVER_ENABLED_KEY, new U8(DATA_SAVER_DISABLED)); |
| 278 | } catch (ErrnoException e) { |
| 279 | throw new IllegalStateException("Failed to initialize data saver configuration", e); |
| 280 | } |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 283 | /** |
| 284 | * Initializes the class if it is not already initialized. This method will open maps but not |
| 285 | * cause any other effects. This method may be called multiple times on any thread. |
| 286 | */ |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 287 | private static synchronized void ensureInitialized(final Context context) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 288 | if (sInitialized) return; |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 289 | if (sEnableJavaBpfMap == null) { |
Maciej Żenczykowski | e7ebb15 | 2022-12-27 10:57:38 +0000 | [diff] [blame] | 290 | sEnableJavaBpfMap = SdkLevel.isAtLeastU() || |
Motomu Utsumi | ed4e7ec | 2023-09-13 14:58:32 +0900 | [diff] [blame] | 291 | DeviceConfigUtils.isTetheringFeatureNotChickenedOut(context, |
Motomu Utsumi | 7628ea3 | 2023-08-14 11:09:02 +0900 | [diff] [blame] | 292 | BPF_NET_MAPS_FORCE_DISABLE_JAVA_BPF_MAP); |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 293 | } |
| 294 | Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap); |
| 295 | |
Motomu Utsumi | ba2fa15 | 2022-07-25 01:57:23 +0000 | [diff] [blame] | 296 | initBpfMaps(); |
Motomu Utsumi | d95a0da | 2022-09-03 00:40:30 +0900 | [diff] [blame] | 297 | native_init(!sEnableJavaBpfMap /* startSkDestroyListener */); |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 298 | sInitialized = true; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 299 | } |
| 300 | |
Motomu Utsumi | d95a0da | 2022-09-03 00:40:30 +0900 | [diff] [blame] | 301 | public boolean isSkDestroyListenerRunning() { |
| 302 | return !sEnableJavaBpfMap; |
| 303 | } |
| 304 | |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 305 | /** |
| 306 | * Dependencies of BpfNetMaps, for injection in tests. |
| 307 | */ |
| 308 | @VisibleForTesting |
| 309 | public static class Dependencies { |
| 310 | /** |
| 311 | * Get interface index. |
| 312 | */ |
| 313 | public int getIfIndex(final String ifName) { |
| 314 | return Os.if_nametoindex(ifName); |
| 315 | } |
Motomu Utsumi | 7abeaa4 | 2022-07-20 07:54:18 +0000 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * Call synchronize_rcu() |
| 319 | */ |
| 320 | public int synchronizeKernelRCU() { |
| 321 | return native_synchronizeKernelRCU(); |
| 322 | } |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * Build Stats Event for NETWORK_BPF_MAP_INFO atom |
| 326 | */ |
| 327 | public StatsEvent buildStatsEvent(final int cookieTagMapSize, final int uidOwnerMapSize, |
| 328 | final int uidPermissionMapSize) { |
| 329 | return ConnectivityStatsLog.buildStatsEvent(NETWORK_BPF_MAP_INFO, cookieTagMapSize, |
| 330 | uidOwnerMapSize, uidPermissionMapSize); |
| 331 | } |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 332 | } |
| 333 | |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 334 | /** Constructor used after T that doesn't need to use netd anymore. */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 335 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 336 | public BpfNetMaps(final Context context) { |
| 337 | this(context, null); |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 338 | |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 339 | if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T"); |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 340 | } |
| 341 | |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 342 | public BpfNetMaps(final Context context, final INetd netd) { |
| 343 | this(context, netd, new Dependencies()); |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | @VisibleForTesting |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 347 | public BpfNetMaps(final Context context, final INetd netd, final Dependencies deps) { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 348 | if (!PRE_T) { |
Motomu Utsumi | f688eeb | 2022-07-22 03:47:35 +0000 | [diff] [blame] | 349 | ensureInitialized(context); |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 350 | } |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 351 | mNetd = netd; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 352 | mDeps = deps; |
Wayne Ma | 790c83e | 2022-01-13 10:35:05 +0800 | [diff] [blame] | 353 | } |
| 354 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 355 | /** |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 356 | * Get if the chain is allow list or not. |
| 357 | * |
| 358 | * ALLOWLIST means the firewall denies all by default, uids must be explicitly allowed |
| 359 | * DENYLIST means the firewall allows all by default, uids must be explicitly denyed |
| 360 | */ |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 361 | public boolean isFirewallAllowList(final int chain) { |
| 362 | switch (chain) { |
| 363 | case FIREWALL_CHAIN_DOZABLE: |
| 364 | case FIREWALL_CHAIN_POWERSAVE: |
| 365 | case FIREWALL_CHAIN_RESTRICTED: |
| 366 | case FIREWALL_CHAIN_LOW_POWER_STANDBY: |
| 367 | return true; |
| 368 | case FIREWALL_CHAIN_STANDBY: |
| 369 | case FIREWALL_CHAIN_OEM_DENY_1: |
| 370 | case FIREWALL_CHAIN_OEM_DENY_2: |
| 371 | case FIREWALL_CHAIN_OEM_DENY_3: |
| 372 | return false; |
| 373 | default: |
| 374 | throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain); |
| 375 | } |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 378 | private void maybeThrow(final int err, final String msg) { |
| 379 | if (err != 0) { |
| 380 | throw new ServiceSpecificException(err, msg + ": " + Os.strerror(err)); |
| 381 | } |
| 382 | } |
| 383 | |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 384 | private void throwIfPreT(final String msg) { |
| 385 | if (PRE_T) { |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 386 | throw new UnsupportedOperationException(msg); |
| 387 | } |
| 388 | } |
| 389 | |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 390 | private void removeRule(final int uid, final long match, final String caller) { |
| 391 | try { |
| 392 | synchronized (sUidOwnerMap) { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 393 | final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new S32(uid)); |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 394 | |
| 395 | if (oldMatch == null) { |
| 396 | throw new ServiceSpecificException(ENOENT, |
| 397 | "sUidOwnerMap does not have entry for uid: " + uid); |
| 398 | } |
| 399 | |
| 400 | final UidOwnerValue newMatch = new UidOwnerValue( |
| 401 | (match == IIF_MATCH) ? 0 : oldMatch.iif, |
| 402 | oldMatch.rule & ~match |
| 403 | ); |
| 404 | |
| 405 | if (newMatch.rule == 0) { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 406 | sUidOwnerMap.deleteEntry(new S32(uid)); |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 407 | } else { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 408 | sUidOwnerMap.updateEntry(new S32(uid), newMatch); |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } catch (ErrnoException e) { |
| 412 | throw new ServiceSpecificException(e.errno, |
| 413 | caller + " failed to remove rule: " + Os.strerror(e.errno)); |
| 414 | } |
| 415 | } |
| 416 | |
Maciej Żenczykowski | 6c1c6bb | 2022-09-16 06:55:33 +0000 | [diff] [blame] | 417 | private void addRule(final int uid, final long match, final int iif, final String caller) { |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 418 | if (match != IIF_MATCH && iif != 0) { |
| 419 | throw new ServiceSpecificException(EINVAL, |
| 420 | "Non-interface match must have zero interface index"); |
| 421 | } |
| 422 | |
| 423 | try { |
| 424 | synchronized (sUidOwnerMap) { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 425 | final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new S32(uid)); |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 426 | |
| 427 | final UidOwnerValue newMatch; |
| 428 | if (oldMatch != null) { |
| 429 | newMatch = new UidOwnerValue( |
| 430 | (match == IIF_MATCH) ? iif : oldMatch.iif, |
| 431 | oldMatch.rule | match |
| 432 | ); |
| 433 | } else { |
| 434 | newMatch = new UidOwnerValue( |
| 435 | iif, |
| 436 | match |
| 437 | ); |
| 438 | } |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 439 | sUidOwnerMap.updateEntry(new S32(uid), newMatch); |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 440 | } |
| 441 | } catch (ErrnoException e) { |
| 442 | throw new ServiceSpecificException(e.errno, |
| 443 | caller + " failed to add rule: " + Os.strerror(e.errno)); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | private void addRule(final int uid, final long match, final String caller) { |
| 448 | addRule(uid, match, 0 /* iif */, caller); |
| 449 | } |
| 450 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 451 | /** |
| 452 | * Add naughty app bandwidth rule for specific app |
| 453 | * |
| 454 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 455 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 456 | * cause of the failure. |
| 457 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 458 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 459 | public void addNaughtyApp(final int uid) { |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 460 | throwIfPreT("addNaughtyApp is not available on pre-T devices"); |
Motomu Utsumi | 55c282e | 2022-08-03 06:25:33 +0000 | [diff] [blame] | 461 | |
| 462 | if (sEnableJavaBpfMap) { |
| 463 | addRule(uid, PENALTY_BOX_MATCH, "addNaughtyApp"); |
| 464 | } else { |
| 465 | final int err = native_addNaughtyApp(uid); |
| 466 | maybeThrow(err, "Unable to add naughty app"); |
| 467 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 468 | } |
| 469 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 470 | /** |
| 471 | * Remove naughty app bandwidth rule for specific app |
| 472 | * |
| 473 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 474 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 475 | * cause of the failure. |
| 476 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 477 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 478 | public void removeNaughtyApp(final int uid) { |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 479 | throwIfPreT("removeNaughtyApp is not available on pre-T devices"); |
Motomu Utsumi | 878ce0d | 2022-08-03 06:22:42 +0000 | [diff] [blame] | 480 | |
| 481 | if (sEnableJavaBpfMap) { |
| 482 | removeRule(uid, PENALTY_BOX_MATCH, "removeNaughtyApp"); |
| 483 | } else { |
| 484 | final int err = native_removeNaughtyApp(uid); |
| 485 | maybeThrow(err, "Unable to remove naughty app"); |
| 486 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 487 | } |
| 488 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 489 | /** |
| 490 | * Add nice app bandwidth rule for specific app |
| 491 | * |
| 492 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 493 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 494 | * cause of the failure. |
| 495 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 496 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 497 | public void addNiceApp(final int uid) { |
Motomu Utsumi | 55630d0 | 2022-06-29 07:46:52 +0000 | [diff] [blame] | 498 | throwIfPreT("addNiceApp is not available on pre-T devices"); |
Motomu Utsumi | 7f19df9 | 2022-08-03 06:29:59 +0000 | [diff] [blame] | 499 | |
| 500 | if (sEnableJavaBpfMap) { |
| 501 | addRule(uid, HAPPY_BOX_MATCH, "addNiceApp"); |
| 502 | } else { |
| 503 | final int err = native_addNiceApp(uid); |
| 504 | maybeThrow(err, "Unable to add nice app"); |
| 505 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 506 | } |
| 507 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 508 | /** |
| 509 | * Remove nice app bandwidth rule for specific app |
| 510 | * |
| 511 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 512 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 513 | * cause of the failure. |
| 514 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 515 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 516 | public void removeNiceApp(final int uid) { |
Motomu Utsumi | 7392eb4 | 2022-06-29 03:53:03 +0000 | [diff] [blame] | 517 | throwIfPreT("removeNiceApp is not available on pre-T devices"); |
Motomu Utsumi | 5f15f75 | 2022-08-03 06:27:51 +0000 | [diff] [blame] | 518 | |
| 519 | if (sEnableJavaBpfMap) { |
| 520 | removeRule(uid, HAPPY_BOX_MATCH, "removeNiceApp"); |
| 521 | } else { |
| 522 | final int err = native_removeNiceApp(uid); |
| 523 | maybeThrow(err, "Unable to remove nice app"); |
| 524 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 525 | } |
| 526 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 527 | /** |
| 528 | * Set target firewall child chain |
| 529 | * |
| 530 | * @param childChain target chain to enable |
| 531 | * @param enable whether to enable or disable child chain. |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 532 | * @throws UnsupportedOperationException if called on pre-T devices. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 533 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 534 | * cause of the failure. |
| 535 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 536 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 537 | public void setChildChain(final int childChain, final boolean enable) { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 538 | throwIfPreT("setChildChain is not available on pre-T devices"); |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 539 | |
Motomu Utsumi | e057dd4 | 2022-08-03 01:23:49 +0000 | [diff] [blame] | 540 | if (sEnableJavaBpfMap) { |
| 541 | final long match = getMatchByFirewallChain(childChain); |
| 542 | try { |
| 543 | synchronized (sUidRulesConfigBpfMapLock) { |
| 544 | final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY); |
| 545 | final long newConfig = enable ? (config.val | match) : (config.val & ~match); |
| 546 | sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig)); |
| 547 | } |
| 548 | } catch (ErrnoException e) { |
| 549 | throw new ServiceSpecificException(e.errno, |
| 550 | "Unable to set child chain: " + Os.strerror(e.errno)); |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 551 | } |
Motomu Utsumi | e057dd4 | 2022-08-03 01:23:49 +0000 | [diff] [blame] | 552 | } else { |
| 553 | final int err = native_setChildChain(childChain, enable); |
| 554 | maybeThrow(err, "Unable to set child chain"); |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 555 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /** |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 559 | * Get the specified firewall chain's status. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 560 | * |
| 561 | * @param childChain target chain |
| 562 | * @return {@code true} if chain is enabled, {@code false} if chain is not enabled. |
| 563 | * @throws UnsupportedOperationException if called on pre-T devices. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 564 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 565 | * cause of the failure. |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 566 | * |
| 567 | * @deprecated Use {@link BpfNetMapsReader#isChainEnabled} instead. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 568 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 569 | // TODO: Migrate the callers to use {@link BpfNetMapsReader#isChainEnabled} instead. |
| 570 | @Deprecated |
| 571 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 572 | public boolean isChainEnabled(final int childChain) { |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 573 | return BpfNetMapsReader.isChainEnabled(sConfigurationMap, childChain); |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Motomu Utsumi | 1a477b0 | 2022-08-23 15:14:56 +0900 | [diff] [blame] | 576 | private Set<Integer> asSet(final int[] uids) { |
| 577 | final Set<Integer> uidSet = new ArraySet<>(); |
| 578 | for (final int uid: uids) { |
| 579 | uidSet.add(uid); |
| 580 | } |
| 581 | return uidSet; |
| 582 | } |
| 583 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 584 | /** |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 585 | * Replaces the contents of the specified UID-based firewall chain. |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame] | 586 | * Enables the chain for specified uids and disables the chain for non-specified uids. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 587 | * |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame] | 588 | * @param chain Target chain. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 589 | * @param uids The list of UIDs to allow/deny. |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame] | 590 | * @throws UnsupportedOperationException if called on pre-T devices. |
| 591 | * @throws IllegalArgumentException if {@code chain} is not a valid chain. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 592 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 593 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame] | 594 | public void replaceUidChain(final int chain, final int[] uids) { |
| 595 | throwIfPreT("replaceUidChain is not available on pre-T devices"); |
| 596 | |
Motomu Utsumi | c7c1685 | 2022-08-03 06:51:41 +0000 | [diff] [blame] | 597 | if (sEnableJavaBpfMap) { |
| 598 | final long match; |
| 599 | try { |
| 600 | match = getMatchByFirewallChain(chain); |
| 601 | } catch (ServiceSpecificException e) { |
| 602 | // Throws IllegalArgumentException to keep the behavior of |
| 603 | // ConnectivityManager#replaceFirewallChain API |
| 604 | throw new IllegalArgumentException("Invalid firewall chain: " + chain); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 605 | } |
Motomu Utsumi | 1a477b0 | 2022-08-23 15:14:56 +0900 | [diff] [blame] | 606 | final Set<Integer> uidSet = asSet(uids); |
| 607 | final Set<Integer> uidSetToRemoveRule = new ArraySet<>(); |
Motomu Utsumi | c7c1685 | 2022-08-03 06:51:41 +0000 | [diff] [blame] | 608 | try { |
| 609 | synchronized (sUidOwnerMap) { |
| 610 | sUidOwnerMap.forEach((uid, config) -> { |
| 611 | // config could be null if there is a concurrent entry deletion. |
Motomu Utsumi | 8e420ea | 2022-08-24 18:03:30 +0900 | [diff] [blame] | 612 | // http://b/220084230. But sUidOwnerMap update must be done while holding a |
| 613 | // lock, so this should not happen. |
| 614 | if (config == null) { |
| 615 | Log.wtf(TAG, "sUidOwnerMap entry was deleted while holding a lock"); |
| 616 | } else if (!uidSet.contains((int) uid.val) && (config.rule & match) != 0) { |
Motomu Utsumi | c7c1685 | 2022-08-03 06:51:41 +0000 | [diff] [blame] | 617 | uidSetToRemoveRule.add((int) uid.val); |
| 618 | } |
| 619 | }); |
| 620 | |
| 621 | for (final int uid : uidSetToRemoveRule) { |
| 622 | removeRule(uid, match, "replaceUidChain"); |
| 623 | } |
| 624 | for (final int uid : uids) { |
| 625 | addRule(uid, match, "replaceUidChain"); |
| 626 | } |
| 627 | } |
| 628 | } catch (ErrnoException | ServiceSpecificException e) { |
| 629 | Log.e(TAG, "replaceUidChain failed: " + e); |
| 630 | } |
| 631 | } else { |
| 632 | final int err; |
| 633 | switch (chain) { |
| 634 | case FIREWALL_CHAIN_DOZABLE: |
| 635 | err = native_replaceUidChain("fw_dozable", true /* isAllowList */, uids); |
| 636 | break; |
| 637 | case FIREWALL_CHAIN_STANDBY: |
| 638 | err = native_replaceUidChain("fw_standby", false /* isAllowList */, uids); |
| 639 | break; |
| 640 | case FIREWALL_CHAIN_POWERSAVE: |
| 641 | err = native_replaceUidChain("fw_powersave", true /* isAllowList */, uids); |
| 642 | break; |
| 643 | case FIREWALL_CHAIN_RESTRICTED: |
| 644 | err = native_replaceUidChain("fw_restricted", true /* isAllowList */, uids); |
| 645 | break; |
| 646 | case FIREWALL_CHAIN_LOW_POWER_STANDBY: |
| 647 | err = native_replaceUidChain( |
| 648 | "fw_low_power_standby", true /* isAllowList */, uids); |
| 649 | break; |
| 650 | case FIREWALL_CHAIN_OEM_DENY_1: |
| 651 | err = native_replaceUidChain("fw_oem_deny_1", false /* isAllowList */, uids); |
| 652 | break; |
| 653 | case FIREWALL_CHAIN_OEM_DENY_2: |
| 654 | err = native_replaceUidChain("fw_oem_deny_2", false /* isAllowList */, uids); |
| 655 | break; |
| 656 | case FIREWALL_CHAIN_OEM_DENY_3: |
| 657 | err = native_replaceUidChain("fw_oem_deny_3", false /* isAllowList */, uids); |
| 658 | break; |
| 659 | default: |
| 660 | throw new IllegalArgumentException("replaceFirewallChain with invalid chain: " |
| 661 | + chain); |
| 662 | } |
| 663 | if (err != 0) { |
| 664 | Log.e(TAG, "replaceUidChain failed: " + Os.strerror(-err)); |
| 665 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 666 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 667 | } |
| 668 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 669 | /** |
| 670 | * Set firewall rule for uid |
| 671 | * |
| 672 | * @param childChain target chain |
| 673 | * @param uid uid to allow/deny |
| 674 | * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 675 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 676 | * cause of the failure. |
| 677 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 678 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 679 | public void setUidRule(final int childChain, final int uid, final int firewallRule) { |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 680 | throwIfPreT("setUidRule is not available on pre-T devices"); |
| 681 | |
Motomu Utsumi | 381ad9e | 2022-08-03 06:42:47 +0000 | [diff] [blame] | 682 | if (sEnableJavaBpfMap) { |
| 683 | final long match = getMatchByFirewallChain(childChain); |
| 684 | final boolean isAllowList = isFirewallAllowList(childChain); |
| 685 | final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList) |
| 686 | || (firewallRule == FIREWALL_RULE_DENY && !isAllowList); |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 687 | |
Motomu Utsumi | 381ad9e | 2022-08-03 06:42:47 +0000 | [diff] [blame] | 688 | if (add) { |
| 689 | addRule(uid, match, "setUidRule"); |
| 690 | } else { |
| 691 | removeRule(uid, match, "setUidRule"); |
| 692 | } |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 693 | } else { |
Motomu Utsumi | 381ad9e | 2022-08-03 06:42:47 +0000 | [diff] [blame] | 694 | final int err = native_setUidRule(childChain, uid, firewallRule); |
| 695 | maybeThrow(err, "Unable to set uid rule"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 696 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
Motomu Utsumi | 56c412a | 2023-01-19 15:58:39 +0900 | [diff] [blame] | 700 | * Get firewall rule of specified firewall chain on specified uid. |
| 701 | * |
| 702 | * @param childChain target chain |
| 703 | * @param uid target uid |
| 704 | * @return either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY |
| 705 | * @throws UnsupportedOperationException if called on pre-T devices. |
| 706 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 707 | * cause of the failure. |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 708 | * |
| 709 | * @deprecated use {@link BpfNetMapsReader#getUidRule} instead. |
Motomu Utsumi | 56c412a | 2023-01-19 15:58:39 +0900 | [diff] [blame] | 710 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 711 | // TODO: Migrate the callers to use {@link BpfNetMapsReader#getUidRule} instead. |
Motomu Utsumi | 56c412a | 2023-01-19 15:58:39 +0900 | [diff] [blame] | 712 | public int getUidRule(final int childChain, final int uid) { |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 713 | return BpfNetMapsReader.getUidRule(sUidOwnerMap, childChain, uid); |
Motomu Utsumi | 56c412a | 2023-01-19 15:58:39 +0900 | [diff] [blame] | 714 | } |
| 715 | |
Motomu Utsumi | d44a33a | 2023-03-28 18:08:12 +0900 | [diff] [blame] | 716 | private Set<Integer> getUidsMatchEnabled(final int childChain) throws ErrnoException { |
| 717 | final long match = getMatchByFirewallChain(childChain); |
| 718 | Set<Integer> uids = new ArraySet<>(); |
| 719 | synchronized (sUidOwnerMap) { |
| 720 | sUidOwnerMap.forEach((uid, val) -> { |
| 721 | if (val == null) { |
| 722 | Log.wtf(TAG, "sUidOwnerMap entry was deleted while holding a lock"); |
| 723 | } else { |
| 724 | if ((val.rule & match) != 0) { |
| 725 | uids.add(uid.val); |
| 726 | } |
| 727 | } |
| 728 | }); |
| 729 | } |
| 730 | return uids; |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Get uids that has FIREWALL_RULE_ALLOW on allowlist chain. |
| 735 | * Allowlist means the firewall denies all by default, uids must be explicitly allowed. |
| 736 | * |
| 737 | * Note that uids that has FIREWALL_RULE_DENY on allowlist chain can not be computed from the |
| 738 | * bpf map, since all the uids that does not have explicit FIREWALL_RULE_ALLOW rule in bpf map |
| 739 | * are determined to have FIREWALL_RULE_DENY. |
| 740 | * |
| 741 | * @param childChain target chain |
| 742 | * @return Set of uids |
| 743 | */ |
| 744 | public Set<Integer> getUidsWithAllowRuleOnAllowListChain(final int childChain) |
| 745 | throws ErrnoException { |
| 746 | if (!isFirewallAllowList(childChain)) { |
| 747 | throw new IllegalArgumentException("getUidsWithAllowRuleOnAllowListChain is called with" |
| 748 | + " denylist chain:" + childChain); |
| 749 | } |
| 750 | // Corresponding match is enabled for uids that has FIREWALL_RULE_ALLOW on allowlist chain. |
| 751 | return getUidsMatchEnabled(childChain); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Get uids that has FIREWALL_RULE_DENY on denylist chain. |
| 756 | * Denylist means the firewall allows all by default, uids must be explicitly denyed |
| 757 | * |
| 758 | * Note that uids that has FIREWALL_RULE_ALLOW on denylist chain can not be computed from the |
| 759 | * bpf map, since all the uids that does not have explicit FIREWALL_RULE_DENY rule in bpf map |
| 760 | * are determined to have the FIREWALL_RULE_ALLOW. |
| 761 | * |
| 762 | * @param childChain target chain |
| 763 | * @return Set of uids |
| 764 | */ |
| 765 | public Set<Integer> getUidsWithDenyRuleOnDenyListChain(final int childChain) |
| 766 | throws ErrnoException { |
| 767 | if (isFirewallAllowList(childChain)) { |
| 768 | throw new IllegalArgumentException("getUidsWithDenyRuleOnDenyListChain is called with" |
| 769 | + " allowlist chain:" + childChain); |
| 770 | } |
| 771 | // Corresponding match is enabled for uids that has FIREWALL_RULE_DENY on denylist chain. |
| 772 | return getUidsMatchEnabled(childChain); |
| 773 | } |
| 774 | |
Motomu Utsumi | 56c412a | 2023-01-19 15:58:39 +0900 | [diff] [blame] | 775 | /** |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 776 | * Add ingress interface filtering rules to a list of UIDs |
| 777 | * |
| 778 | * For a given uid, once a filtering rule is added, the kernel will only allow packets from the |
| 779 | * allowed interface and loopback to be sent to the list of UIDs. |
| 780 | * |
| 781 | * Calling this method on one or more UIDs with an existing filtering rule but a different |
| 782 | * interface name will result in the filtering rule being updated to allow the new interface |
| 783 | * instead. Otherwise calling this method will not affect existing rules set on other UIDs. |
| 784 | * |
| 785 | * @param ifName the name of the interface on which the filtering rules will allow packets to |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 786 | * be received. |
| 787 | * @param uids an array of UIDs which the filtering rules will be set |
| 788 | * @throws RemoteException when netd has crashed. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 789 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 790 | * cause of the failure. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 791 | */ |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 792 | public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 793 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 794 | mNetd.firewallAddUidInterfaceRules(ifName, uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 795 | return; |
| 796 | } |
Motomu Utsumi | f794e7d | 2022-08-03 06:38:43 +0000 | [diff] [blame] | 797 | |
| 798 | if (sEnableJavaBpfMap) { |
| 799 | // Null ifName is a wildcard to allow apps to receive packets on all interfaces and |
| 800 | // ifIndex is set to 0. |
| 801 | final int ifIndex; |
| 802 | if (ifName == null) { |
| 803 | ifIndex = 0; |
| 804 | } else { |
| 805 | ifIndex = mDeps.getIfIndex(ifName); |
| 806 | if (ifIndex == 0) { |
| 807 | throw new ServiceSpecificException(ENODEV, |
| 808 | "Failed to get index of interface " + ifName); |
| 809 | } |
| 810 | } |
| 811 | for (final int uid : uids) { |
| 812 | try { |
| 813 | addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules"); |
| 814 | } catch (ServiceSpecificException e) { |
| 815 | Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e); |
| 816 | } |
| 817 | } |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 818 | } else { |
Motomu Utsumi | f794e7d | 2022-08-03 06:38:43 +0000 | [diff] [blame] | 819 | final int err = native_addUidInterfaceRules(ifName, uids); |
| 820 | maybeThrow(err, "Unable to add uid interface rules"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 821 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Remove ingress interface filtering rules from a list of UIDs |
| 826 | * |
| 827 | * Clear the ingress interface filtering rules from the list of UIDs which were previously set |
| 828 | * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule. |
| 829 | * |
| 830 | * @param uids an array of UIDs from which the filtering rules will be removed |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 831 | * @throws RemoteException when netd has crashed. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 832 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 833 | * cause of the failure. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 834 | */ |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 835 | public void removeUidInterfaceRules(final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 836 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 837 | mNetd.firewallRemoveUidInterfaceRules(uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 838 | return; |
| 839 | } |
Motomu Utsumi | 7dc657d | 2022-08-03 06:40:46 +0000 | [diff] [blame] | 840 | |
| 841 | if (sEnableJavaBpfMap) { |
| 842 | for (final int uid : uids) { |
| 843 | try { |
| 844 | removeRule(uid, IIF_MATCH, "removeUidInterfaceRules"); |
| 845 | } catch (ServiceSpecificException e) { |
| 846 | Log.e(TAG, "removeRule failed uid=" + uid + ", " + e); |
| 847 | } |
Motomu Utsumi | 599c4e5 | 2022-06-30 03:37:18 +0000 | [diff] [blame] | 848 | } |
Motomu Utsumi | 7dc657d | 2022-08-03 06:40:46 +0000 | [diff] [blame] | 849 | } else { |
| 850 | final int err = native_removeUidInterfaceRules(uids); |
| 851 | maybeThrow(err, "Unable to remove uid interface rules"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 852 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 853 | } |
| 854 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 855 | /** |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 856 | * Update lockdown rule for uid |
| 857 | * |
| 858 | * @param uid target uid to add/remove the rule |
| 859 | * @param add {@code true} to add the rule, {@code false} to remove the rule. |
| 860 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 861 | * cause of the failure. |
| 862 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 863 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 864 | public void updateUidLockdownRule(final int uid, final boolean add) { |
Motomu Utsumi | 697b299 | 2022-06-30 02:25:29 +0000 | [diff] [blame] | 865 | throwIfPreT("updateUidLockdownRule is not available on pre-T devices"); |
Motomu Utsumi | b2d32b7 | 2022-08-03 06:31:58 +0000 | [diff] [blame] | 866 | |
| 867 | if (sEnableJavaBpfMap) { |
| 868 | if (add) { |
| 869 | addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule"); |
| 870 | } else { |
| 871 | removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule"); |
| 872 | } |
Motomu Utsumi | 697b299 | 2022-06-30 02:25:29 +0000 | [diff] [blame] | 873 | } else { |
Motomu Utsumi | b2d32b7 | 2022-08-03 06:31:58 +0000 | [diff] [blame] | 874 | final int err = native_updateUidLockdownRule(uid, add); |
| 875 | maybeThrow(err, "Unable to update lockdown rule"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 876 | } |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /** |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 880 | * Request netd to change the current active network stats map. |
| 881 | * |
Motomu Utsumi | 7abeaa4 | 2022-07-20 07:54:18 +0000 | [diff] [blame] | 882 | * @throws UnsupportedOperationException if called on pre-T devices. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 883 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 884 | * cause of the failure. |
| 885 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 886 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 887 | public void swapActiveStatsMap() { |
Motomu Utsumi | 7abeaa4 | 2022-07-20 07:54:18 +0000 | [diff] [blame] | 888 | throwIfPreT("swapActiveStatsMap is not available on pre-T devices"); |
| 889 | |
| 890 | if (sEnableJavaBpfMap) { |
| 891 | try { |
| 892 | synchronized (sCurrentStatsMapConfigLock) { |
| 893 | final long config = sConfigurationMap.getValue( |
| 894 | CURRENT_STATS_MAP_CONFIGURATION_KEY).val; |
| 895 | final long newConfig = (config == STATS_SELECT_MAP_A) |
| 896 | ? STATS_SELECT_MAP_B : STATS_SELECT_MAP_A; |
| 897 | sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY, |
| 898 | new U32(newConfig)); |
| 899 | } |
| 900 | } catch (ErrnoException e) { |
| 901 | throw new ServiceSpecificException(e.errno, "Failed to swap active stats map"); |
| 902 | } |
| 903 | |
| 904 | // After changing the config, it's needed to make sure all the current running eBPF |
| 905 | // programs are finished and all the CPUs are aware of this config change before the old |
| 906 | // map is modified. So special hack is needed here to wait for the kernel to do a |
| 907 | // synchronize_rcu(). Once the kernel called synchronize_rcu(), the updated config will |
| 908 | // be available to all cores and the next eBPF programs triggered inside the kernel will |
| 909 | // use the new map configuration. So once this function returns it is safe to modify the |
| 910 | // old stats map without concerning about race between the kernel and userspace. |
| 911 | final int err = mDeps.synchronizeKernelRCU(); |
| 912 | maybeThrow(err, "synchronizeKernelRCU failed"); |
| 913 | } else { |
| 914 | final int err = native_swapActiveStatsMap(); |
| 915 | maybeThrow(err, "Unable to swap active stats map"); |
| 916 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 917 | } |
| 918 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 919 | /** |
| 920 | * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids |
| 921 | * specified. Or remove all permissions from the uids. |
| 922 | * |
| 923 | * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or |
| 924 | * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then |
| 925 | * revoke all permissions for the uids. |
| 926 | * @param uids uid of users to grant permission |
| 927 | * @throws RemoteException when netd has crashed. |
| 928 | */ |
| 929 | public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 930 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 931 | mNetd.trafficSetNetPermForUids(permissions, uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 932 | return; |
| 933 | } |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 934 | |
| 935 | if (sEnableJavaBpfMap) { |
| 936 | // Remove the entry if package is uninstalled or uid has only INTERNET permission. |
| 937 | if (permissions == PERMISSION_UNINSTALLED || permissions == PERMISSION_INTERNET) { |
| 938 | for (final int uid : uids) { |
| 939 | try { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 940 | sUidPermissionMap.deleteEntry(new S32(uid)); |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 941 | } catch (ErrnoException e) { |
| 942 | Log.e(TAG, "Failed to remove uid " + uid + " from permission map: " + e); |
| 943 | } |
| 944 | } |
| 945 | return; |
| 946 | } |
| 947 | |
| 948 | for (final int uid : uids) { |
| 949 | try { |
Maciej Żenczykowski | 785793f | 2022-09-17 02:35:20 +0000 | [diff] [blame] | 950 | sUidPermissionMap.updateEntry(new S32(uid), new U8((short) permissions)); |
Motomu Utsumi | 6527120 | 2022-07-05 08:21:41 +0000 | [diff] [blame] | 951 | } catch (ErrnoException e) { |
| 952 | Log.e(TAG, "Failed to set permission " |
| 953 | + permissions + " to uid " + uid + ": " + e); |
| 954 | } |
| 955 | } |
| 956 | } else { |
| 957 | native_setPermissionForUids(permissions, uids); |
| 958 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 959 | } |
| 960 | |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 961 | /** |
| 962 | * Set Data Saver enabled or disabled |
| 963 | * |
| 964 | * @param enable whether Data Saver is enabled or disabled. |
| 965 | * @throws UnsupportedOperationException if called on pre-T devices. |
| 966 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 967 | * cause of the failure. |
| 968 | */ |
| 969 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
| 970 | public void setDataSaverEnabled(boolean enable) { |
| 971 | throwIfPreT("setDataSaverEnabled is not available on pre-T devices"); |
| 972 | |
| 973 | try { |
| 974 | final short config = enable ? DATA_SAVER_ENABLED : DATA_SAVER_DISABLED; |
| 975 | sDataSaverEnabledMap.updateEntry(DATA_SAVER_ENABLED_KEY, new U8(config)); |
| 976 | } catch (ErrnoException e) { |
| 977 | throw new ServiceSpecificException(e.errno, "Unable to set data saver: " |
| 978 | + Os.strerror(e.errno)); |
| 979 | } |
| 980 | } |
| 981 | |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 982 | /** Register callback for statsd to pull atom. */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 983 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 166f966 | 2022-09-01 10:35:29 +0900 | [diff] [blame] | 984 | public void setPullAtomCallback(final Context context) { |
| 985 | throwIfPreT("setPullAtomCallback is not available on pre-T devices"); |
| 986 | |
| 987 | final StatsManager statsManager = context.getSystemService(StatsManager.class); |
| 988 | statsManager.setPullAtomCallback(NETWORK_BPF_MAP_INFO, null /* metadata */, |
| 989 | BackgroundThread.getExecutor(), this::pullBpfMapInfoAtom); |
| 990 | } |
| 991 | |
| 992 | private <K extends Struct, V extends Struct> int getMapSize(IBpfMap<K, V> map) |
| 993 | throws ErrnoException { |
| 994 | // forEach could restart iteration from the beginning if there is a concurrent entry |
| 995 | // deletion. netd and skDestroyListener could delete CookieTagMap entry concurrently. |
| 996 | // So using Set to count the number of entry in the map. |
| 997 | Set<K> keySet = new ArraySet<>(); |
| 998 | map.forEach((k, v) -> keySet.add(k)); |
| 999 | return keySet.size(); |
| 1000 | } |
| 1001 | |
| 1002 | /** Callback for StatsManager#setPullAtomCallback */ |
| 1003 | @VisibleForTesting |
| 1004 | public int pullBpfMapInfoAtom(final int atomTag, final List<StatsEvent> data) { |
| 1005 | if (atomTag != NETWORK_BPF_MAP_INFO) { |
| 1006 | Log.e(TAG, "Unexpected atom tag: " + atomTag); |
| 1007 | return StatsManager.PULL_SKIP; |
| 1008 | } |
| 1009 | |
| 1010 | try { |
| 1011 | data.add(mDeps.buildStatsEvent(getMapSize(sCookieTagMap), getMapSize(sUidOwnerMap), |
| 1012 | getMapSize(sUidPermissionMap))); |
| 1013 | } catch (ErrnoException e) { |
| 1014 | Log.e(TAG, "Failed to pull NETWORK_BPF_MAP_INFO atom: " + e); |
| 1015 | return StatsManager.PULL_SKIP; |
| 1016 | } |
| 1017 | return StatsManager.PULL_SUCCESS; |
| 1018 | } |
| 1019 | |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1020 | private String permissionToString(int permissionMask) { |
| 1021 | if (permissionMask == PERMISSION_NONE) { |
| 1022 | return "PERMISSION_NONE"; |
| 1023 | } |
| 1024 | if (permissionMask == PERMISSION_UNINSTALLED) { |
| 1025 | // PERMISSION_UNINSTALLED should never appear in the map |
| 1026 | return "PERMISSION_UNINSTALLED error!"; |
| 1027 | } |
| 1028 | |
| 1029 | final StringJoiner sj = new StringJoiner(" "); |
| 1030 | for (Pair<Integer, String> permission: PERMISSION_LIST) { |
| 1031 | final int permissionFlag = permission.first; |
| 1032 | final String permissionName = permission.second; |
| 1033 | if ((permissionMask & permissionFlag) != 0) { |
| 1034 | sj.add(permissionName); |
| 1035 | permissionMask &= ~permissionFlag; |
| 1036 | } |
| 1037 | } |
| 1038 | if (permissionMask != 0) { |
| 1039 | sj.add("PERMISSION_UNKNOWN(" + permissionMask + ")"); |
| 1040 | } |
| 1041 | return sj.toString(); |
| 1042 | } |
| 1043 | |
Motomu Utsumi | 372c9b4 | 2022-09-02 19:02:56 +0900 | [diff] [blame] | 1044 | private void dumpOwnerMatchConfig(final IndentingPrintWriter pw) { |
| 1045 | try { |
| 1046 | final long match = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY).val; |
| 1047 | pw.println("current ownerMatch configuration: " + match + " " + matchToString(match)); |
| 1048 | } catch (ErrnoException e) { |
| 1049 | pw.println("Failed to read ownerMatch configuration: " + e); |
| 1050 | } |
| 1051 | } |
| 1052 | |
Motomu Utsumi | c675d6f | 2022-09-02 18:15:25 +0900 | [diff] [blame] | 1053 | private void dumpCurrentStatsMapConfig(final IndentingPrintWriter pw) { |
| 1054 | try { |
| 1055 | final long config = sConfigurationMap.getValue(CURRENT_STATS_MAP_CONFIGURATION_KEY).val; |
| 1056 | final String currentStatsMap = |
| 1057 | (config == STATS_SELECT_MAP_A) ? "SELECT_MAP_A" : "SELECT_MAP_B"; |
| 1058 | pw.println("current statsMap configuration: " + config + " " + currentStatsMap); |
| 1059 | } catch (ErrnoException e) { |
| 1060 | pw.println("Falied to read current statsMap configuration: " + e); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 1064 | private void dumpDataSaverConfig(final IndentingPrintWriter pw) { |
| 1065 | try { |
| 1066 | final short config = sDataSaverEnabledMap.getValue(DATA_SAVER_ENABLED_KEY).val; |
| 1067 | // Any non-zero value converted from short to boolean is true by convention. |
| 1068 | pw.println("sDataSaverEnabledMap: " + (config != DATA_SAVER_DISABLED)); |
| 1069 | } catch (ErrnoException e) { |
| 1070 | pw.println("Failed to read data saver configuration: " + e); |
| 1071 | } |
| 1072 | } |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1073 | /** |
| 1074 | * Dump BPF maps |
| 1075 | * |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1076 | * @param pw print writer |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1077 | * @param fd file descriptor to output |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1078 | * @param verbose verbose dump flag, if true dump the BpfMap contents |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1079 | * @throws IOException when file descriptor is invalid. |
| 1080 | * @throws ServiceSpecificException when the method is called on an unsupported device. |
| 1081 | */ |
Junyu Lai | 626045a | 2023-08-28 18:49:44 +0800 | [diff] [blame] | 1082 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1083 | public void dump(final IndentingPrintWriter pw, final FileDescriptor fd, boolean verbose) |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1084 | throws IOException, ServiceSpecificException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 1085 | if (PRE_T) { |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1086 | throw new ServiceSpecificException( |
| 1087 | EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T" |
| 1088 | + " devices, use dumpsys netd trafficcontroller instead."); |
| 1089 | } |
Maciej Żenczykowski | d70a330 | 2023-09-06 16:45:25 +0000 | [diff] [blame] | 1090 | |
| 1091 | pw.println("TrafficController"); // required by CTS testDumpBpfNetMaps |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1092 | |
Motomu Utsumi | 316d057 | 2022-09-15 13:24:48 +0900 | [diff] [blame] | 1093 | pw.println(); |
| 1094 | pw.println("sEnableJavaBpfMap: " + sEnableJavaBpfMap); |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1095 | if (verbose) { |
Motomu Utsumi | ef546a9 | 2022-10-05 16:42:29 +0900 | [diff] [blame] | 1096 | pw.println(); |
| 1097 | pw.println("BPF map content:"); |
| 1098 | pw.increaseIndent(); |
| 1099 | |
Motomu Utsumi | 372c9b4 | 2022-09-02 19:02:56 +0900 | [diff] [blame] | 1100 | dumpOwnerMatchConfig(pw); |
Motomu Utsumi | c675d6f | 2022-09-02 18:15:25 +0900 | [diff] [blame] | 1101 | dumpCurrentStatsMapConfig(pw); |
| 1102 | pw.println(); |
| 1103 | |
Motomu Utsumi | ef546a9 | 2022-10-05 16:42:29 +0900 | [diff] [blame] | 1104 | // TODO: Remove CookieTagMap content dump |
| 1105 | // NetworkStatsService also dumps CookieTagMap and NetworkStatsService is a right place |
| 1106 | // to dump CookieTagMap. But the TagSocketTest in CTS depends on this dump so the tests |
| 1107 | // need to be updated before remove the dump from BpfNetMaps. |
| 1108 | BpfDump.dumpMap(sCookieTagMap, pw, "sCookieTagMap", |
| 1109 | (key, value) -> "cookie=" + key.socketCookie |
| 1110 | + " tag=0x" + Long.toHexString(value.tag) |
| 1111 | + " uid=" + value.uid); |
Motomu Utsumi | 956d86c | 2022-09-02 17:01:25 +0900 | [diff] [blame] | 1112 | BpfDump.dumpMap(sUidOwnerMap, pw, "sUidOwnerMap", |
| 1113 | (uid, match) -> { |
| 1114 | if ((match.rule & IIF_MATCH) != 0) { |
| 1115 | // TODO: convert interface index to interface name by IfaceIndexNameMap |
| 1116 | return uid.val + " " + matchToString(match.rule) + " " + match.iif; |
| 1117 | } else { |
| 1118 | return uid.val + " " + matchToString(match.rule); |
| 1119 | } |
| 1120 | }); |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1121 | BpfDump.dumpMap(sUidPermissionMap, pw, "sUidPermissionMap", |
| 1122 | (uid, permission) -> uid.val + " " + permissionToString(permission.val)); |
Ken Chen | 2433017 | 2023-10-20 13:02:14 +0800 | [diff] [blame^] | 1123 | |
| 1124 | dumpDataSaverConfig(pw); |
Motomu Utsumi | ef546a9 | 2022-10-05 16:42:29 +0900 | [diff] [blame] | 1125 | pw.decreaseIndent(); |
Motomu Utsumi | 310850f | 2022-09-02 12:48:20 +0900 | [diff] [blame] | 1126 | } |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 1127 | } |
| 1128 | |
Maciej Żenczykowski | 70fbfa4 | 2023-07-18 20:14:38 +0000 | [diff] [blame] | 1129 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 3af8f0e | 2022-09-02 23:42:13 +0900 | [diff] [blame] | 1130 | private static native void native_init(boolean startSkDestroyListener); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1131 | |
| 1132 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1133 | private native int native_addNaughtyApp(int uid); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1134 | |
| 1135 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1136 | private native int native_removeNaughtyApp(int uid); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1137 | |
| 1138 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1139 | private native int native_addNiceApp(int uid); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1140 | |
| 1141 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1142 | private native int native_removeNiceApp(int uid); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1143 | |
| 1144 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 114cd9c | 2022-08-01 02:08:35 +0000 | [diff] [blame] | 1145 | private native int native_setChildChain(int childChain, boolean enable); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1146 | |
| 1147 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1148 | private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1149 | |
| 1150 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1151 | private native int native_setUidRule(int childChain, int uid, int firewallRule); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1152 | |
| 1153 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1154 | private native int native_addUidInterfaceRules(String ifName, int[] uids); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1155 | |
| 1156 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1157 | private native int native_removeUidInterfaceRules(int[] uids); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1158 | |
| 1159 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 1160 | private native int native_updateUidLockdownRule(int uid, boolean add); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1161 | |
| 1162 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1163 | private native int native_swapActiveStatsMap(); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1164 | |
| 1165 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 1166 | private native void native_setPermissionForUids(int permissions, int[] uids); |
Maciej Żenczykowski | e7da6fd | 2023-07-18 14:19:19 +0000 | [diff] [blame] | 1167 | |
| 1168 | @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
Motomu Utsumi | 7abeaa4 | 2022-07-20 07:54:18 +0000 | [diff] [blame] | 1169 | private static native int native_synchronizeKernelRCU(); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1170 | } |