]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
rtc: 88pm860x: prevent use-after-free on device remove
authorSven Van Asbroeck <thesven73@gmail.com>
Fri, 26 Apr 2019 18:36:35 +0000 (14:36 -0400)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 29 Apr 2019 13:53:43 +0000 (15:53 +0200)
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>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-88pm860x.c

index d25282b4a7dd1c8798569e79537f9a0682214a30..73697e4b18a9d4d9d85546a1d807a861966df8d8 100644 (file)
@@ -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 */