From 0bb9c07eba9857030fb685bf5ba24ce519e2f492 Mon Sep 17 00:00:00 2001 From: Sreeram Ramachandran Date: Sun, 27 Jul 2014 00:37:35 -0700 Subject: [PATCH] Prohibit address families by default unless a VPN explicitly allows them. Bug: 15972465 Change-Id: I3278d94536fefacc86390c1ba4231680f7be8589 --- core/java/android/net/NetworkAgent.java | 29 ++++++++++++++ .../android/server/ConnectivityService.java | 38 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java index a365af0f47..22da90e80e 100644 --- a/core/java/android/net/NetworkAgent.java +++ b/core/java/android/net/NetworkAgent.java @@ -106,6 +106,20 @@ public abstract class NetworkAgent extends Handler { */ public static final int EVENT_UID_RANGES_REMOVED = BASE + 6; + /** + * Sent by the NetworkAgent to ConnectivityService to block all routes for a certain address + * family (AF_INET or AF_INET6) on this Network. For VPNs only. + * obj = Integer representing the family (AF_INET or AF_INET6) + */ + public static final int EVENT_BLOCK_ADDRESS_FAMILY = BASE + 7; + + /** + * Sent by the NetworkAgent to ConnectivityService to unblock routes for a certain address + * family (AF_INET or AF_INET6) on this Network. For VPNs only. + * obj = Integer representing the family (AF_INET or AF_INET6) + */ + public static final int EVENT_UNBLOCK_ADDRESS_FAMILY = BASE + 8; + public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, NetworkCapabilities nc, LinkProperties lp, int score) { this(looper, context, logTag, ni, nc, lp, score, null); @@ -228,6 +242,21 @@ public abstract class NetworkAgent extends Handler { queueOrSendMessage(EVENT_UID_RANGES_REMOVED, ranges); } + /** + * Called by the VPN code when it wants to block an address family from being routed, typically + * because the VPN network doesn't support that family. + */ + public void blockAddressFamily(int family) { + queueOrSendMessage(EVENT_BLOCK_ADDRESS_FAMILY, family); + } + + /** + * Called by the VPN code when it wants to unblock an address family from being routed. + */ + public void unblockAddressFamily(int family) { + queueOrSendMessage(EVENT_UNBLOCK_ADDRESS_FAMILY, family); + } + /** * Called when ConnectivityService has indicated they no longer want this network. * The parent factory should (previously) have received indication of the change diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 56265e12da..aa7501b470 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2940,7 +2940,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { } try { mNetd.addVpnUidRanges(nai.network.netId, (UidRange[])msg.obj); - } catch (RemoteException e) { + } catch (Exception e) { + // Never crash! + loge("Exception in addVpnUidRanges: " + e); } break; } @@ -2952,7 +2954,39 @@ public class ConnectivityService extends IConnectivityManager.Stub { } try { mNetd.removeVpnUidRanges(nai.network.netId, (UidRange[])msg.obj); - } catch (RemoteException e) { + } catch (Exception e) { + // Never crash! + loge("Exception in removeVpnUidRanges: " + e); + } + break; + } + case NetworkAgent.EVENT_BLOCK_ADDRESS_FAMILY: { + NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo); + if (nai == null) { + loge("EVENT_BLOCK_ADDRESS_FAMILY from unknown NetworkAgent"); + break; + } + try { + mNetd.blockAddressFamily((Integer) msg.obj, nai.network.netId, + nai.linkProperties.getInterfaceName()); + } catch (Exception e) { + // Never crash! + loge("Exception in blockAddressFamily: " + e); + } + break; + } + case NetworkAgent.EVENT_UNBLOCK_ADDRESS_FAMILY: { + NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo); + if (nai == null) { + loge("EVENT_UNBLOCK_ADDRESS_FAMILY from unknown NetworkAgent"); + break; + } + try { + mNetd.unblockAddressFamily((Integer) msg.obj, nai.network.netId, + nai.linkProperties.getInterfaceName()); + } catch (Exception e) { + // Never crash! + loge("Exception in blockAddressFamily: " + e); } break; }