OSDN Git Service

Block incoming non-VPN packets to apps under fully-routed VPN
authorRubin Xu <rubinxu@google.com>
Thu, 11 Apr 2019 18:45:43 +0000 (11:45 -0700)
committerRubin Xu <rubinxu@google.com>
Wed, 24 Apr 2019 10:56:46 +0000 (11:56 +0100)
commit9a3f7245979614e9eaa80ccfd4e907a527796da5
tree5ddf8546c8952f221dc1b247ae8d822a96fb5d30
parentc37d832194c9a93a720bf14d0a991377e4d4db53
Block incoming non-VPN packets to apps under fully-routed VPN

When a fully-routed VPN is running, we want to prevent normal apps
under the VPN from receiving packets originating from any local non-VPN
interfaces. This is achieved by using eBPF to create a per-UID input
interface whitelist and populate the whitelist such that all
non-bypassable apps under a VPN can only receive packets from the VPN's
TUN interface (and loopback implicitly)

This is the framework part of the change that build the whitelist.
The whitelist needs to be updated in the following cases:
* When a VPN is connected and disconnected
    This will cover the change to allowBypass bit, since that can't be
    changed without reconnecting.
* When a VPN's NetworkCapabilites is changed (whitelist/blacklist app changes)
* When a new app is installed
* When an existing app is removed
* When a VPN becomes fully-routed or is no longer fully-routed

New user/profile creation will automatically result in a whitelist app change
transition so it doesn't need to be handled specially here.

Due to the limitation of the kernel IPSec interacting with eBPF (sk_buf->ifindex
does not point to the virtual tunnel interface for kernel IPSec), the whitelist
will only apply to app VPNs but not legacy VPN connections, to prevent breaking
connectivity with kernel IPSec entirely.

Test: atest PermissionMonitorTest
Test: atest android.net.RouteInfoTest
Test: atest com.android.server.ConnectivityServiceTest
Test: atest HostsideVpnTests
Bug: 114231106

Merged-In: I5af81bc80dadd086261ba4b1eb706cc873bb7cfa
Change-Id: I5af81bc80dadd086261ba4b1eb706cc873bb7cfa
(cherry picked from commit 65968ea16bf49f678d4a43c220e1d67393170459)
core/java/android/net/NetworkCapabilities.java
core/java/android/net/UidRange.java
services/core/java/com/android/server/ConnectivityService.java
services/core/java/com/android/server/connectivity/PermissionMonitor.java
services/core/java/com/android/server/connectivity/Vpn.java
tests/net/java/android/net/RouteInfoTest.java
tests/net/java/com/android/server/ConnectivityServiceTest.java
tests/net/java/com/android/server/connectivity/PermissionMonitorTest.java