Skip to contentSkip to conversation

Patch "spi: fix use-after-free at controller deregistration" has been added to the 4.14-stable tree

PATCH [email protected] 1 participant 1 message Nov 19, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

spi: fix use-after-free at controller deregistration

to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
spi-fix-use-after-free-at-controller-deregistration.patch
and it can be found in the queue-4.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 67f7b2781fafcc0f52464880154b320fea1ae982 Mon Sep 17 00:00:00 2001

From: Johan Hovold <[email protected]>
Date: Mon, 30 Oct 2017 11:35:25 +0100
Subject: spi: fix use-after-free at controller deregistration

From: Johan Hovold <[email protected]>

commit 67f7b2781fafcc0f52464880154b320fea1ae982 upstream.

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")
---
 drivers/spi/spi.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi.c +3 -2
@@ -2245,11 +2245,12 @@ static int __unregister(struct device *d
 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 sp
 	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);

Patches currently in stable-queue which might be from [email protected] are

queue-4.14/usb-serial-qcserial-add-pid-vid-for-sierra-wireless-em7355-fw-update.patch queue-4.14/staging-greybus-spilib-fix-use-after-free-after-deregistration.patch queue-4.14/usb-serial-metro-usb-stop-i-o-after-failed-open.patch queue-4.14/usb-serial-change-dbc-debug-device-binding-id.patch queue-4.14/spi-fix-use-after-free-at-controller-deregistration.patch queue-4.14/usb-serial-garmin_gps-fix-i-o-after-failed-probe-and-remove.patch queue-4.14/usb-serial-garmin_gps-fix-memory-leak-on-probe-errors.patch