net: ipconfig: Fix more use after free
authorThierry Reding <treding@nvidia.com>
Tue, 16 Aug 2016 14:45:38 +0000 (16:45 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 17 Aug 2016 23:33:40 +0000 (19:33 -0400)
While commit 9c706a49d660 ("net: ipconfig: fix use after free") avoids
the use after free, the resulting code still ends up calling both the
ic_setup_if() and ic_setup_routes() after calling ic_close_devs(), and
access to the device is still required.

Move the call to ic_close_devs() to the very end of the function.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ipconfig.c

index 66c2fe602810e7233fe7ff2c8f764f7b8b18eebc..ba9cbeafbb2e081706c40e6236762b411f7ef1f7 100644 (file)
@@ -1530,12 +1530,14 @@ static int __init ip_auto_config(void)
         * Close all network devices except the device we've
         * autoconfigured and set up routes.
         */
-       ic_close_devs();
        if (ic_setup_if() < 0 || ic_setup_routes() < 0)
-               return -1;
+               err = -1;
+       else
+               err = 0;
 
+       ic_close_devs();
 
-       return 0;
+       return err;
 }
 
 late_initcall(ip_auto_config);