nvme-pci: avoid dereference of symbol from unloaded module
PATCH v2 1/1 nvme-pci: avoid dereference of symbol from unloaded module
The 'remove_work' may be scheduled to run after nvme_remove() returns since we can't simply cancel it in nvme_remove() for avoiding deadlock. Once nvme_remove() returns, this module(nvme) can be unloaded.
On the other hand, nvme_put_ctrl() calls ctr->ops->free_ctrl which may point to nvme_pci_free_ctrl() in unloaded module.
This patch avoids this issue by queuing 'remove_work' via 'nvme_wq', and flush this worqueue in nvme_exit() as suggested by Sagi.
--- drivers/nvme/host/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
@@ -2290,7 +2290,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)nvme_get_ctrl (&dev->ctrl);nvme_dev_disable (dev, false); -if (!schedule_work (&dev->remove_work)) +if (!queue_work (nvme_wq, &dev->remove_work))nvme_put_ctrl (&dev->ctrl); }
@@ -2713,6 +2713,7 @@ static int __init nvme_init(void) static void __exit nvme_exit(void) {pci_unregister_driver (&nvme_driver); +flush_workqueue (nvme_wq);_nvme_check_size (); }
Signature · 1 line
2.9.5
Sagi Grimberg
maintainerPATCH v2 1/1 nvme-pci: avoid dereference of symbol from unloaded module
Thanks Ming,
PATCH v2 1/1 nvme-pci: avoid dereference of symbol from unloaded module
In reply to Ming LeiLooks good, thanks.
PATCH v2 1/1 nvme-pci: avoid dereference of symbol from unloaded module
In reply to Ming LeiThanks,
applied to nvme-4.15.