Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 67f7b278 authored by Johan Hovold's avatar Johan Hovold Committed by Mark Brown
Browse files

spi: fix use-after-free at controller deregistration



The controller is typically freed as part of device_unregister() so
store the bus id before deregistration to avoid use-after-free when the
id is later released.

Fixes: 9b61e302 ("spi: Pick spi bus number from Linux idr or spi alias")
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Cc: stable <stable@vger.kernel.org>
parent 2bd6bf03
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -2240,11 +2240,12 @@ static int __unregister(struct device *dev, void *null)
void spi_unregister_controller(struct spi_controller *ctlr)
void spi_unregister_controller(struct spi_controller *ctlr)
{
{
	struct spi_controller *found;
	struct spi_controller *found;
	int id = ctlr->bus_num;
	int dummy;
	int dummy;


	/* First make sure that this controller was ever added */
	/* First make sure that this controller was ever added */
	mutex_lock(&board_lock);
	mutex_lock(&board_lock);
	found = idr_find(&spi_master_idr, ctlr->bus_num);
	found = idr_find(&spi_master_idr, id);
	mutex_unlock(&board_lock);
	mutex_unlock(&board_lock);
	if (found != ctlr) {
	if (found != ctlr) {
		dev_dbg(&ctlr->dev,
		dev_dbg(&ctlr->dev,
@@ -2264,7 +2265,7 @@ void spi_unregister_controller(struct spi_controller *ctlr)
	device_unregister(&ctlr->dev);
	device_unregister(&ctlr->dev);
	/* free bus id */
	/* free bus id */
	mutex_lock(&board_lock);
	mutex_lock(&board_lock);
	idr_remove(&spi_master_idr, ctlr->bus_num);
	idr_remove(&spi_master_idr, id);
	mutex_unlock(&board_lock);
	mutex_unlock(&board_lock);
}
}
EXPORT_SYMBOL_GPL(spi_unregister_controller);
EXPORT_SYMBOL_GPL(spi_unregister_controller);