linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: 88pm860x: prevent use-after-free on device remove
@ 2019-04-26 18:36 Sven Van Asbroeck
  2019-04-26 18:57 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Sven Van Asbroeck @ 2019-04-26 18:36 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

The device's remove() attempts to shut down the delayed_work scheduled
on the kernel-global workqueue by calling flush_scheduled_work().

Unfortunately, flush_scheduled_work() does not prevent the delayed_work
from re-scheduling itself. The delayed_work might run after the device
has been removed, and touch the already de-allocated info structure.
This is a potential use-after-free.

Fix by calling cancel_delayed_work_sync() during remove(): this ensures
that the delayed work is properly cancelled, is no longer running, and
is not able to re-schedule itself.

This issue was detected with the help of Coccinelle.

Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
---
 drivers/rtc/rtc-88pm860x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index d25282b4a7dd..73697e4b18a9 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -421,7 +421,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
 	struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
 
 #ifdef VRTC_CALIBRATION
-	flush_scheduled_work();
+	cancel_delayed_work_sync(&info->calib_work);
 	/* disable measurement */
 	pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
 #endif	/* VRTC_CALIBRATION */
-- 
2.17.1


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

* Re: [PATCH] rtc: 88pm860x: prevent use-after-free on device remove
  2019-04-26 18:36 [PATCH] rtc: 88pm860x: prevent use-after-free on device remove Sven Van Asbroeck
@ 2019-04-26 18:57 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2019-04-26 18:57 UTC (permalink / raw)
  To: Sven Van Asbroeck; +Cc: Alessandro Zummo, linux-rtc, linux-kernel

On 26/04/2019 14:36:35-0400, Sven Van Asbroeck wrote:
> The device's remove() attempts to shut down the delayed_work scheduled
> on the kernel-global workqueue by calling flush_scheduled_work().
> 
> Unfortunately, flush_scheduled_work() does not prevent the delayed_work
> from re-scheduling itself. The delayed_work might run after the device
> has been removed, and touch the already de-allocated info structure.
> This is a potential use-after-free.
> 
> Fix by calling cancel_delayed_work_sync() during remove(): this ensures
> that the delayed work is properly cancelled, is no longer running, and
> is not able to re-schedule itself.
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
> ---
>  drivers/rtc/rtc-88pm860x.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-04-26 18:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 18:36 [PATCH] rtc: 88pm860x: prevent use-after-free on device remove Sven Van Asbroeck
2019-04-26 18:57 ` Alexandre Belloni

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).