diff options
author | Johan Hovold <johan@kernel.org> | 2017-10-30 11:35:25 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-10-31 12:09:23 +0100 |
commit | 67f7b2781fafcc0f52464880154b320fea1ae982 (patch) | |
tree | 4ecd11b1646048334b8aae7bc2a5acdb9d918b40 /drivers/spi | |
parent | Linux 4.14-rc1 (diff) | |
download | linux-67f7b2781fafcc0f52464880154b320fea1ae982.tar.xz linux-67f7b2781fafcc0f52464880154b320fea1ae982.zip |
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: 9b61e302210e ("spi: Pick spi bus number from Linux idr or spi alias")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable <stable@vger.kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6e65524cbfd9..759c9725495a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2240,11 +2240,12 @@ static int __unregister(struct device *dev, void *null) void spi_unregister_controller(struct spi_controller *ctlr) { struct spi_controller *found; + int id = ctlr->bus_num; int dummy; /* First make sure that this controller was ever added */ mutex_lock(&board_lock); - found = idr_find(&spi_master_idr, ctlr->bus_num); + found = idr_find(&spi_master_idr, id); mutex_unlock(&board_lock); if (found != ctlr) { dev_dbg(&ctlr->dev, @@ -2264,7 +2265,7 @@ void spi_unregister_controller(struct spi_controller *ctlr) device_unregister(&ctlr->dev); /* free bus id */ mutex_lock(&board_lock); - idr_remove(&spi_master_idr, ctlr->bus_num); + idr_remove(&spi_master_idr, id); mutex_unlock(&board_lock); } EXPORT_SYMBOL_GPL(spi_unregister_controller); |