driver: core: Fix list corruption after device_del()
authorTakashi Iwai <tiwai@suse.de>
Tue, 8 Dec 2020 19:03:26 +0000 (20:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Dec 2020 18:09:27 +0000 (19:09 +0100)
The device_links_purge() function (called from device_del()) tries to
remove the links.needs_suppliers list entry, but it's using
list_del(), hence it doesn't initialize after the removal.  This is OK
for normal cases where device_del() is called via device_destroy().
However, it's not guaranteed that the device object will be really
deleted soon after device_del().  In a minor case like HD-audio codec
reconfiguration that re-initializes the device after device_del(), it
may lead to a crash by the corrupted list entry.

As a simple fix, replace list_del() with list_del_init() in order to
make the list intact after the device_del() call.

Fixes: e2ae9bcc4aaa ("driver core: Add support for linking devices during device addition")
Cc: <stable@vger.kernel.org>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20201208190326.27531-1-tiwai@suse.de
Cc: Saravana Kannan <saravanak@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c

index 1165a80f8010ec174c4d9c62f1706245292319b0..ba5a3cac6571921e88f50eea9f05cabd6b98113e 100644 (file)
@@ -1384,7 +1384,7 @@ static void device_links_purge(struct device *dev)
                return;
 
        mutex_lock(&wfs_lock);
-       list_del(&dev->links.needs_suppliers);
+       list_del_init(&dev->links.needs_suppliers);
        mutex_unlock(&wfs_lock);
 
        /*