All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] driver core: Use list_del_init to replace list_del at device_links_purge()
@ 2020-01-08 11:34 Luo Jiaxing
  2020-01-08 11:53 ` John Garry
  2020-01-08 12:26 ` Greg KH
  0 siblings, 2 replies; 14+ messages in thread
From: Luo Jiaxing @ 2020-01-08 11:34 UTC (permalink / raw)
  To: gregkh, saravanak, jejb, James.Bottomley, James.Bottomley, john.garry
  Cc: linux-kernel, luojiaxing, linuxarm

We found that enabling kernel compilation options CONFIG_SCSI_ENCLOSURE and
CONFIG_ENCLOSURE_SERVICES, repeated initialization and deletion of the same
SCSI device will cause system panic, as follows:
[72.425705] Unable to handle kernel paging request at virtual address
dead000000000108
...
[72.595093] Call trace:
[72.597532] device_del + 0x194 / 0x3a0
[72.601012] enclosure_remove_device + 0xbc / 0xf8
[72.605445] ses_intf_remove + 0x9c / 0xd8
[72.609185] device_del + 0xf8 / 0x3a0
[72.612576] device_unregister + 0x14 / 0x30
[72.616489] __scsi_remove_device + 0xf4 / 0x140
[72.620747] scsi_remove_device + 0x28 / 0x40
[72.624745] scsi_remove_target + 0x1c8 / 0x220

After analysis, we see that in the error scenario, the ses module has the
following calling sequence:
device_register() -> device_del() -> device_add() -> device_del().
The first call to device_del() is fine, but the second call to device_del()
will cause a system panic.

Through disassembly, we locate that panic happen when device_links_purge()
call list_del() to remove device_links.needs_suppliers from list, and
list_del() will set this list entry's prev and next pointers to poison.
So if INIT_LIST_HEAD() is not re-executed before the next list_del(), It
will cause the system to access a memory address which is posioned.

Therefore, replace list_del() with list_del_init() can avoid such issue.

Fixes: e2ae9bcc4aaa ("driver core: Add support for linking devices during device addition")
Signed-off-by: Luo Jiaxing <luojiaxing@huawei.com>
Reviewed-by: John Garry <john.garry@huawei.com>
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 42a6724..7b9b0d6 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1103,7 +1103,7 @@ static void device_links_purge(struct device *dev)
 	struct device_link *link, *ln;
 
 	mutex_lock(&wfs_lock);
-	list_del(&dev->links.needs_suppliers);
+	list_del_init(&dev->links.needs_suppliers);
 	mutex_unlock(&wfs_lock);
 
 	/*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-01-14 15:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 11:34 [PATCH v1] driver core: Use list_del_init to replace list_del at device_links_purge() Luo Jiaxing
2020-01-08 11:53 ` John Garry
2020-01-08 12:26 ` Greg KH
2020-01-08 14:50   ` John Garry
2020-01-08 15:44     ` Greg KH
2020-01-08 15:51     ` James Bottomley
2020-01-08 15:57       ` Greg KH
2020-01-08 16:01         ` James Bottomley
2020-01-08 16:08           ` John Garry
2020-01-08 17:10             ` John Garry
2020-01-09  1:04               ` James Bottomley
2020-01-14 15:07                 ` Greg KH
2020-01-14 15:20                   ` John Garry
2020-01-14 15:28                     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.