Skip to contentSkip to conversation

bus: mhi: pci_generic: Fix possible use-after-free in mhi_pci_remove()

PATCH Applied Wei Yongjun 4 participants 6 messages Apr 13, 2021 – May 21, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: mhi: pci_generic: Fix possible use-after-free in mhi_pci_remove()

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

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")
---
 drivers/bus/mhi/pci_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/mhi/pci_generic.c +1 -1
index 7c810f02a2ef..5b19e877d17a 100644
@@ -708,7 +708,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
 	struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev);
 	struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
 
-	del_timer(&mhi_pdev->health_check_timer);
+	del_timer_sync(&mhi_pdev->health_check_timer);
 	cancel_work_sync(&mhi_pdev->recovery_work);
 
 	if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Wei Yongjun

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

Quoted 6 lines

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Wei Yongjun
Quoted 11 lines · Wei Yongjun

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

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Wei Yongjun
Quoted 11 lines · Wei Yongjun

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

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")

Loic, could you please review this patch as well?

Thanks,
Mani

Quoted 18 lines
---
 drivers/bus/mhi/pci_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/mhi/pci_generic.c +1 -1
index 7c810f02a2ef..5b19e877d17a 100644
@@ -708,7 +708,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
 	struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev);
 	struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
 
-	del_timer(&mhi_pdev->health_check_timer);
+	del_timer_sync(&mhi_pdev->health_check_timer);
 	cancel_work_sync(&mhi_pdev->recovery_work);
 
 	if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
#4 lore raw
Quoted 9 lines · Manivannan Sadhasivam
Quoted 8 lines · Wei Yongjun

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

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Quoted 8 lines
Quoted 3 lines
Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")

Loic, could you please review this patch as well?

Nvm, Loic did review the patch.

Thanks,
Mani

Quoted 21 lines

Thanks,
Mani

Quoted 18 lines
---
 drivers/bus/mhi/pci_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/mhi/pci_generic.c +1 -1
index 7c810f02a2ef..5b19e877d17a 100644
@@ -708,7 +708,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
 	struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev);
 	struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
 
-	del_timer(&mhi_pdev->health_check_timer);
+	del_timer_sync(&mhi_pdev->health_check_timer);
 	cancel_work_sync(&mhi_pdev->recovery_work);
 
 	if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
maintainer Applied
#5 lore raw
In reply to Wei Yongjun
Quoted 11 lines · Wei Yongjun

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

Fix by calling del_timer_sync(), which makes sure the timer handler has finished, and unable to re-schedule itself.

Fixes 8562d4fe34a3 ("mhi: pci_generic: Add health-check")

Applied to mhi-fixes!

Thanks,
Mani

Quoted 18 lines
---
 drivers/bus/mhi/pci_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/mhi/pci_generic.c +1 -1
index 7c810f02a2ef..5b19e877d17a 100644
@@ -708,7 +708,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
 	struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev);
 	struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
 
-	del_timer(&mhi_pdev->health_check_timer);
+	del_timer_sync(&mhi_pdev->health_check_timer);
 	cancel_work_sync(&mhi_pdev->recovery_work);
 
 	if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {