Skip to content

Commit

Permalink
spi: pxa2xx: Fix use-after-free on unbind
Browse files Browse the repository at this point in the history
commit 5626308 upstream.

pxa2xx_spi_remove() accesses the driver's private data after calling
spi_unregister_controller() even though that function releases the last
reference on the spi_controller and thereby frees the private data.

Fix by switching over to the new devm_spi_alloc_master/slave() helper
which keeps the private data accessible until the driver has unbound.

Fixes: 32e5b57 ("spi: pxa2xx: Fix controller unregister order")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: <stable@vger.kernel.org> # v2.6.17+: 5e844cc: spi: Introduce device-managed SPI controller allocation
Cc: <stable@vger.kernel.org> # v2.6.17+: 32e5b57: spi: pxa2xx: Fix controller unregister order
Cc: <stable@vger.kernel.org> # v2.6.17+
Link: https://lore.kernel.org/r/5764b04d4a6e43069ebb7808f64c2f774ac6f193.1607286887.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
l1k authored and gregkh committed Dec 30, 2020
1 parent c5ae864 commit 17360c3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/spi/spi-pxa2xx.c
Expand Up @@ -1675,9 +1675,9 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
}

if (platform_info->is_slave)
controller = spi_alloc_slave(dev, sizeof(struct driver_data));
controller = devm_spi_alloc_slave(dev, sizeof(*drv_data));
else
controller = spi_alloc_master(dev, sizeof(struct driver_data));
controller = devm_spi_alloc_master(dev, sizeof(*drv_data));

if (!controller) {
dev_err(&pdev->dev, "cannot alloc spi_controller\n");
Expand Down Expand Up @@ -1900,7 +1900,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
free_irq(ssp->irq, drv_data);

out_error_controller_alloc:
spi_controller_put(controller);
pxa_ssp_free(ssp);
return status;
}
Expand Down

0 comments on commit 17360c3

Please sign in to comment.