linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/cm: Fix possible use-after-free in ib_cm_cleanup()
@ 2021-10-13  9:30 Wang Hai
  2021-10-13 18:24 ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Wang Hai @ 2021-10-13  9:30 UTC (permalink / raw)
  To: dledford, jgg, leon, markzhang, liangwenpeng, liweihang,
	haakon.bugge, rolandd, sean.hefty
  Cc: linux-rdma, linux-ide, linux-kernel

This module's remove path calls cancel_delayed_work(). However, that
function does not wait until the work function finishes. This means
that the callback function may still be running after the driver's
remove function has finished, which would result in a use-after-free.

Fix by calling cancel_delayed_work_sync(), which ensures that
the work is properly cancelled, no longer running, and unable
to re-schedule itself.

Fixes: 8575329d4f85 ("IB/cm: Fix timewait crash after module unload")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 drivers/infiniband/core/cm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index c903b74f46a4..ae0af63f3271 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -4508,7 +4508,7 @@ static void __exit ib_cm_cleanup(void)
 
 	spin_lock_irq(&cm.lock);
 	list_for_each_entry(timewait_info, &cm.timewait_list, list)
-		cancel_delayed_work(&timewait_info->work.work);
+		cancel_delayed_work_sync(&timewait_info->work.work);
 	spin_unlock_irq(&cm.lock);
 
 	ib_unregister_client(&cm_client);
-- 
2.25.1


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

end of thread, other threads:[~2021-10-14 13:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  9:30 [PATCH] IB/cm: Fix possible use-after-free in ib_cm_cleanup() Wang Hai
2021-10-13 18:24 ` Jason Gunthorpe
2021-10-14 13:19   ` wanghai (M)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).