Message ID | ab3c0b18bd820501a12c85e440006e09ec0e275f.1604874488.git.lukas@wunner.de |
---|---|
State | Accepted |
Commit | 4def49da620c84a682d9361d6bef0a97eed46fe0 |
Headers | show |
Series | spi: lpspi: Fix use-after-free on unbind | expand |
On Sun, 8 Nov 2020 23:41:00 +0100, Lukas Wunner wrote: > Normally the last reference on an spi_controller is released by > spi_unregister_controller(). In the case of the i.MX lpspi driver, > the spi_controller is registered with devm_spi_register_controller(), > so spi_unregister_controller() is invoked automatically after the driver > has unbound. > > However the driver already releases the last reference in > fsl_lpspi_remove() through a gratuitous call to spi_master_put(), > causing a use-after-free when spi_unregister_controller() is > subsequently invoked by the devres framework. > > [...] Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next Thanks! [1/1] spi: lpspi: Fix use-after-free on unbind commit: 4def49da620c84a682d9361d6bef0a97eed46fe0 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 986b9793fd3c..a2886ee44e4c 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -938,9 +938,6 @@ static int fsl_lpspi_remove(struct platform_device *pdev) spi_controller_get_devdata(controller); pm_runtime_disable(fsl_lpspi->dev); - - spi_master_put(controller); - return 0; }
Normally the last reference on an spi_controller is released by spi_unregister_controller(). In the case of the i.MX lpspi driver, the spi_controller is registered with devm_spi_register_controller(), so spi_unregister_controller() is invoked automatically after the driver has unbound. However the driver already releases the last reference in fsl_lpspi_remove() through a gratuitous call to spi_master_put(), causing a use-after-free when spi_unregister_controller() is subsequently invoked by the devres framework. Fix by dropping the superfluous spi_master_put(). Fixes: 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi") Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: <stable@vger.kernel.org> # v5.2+ Cc: Han Xu <han.xu@nxp.com> --- drivers/spi/spi-fsl-lpspi.c | 3 --- 1 file changed, 3 deletions(-)