Skip to contentSkip to conversation

driver: core: Fix list corruption after device_del()

PATCH In review Takashi Iwai 3 participants 4 messages Dec 8, 2020 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver: core: Fix list corruption after device_del()

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")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index d661ada1518f..e8cb66093f21 100644
@@ -1386,7 +1386,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);
 
 	/*
Signature · 1 line
2.26.2
#1 lore raw
Quoted 25 lines · Takashi Iwai

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")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +0 -0
index d661ada1518f..e8cb66093f21 100644

drivers/base/core.c static void device_links_purge(struct device *dev) · line 1390

Quoted 6 lines
drivers/base/core.c +1 -1
@@ -1386,7 +1386,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);

Can this wait until 5.11-rc1 and then get backported, as it has been around for a while, or are you hitting this on 5.10-rc7 now and need this for 5.10-final?

thanks,

greg k-h

#2 lore raw
Quoted 29 lines · Greg Kroah-Hartman
Quoted 27 lines · Takashi Iwai

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")
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +0 -0
index d661ada1518f..e8cb66093f21 100644
@@ -1386,7 +1386,7 @@ static void device_links_purge(struct device *dev)
 		return;
 
Quoted 8 lines

drivers/base/core.c static void device_links_purge(struct device *dev) · line 1390

Quoted 4 lines
drivers/base/core.c +1 -1
 	mutex_lock(&wfs_lock);
-	list_del(&dev->links.needs_suppliers);
+	list_del_init(&dev->links.needs_suppliers);
 	mutex_unlock(&wfs_lock);

Can this wait until 5.11-rc1 and then get backported, as it has been around for a while, or are you hitting this on 5.10-rc7 now and need this for 5.10-final?

This is rather a minor (but long-standing) issue, so no problem to wait for 5.11.

thanks,

Takashi

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Takashi Iwai
Quoted 10 lines · Takashi Iwai

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.

Quoted 7 lines

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")
Quoted 20 lines
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -2
index d661ada1518f..e8cb66093f21 100644
@@ -1386,7 +1386,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);
 
        /*
--

2.26.2