Skip to content

Commit 1d6bd61

Browse files
2045castorgregkh
authored andcommitted
bus: fsl-mc: fix use-after-free in driver_override_show()
commit 148891e upstream. 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: 1f86a00 ("bus/fsl-mc: add support for 'driver_override' in the mc-bus") Cc: stable@vger.kernel.org Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com> Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com> Link: https://lore.kernel.org/r/20251202174438.12658-1-hanguidong02@gmail.com Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d14e991 commit 1d6bd61

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/bus/fsl-mc/fsl-mc-bus.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ static ssize_t driver_override_show(struct device *dev,
202202
struct device_attribute *attr, char *buf)
203203
{
204204
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
205+
ssize_t len;
205206

206-
return sysfs_emit(buf, "%s\n", mc_dev->driver_override);
207+
device_lock(dev);
208+
len = sysfs_emit(buf, "%s\n", mc_dev->driver_override);
209+
device_unlock(dev);
210+
return len;
207211
}
208212
static DEVICE_ATTR_RW(driver_override);
209213

0 commit comments

Comments
 (0)