[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171030103527.13535-1-johan@kernel.org>
Date: Mon, 30 Oct 2017 11:35:25 +0100
From: Johan Hovold <johan@...nel.org>
To: Mark Brown <broonie@...nel.org>
Cc: linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org,
Lars-Peter Clausen <lars@...afoo.de>,
Johan Hovold <johan@...nel.org>,
stable <stable@...r.kernel.org>,
Suniel Mahesh <sunil.m@...hveda.org>,
Karthik Tummala <karthik@...hveda.org>
Subject: [PATCH v2 1/3] 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")
Cc: stable <stable@...r.kernel.org> # 4.13
Cc: Suniel Mahesh <sunil.m@...hveda.org>
Cc: Karthik Tummala <karthik@...hveda.org>
Signed-off-by: Johan Hovold <johan@...nel.org>
---
drivers/spi/spi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index e8b5a5e21b2e..3ff0ee88c467 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2245,11 +2245,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,
@@ -2269,7 +2270,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);
--
2.14.3
Powered by blists - more mailing lists