Skip to content

Commit

Permalink
fw/b: Prevent double interface restriction remove on interface name c…
Browse files Browse the repository at this point in the history
…hange

* When temporarily removing a restriction owing to interface name
  change, update the boolean state array to match.  Otherwise, we
  get out of sync, follow-on double removes can occur and the system
  server will crash.

* In addition, it was observed that it is possible to receive a network
  callback for a (VPN) network that has both WIFI and VPN transports set (it
  looked transient rather than persisent but difficult to tell).  So make
  the list of use cases in priority of match order, putting VPN first.

Change-Id: If484b5a715e0a972769c847ea4549fd84afb3ccf
  • Loading branch information
sam3000 authored and PMS22 committed Apr 16, 2020
1 parent 832f885 commit 2cc24ca
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ private static class RestrictIf {

@GuardedBy("mQuotaLock")
private RestrictIf[] mRestrictIf = {
new RestrictIf(RESTRICT_USECASE_DATA, NetworkCapabilities.TRANSPORT_CELLULAR),
// Ordered by match preference (in the event we get a callback with
// multiple transports).
new RestrictIf(RESTRICT_USECASE_VPN, NetworkCapabilities.TRANSPORT_VPN),
new RestrictIf(RESTRICT_USECASE_DATA, NetworkCapabilities.TRANSPORT_CELLULAR),
new RestrictIf(RESTRICT_USECASE_WLAN, NetworkCapabilities.TRANSPORT_WIFI),
};

Expand Down Expand Up @@ -360,6 +362,7 @@ public void onLinkPropertiesChanged(Network network, LinkProperties linkProperti
for (RestrictIf restrictIf : mRestrictIf) {
if (nc.hasTransport(restrictIf.transport)) {
matchedRestrictIf = restrictIf;
break;
}
}
if (matchedRestrictIf == null) {
Expand Down Expand Up @@ -1559,6 +1562,7 @@ private void updateAppOnInterfaceCallback(RestrictIf restrictIf, String newIface
continue;
}
setAppOnInterfaceLocked(restrictIf.useCase, restrictIf.ifName, uid, false);
restrictIf.active.setValueAt(i, false);
// Use pending list to queue re-add.
// (Prefer keeping existing pending status if it exists.)
if (restrictIf.pending.indexOfKey(uid) < 0) {
Expand Down

0 comments on commit 2cc24ca

Please sign in to comment.