summaryrefslogtreecommitdiff
path: root/tests/unit/java/com/android/server/ConnectivityServiceTest.java
diff options
context:
space:
mode:
authormarkchien <markchien@google.com>2021-09-29 22:57:31 +0800
committermarkchien <markchien@google.com>2022-04-19 19:13:10 +0800
commit28160b3141286f7b579696776fbce7eeeff00b6f (patch)
treecd2d3d6707139b3b5f12e8580afce8509db100d9 /tests/unit/java/com/android/server/ConnectivityServiceTest.java
parentfebcedef5a7cc21e14ec99147e5062f2897566cd (diff)
Fix permission bypass problem for Tethering deprecated APIs
Since the tethering functions in ConnectivityService is delegated to TetheringManager instance and get caches informataion in TetheringManager without checking ACCESS_NETWORK_STATE permission. If application use reflection call getTetherXXX functions in ConnectivityService, it can get tethering status with no additional execution privileges needed. Bug: 162952629 Test: manual Ignore-AOSP-First: security fix Change-Id: I5b897f216db19fead6ba6ac07915aa0f6ff5bf42
Diffstat (limited to 'tests/unit/java/com/android/server/ConnectivityServiceTest.java')
-rw-r--r--tests/unit/java/com/android/server/ConnectivityServiceTest.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index 4c768030f8..a4ee78f3ce 100644
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -16,6 +16,7 @@
package com.android.server;
+import static android.Manifest.permission.ACCESS_NETWORK_STATE;
import static android.Manifest.permission.CHANGE_NETWORK_STATE;
import static android.Manifest.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS;
import static android.Manifest.permission.CONTROL_OEM_PAID_NETWORK_PREFERENCE;
@@ -269,6 +270,7 @@ import android.net.RouteInfo;
import android.net.RouteInfoParcel;
import android.net.SocketKeepalive;
import android.net.TelephonyNetworkSpecifier;
+import android.net.TetheringManager;
import android.net.TransportInfo;
import android.net.UidRange;
import android.net.UidRangeParcel;
@@ -543,6 +545,7 @@ public class ConnectivityServiceTest {
@Mock PacProxyManager mPacProxyManager;
@Mock BpfNetMaps mBpfNetMaps;
@Mock CarrierPrivilegeAuthenticator mCarrierPrivilegeAuthenticator;
+ @Mock TetheringManager mTetheringManager;
// BatteryStatsManager is final and cannot be mocked with regular mockito, so just mock the
// underlying binder calls.
@@ -663,6 +666,7 @@ public class ConnectivityServiceTest {
if (Context.NETWORK_STATS_SERVICE.equals(name)) return mStatsManager;
if (Context.BATTERY_STATS_SERVICE.equals(name)) return mBatteryStatsManager;
if (Context.PAC_PROXY_SERVICE.equals(name)) return mPacProxyManager;
+ if (Context.TETHERING_SERVICE.equals(name)) return mTetheringManager;
return super.getSystemService(name);
}
@@ -15699,4 +15703,36 @@ public class ConnectivityServiceTest {
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), false);
mDefaultNetworkCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
}
+
+ @Test
+ public void testLegacyTetheringApiGuardWithProperPermission() throws Exception {
+ final String testIface = "test0";
+ mServiceContext.setPermission(ACCESS_NETWORK_STATE, PERMISSION_DENIED);
+ assertThrows(SecurityException.class, () -> mService.getLastTetherError(testIface));
+ assertThrows(SecurityException.class, () -> mService.getTetherableIfaces());
+ assertThrows(SecurityException.class, () -> mService.getTetheredIfaces());
+ assertThrows(SecurityException.class, () -> mService.getTetheringErroredIfaces());
+ assertThrows(SecurityException.class, () -> mService.getTetherableUsbRegexs());
+ assertThrows(SecurityException.class, () -> mService.getTetherableWifiRegexs());
+
+ withPermission(ACCESS_NETWORK_STATE, () -> {
+ mService.getLastTetherError(testIface);
+ verify(mTetheringManager).getLastTetherError(testIface);
+
+ mService.getTetherableIfaces();
+ verify(mTetheringManager).getTetherableIfaces();
+
+ mService.getTetheredIfaces();
+ verify(mTetheringManager).getTetheredIfaces();
+
+ mService.getTetheringErroredIfaces();
+ verify(mTetheringManager).getTetheringErroredIfaces();
+
+ mService.getTetherableUsbRegexs();
+ verify(mTetheringManager).getTetherableUsbRegexs();
+
+ mService.getTetherableWifiRegexs();
+ verify(mTetheringManager).getTetherableWifiRegexs();
+ });
+ }
}