netifd: Fix device usage after free
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 4 Aug 2015 14:22:43 +0000 (16:22 +0200)
committerSteven Barth <steven@midlink.org>
Tue, 25 Aug 2015 06:23:29 +0000 (08:23 +0200)
Prevent new device from being freed in device_replace when
device_unlock is called along the function chain triggered
by setting the old device as not present

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
device.c

index 6f31e3687c7fb89015f8c34d364bc1a05f8b9393..59a57f403803e11be4bda2268b11099ebee6ec1f 100644 (file)
--- a/device.c
+++ b/device.c
@@ -704,6 +704,7 @@ device_replace(struct device *dev, struct device *odev)
        struct device_user *dep, *tmp;
        bool present = odev->present;
 
+       __devlock++;
        if (present)
                device_set_present(odev, false);
 
@@ -713,6 +714,8 @@ device_replace(struct device *dev, struct device *odev)
                safe_list_add(&dep->list, &dev->users);
                dep->dev = dev;
        }
+       __devlock--;
+
        device_free(odev);
 
        if (present)