Commit 148891e9 authored by Gui-Dong Han's avatar Gui-Dong Han Committed by Christophe Leroy (CS GROUP)
Browse files

bus: fsl-mc: fix use-after-free in driver_override_show()



The driver_override_show() function reads the driver_override string
without holding the device_lock. However, driver_override_store() uses
driver_set_override(), which modifies and frees the string while holding
the device_lock.

This can result in a concurrent use-after-free if the string is freed
by the store function while being read by the show function.

Fix this by holding the device_lock around the read operation.

Fixes: 1f86a00c ("bus/fsl-mc: add support for 'driver_override' in the mc-bus")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGui-Dong Han <hanguidong02@gmail.com>
Reviewed-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Link: https://lore.kernel.org/r/20251202174438.12658-1-hanguidong02@gmail.com


Signed-off-by: default avatarChristophe Leroy (CS GROUP) <chleroy@kernel.org>
parent c8dff80a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -231,8 +231,12 @@ static ssize_t driver_override_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
	ssize_t len;

	return sysfs_emit(buf, "%s\n", mc_dev->driver_override);
	device_lock(dev);
	len = sysfs_emit(buf, "%s\n", mc_dev->driver_override);
	device_unlock(dev);
	return len;
}
static DEVICE_ATTR_RW(driver_override);