OSDN Git Service

Patch incoming LinkProperties before it's visible to the outside
authorRubin Xu <rubinxu@google.com>
Mon, 11 Sep 2017 14:21:10 +0000 (15:21 +0100)
committerRubin Xu <rubinxu@google.com>
Tue, 12 Sep 2017 09:18:58 +0000 (10:18 +0100)
Otherwise we risk a race condition when we are fixing the LinkProperties
routes, other parts of ConnectivityService is reading the field at the
same time.

Test: runtest frameworks-net -c com.android.server.ConnectivityServiceTest
Test: runtest frameworks-core -c android.net.LinkPropertiesTest
Bug: 65529483
Bug: 35995111
Change-Id: I539578703570a901e0a5dff0155422ca78c52401

services/core/java/com/android/server/ConnectivityService.java

index 1703bd5..69350b2 100644 (file)
@@ -4641,7 +4641,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
             // Ignore updates for disconnected networks
             return;
         }
-
+        // newLp is already a defensive copy.
+        newLp.ensureDirectlyConnectedRoutes();
         if (VDBG) {
             log("Update of LinkProperties for " + nai.name() +
                     "; created=" + nai.created +
@@ -4651,8 +4652,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
         synchronized (nai) {
             nai.linkProperties = newLp;
         }
-        // msg.obj is already a defensive copy.
-        nai.linkProperties.ensureDirectlyConnectedRoutes();
         if (nai.everConnected) {
             updateLinkProperties(nai, oldLp);
         }