iio: adc: xilinx: fix potential use-after-free on remove
Subsystems (2)
PATCH 1/3 iio: adc: xilinx: fix potential use-after-free on remove
When cancel_delayed_work() returns, the delayed work may still be running. This means that the core could potentially free the private structure (struct xadc) while the delayed work is still using it. This is a potential use-after-free.
Fix by calling cancel_delayed_work_sync(), which waits for any residual work to finish before returning.
--- drivers/iio/adc/xilinx-xadc-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/xilinx-xadc-core.c +1 -1
@@ -1320,7 +1320,7 @@ static int xadc_remove(struct platform_device *pdev) }free_irq (xadc->irq, indio_dev);clk_disable_unprepare (xadc->clk); -cancel_delayed_work (&xadc->zynq_unmask_work); +cancel_delayed_work_sync (&xadc->zynq_unmask_work);kfree (xadc->data);kfree (indio_dev->channels);
Signature · 1 line
2.17.1
PATCH 2/3 iio: adc: xilinx: fix potential use-after-free on probe
If probe errors out after request_irq(), its error path does not explicitly cancel the delayed work, which may have been scheduled by the interrupt handler.
This means the delayed work may still be running when the core frees the private structure (struct xadc). This is a potential use-after-free.
Fix by inserting cancel_delayed_work_sync() in the probe error path.
--- drivers/iio/adc/xilinx-xadc-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/adc/xilinx-xadc-core.c +1 -0
@@ -1290,6 +1290,7 @@ static int xadc_probe(struct platform_device *pdev) err_free_irq:free_irq (xadc->irq, indio_dev); +cancel_delayed_work_sync (&xadc->zynq_unmask_work); err_clk_disable_unprepare:clk_disable_unprepare (xadc->clk); err_free_samplerate_trigger:
Signature · 1 line
2.17.1
Re: [PATCH 2/3] iio: adc: xilinx: fix potential use-after-free on probe
Quoted 4 lines · On Sun, 10 Mar 2019 14:58:25 -0400 Sven Van Asbroeck <[email protected]>…
If probe errors out after
request_irq(), its error path does not explicitly cancel the delayed work, which may have been scheduled by the interrupt handler.
Quoted 8 lines
This means the delayed work may still be running when the core frees the private structure (struct xadc). This is a potential use-after-free.
Fix by inserting
cancel_delayed_work_sync()in the probe error path.Signed-off-by Sven Van Asbroeck <[email protected]>
Again, seems fine to me.
Applied to the fixes-togreg branch of iio.git.
thanks,
Jonathan
Quoted 16 lines
--- drivers/iio/adc/xilinx-xadc-core.c | 1 + 1 file changed, 1 insertion(+)drivers/iio/adc/xilinx-xadc-core.c +1
-0@@ -1290,6 +1290,7 @@ static int xadc_probe(struct platform_device *pdev) err_free_irq:free_irq (xadc->irq, indio_dev); +cancel_delayed_work_sync (&xadc->zynq_unmask_work); err_clk_disable_unprepare:clk_disable_unprepare (xadc->clk); err_free_samplerate_trigger:
PATCH 3/3 iio: adc: xilinx: prevent touching unclocked h/w on remove
In reply to Sven Van AsbroeckIn remove, the clock is disabled before canceling the delayed work. This means that the delayed work may be touching unclocked hardware.
Fix by disabling the clock after the delayed work is fully canceled. This is consistent with the probe error path order.
--- drivers/iio/adc/xilinx-xadc-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/xilinx-xadc-core.c +1 -1
@@ -1320,8 +1320,8 @@ static int xadc_remove(struct platform_device *pdev)iio_triggered_buffer_cleanup (indio_dev); }free_irq (xadc->irq, indio_dev); -clk_disable_unprepare (xadc->clk);cancel_delayed_work_sync (&xadc->zynq_unmask_work); +clk_disable_unprepare (xadc->clk);kfree (xadc->data);kfree (indio_dev->channels);
Signature · 1 line
2.17.1
Re: [PATCH 3/3] iio: adc: xilinx: prevent touching unclocked h/w on remove
Quoted 9 lines · On Sun, 10 Mar 2019 14:58:26 -0400 Sven Van Asbroeck <[email protected]>…
In remove, the clock is disabled before canceling the delayed work. This means that the delayed work may be touching unclocked hardware.
Fix by disabling the clock after the delayed work is fully canceled. This is consistent with the probe error path order.
Signed-off-by Sven Van Asbroeck <[email protected]>
Applied to the fixes-togreg branch of iio.git.
Thanks,
Jonathan
Quoted 18 lines
--- drivers/iio/adc/xilinx-xadc-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/xilinx-xadc-core.c +1
-1@@ -1320,8 +1320,8 @@ static int xadc_remove(struct platform_device *pdev)iio_triggered_buffer_cleanup (indio_dev); }free_irq (xadc->irq, indio_dev); -clk_disable_unprepare (xadc->clk);cancel_delayed_work_sync (&xadc->zynq_unmask_work); +clk_disable_unprepare (xadc->clk);kfree (xadc->data);kfree (indio_dev->channels);
Re: [PATCH 3/3] iio: adc: xilinx: prevent touching unclocked h/w on remove
Quoted 3 lines · Jonathan Cameron
Applied to the fixes-togreg branch of iio.git.
Thank you kindly for taking this patch set, Jonathan.
Quoted 9 lines · On Sun, 10 Mar 2019 14:58:24 -0400 Sven Van Asbroeck <[email protected]>…
When
cancel_delayed_work()returns, the delayed work may still be running. This means that the core could potentially free the private structure (struct xadc) while the delayed work is still using it. This is a potential use-after-free.Fix by calling
cancel_delayed_work_sync(), which waits for any residual work to finish before returning.Signed-off-by Sven Van Asbroeck <[email protected]>
This appears 'obviously correct' to me so I'll apply it to the fixes togreg branch of iio.git and mark it for stable.
However I won't be sending a pull request for that branch until at least next weekend, so if anyone more familiar with the hardware has a chance to take a look that would be great.
Applied to the fixes-togreg branch of iio.git.
Thanks,
Jonathan
Quoted 17 lines
--- drivers/iio/adc/xilinx-xadc-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/xilinx-xadc-core.c +1
-1@@ -1320,7 +1320,7 @@ static int xadc_remove(struct platform_device *pdev) }free_irq (xadc->irq, indio_dev);clk_disable_unprepare (xadc->clk); -cancel_delayed_work (&xadc->zynq_unmask_work); +cancel_delayed_work_sync (&xadc->zynq_unmask_work);kfree (xadc->data);kfree (indio_dev->channels);