* [PATCH 1/3] spi: fix use-after-free at controller deregistration
@ 2017-10-29 11:56 Johan Hovold
2017-10-31 11:22 ` Applied "spi: fix use-after-free at controller deregistration" to the spi tree Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2017-10-29 11:56 UTC (permalink / raw)
To: Mark Brown
Cc: linux-spi, linux-kernel, Johan Hovold, stable, Suniel Mahesh,
Karthik Tummala
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@vger.kernel.org> # 4.13
Cc: Suniel Mahesh <sunil.m@techveda.org>
Cc: Karthik Tummala <karthik@techveda.org>
Signed-off-by: Johan Hovold <johan@kernel.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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Applied "spi: fix use-after-free at controller deregistration" to the spi tree
2017-10-29 11:56 [PATCH 1/3] spi: fix use-after-free at controller deregistration Johan Hovold
@ 2017-10-31 11:22 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2017-10-31 11:22 UTC (permalink / raw)
To: Johan Hovold
Cc: Mark Brown, stable, Mark Brown, linux-spi, linux-kernel, stable,
Suniel Mahesh, Karthik Tummala, linux-spi
The patch
spi: fix use-after-free at controller deregistration
has been applied to the spi tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
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
>From 67f7b2781fafcc0f52464880154b320fea1ae982 Mon Sep 17 00:00:00 2001
From: Johan Hovold <johan@kernel.org>
Date: Mon, 30 Oct 2017 11:35:25 +0100
Subject: [PATCH] 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>
---
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 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);
--
2.15.0.rc2
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-31 11:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-29 11:56 [PATCH 1/3] spi: fix use-after-free at controller deregistration Johan Hovold
2017-10-31 11:22 ` Applied "spi: fix use-after-free at controller deregistration" to the spi tree Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).