mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
s390/cio: use generic driver_override infrastructure
When a driver is probed through __driver_attach(), the bus' match()
callback is called without the device lock held, thus accessing the
driver_override field without a lock, which can cause a UAF.
Fix this by using the driver-core driver_override infrastructure taking
care of proper locking internally.
Note that calling match() from __driver_attach() without the device lock
held is intentional. [1]
Link: https://lore.kernel.org/driver-core/DGRGTIRHA62X.3RY09D9SOK77P@kernel.org/ [1]
Reported-by: Gui-Dong Han <hanguidong02@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220789
Fixes: ebc3d17915 ("s390/cio: introduce driver_override on the css bus")
Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Link: https://patch.msgid.link/20260324005919.2408620-10-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
@@ -159,7 +159,6 @@ static void css_subchannel_release(struct device *dev)
|
||||
|
||||
sch->config.intparm = 0;
|
||||
cio_commit_config(sch);
|
||||
kfree(sch->driver_override);
|
||||
kfree(sch);
|
||||
}
|
||||
|
||||
@@ -323,37 +322,9 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
|
||||
|
||||
static DEVICE_ATTR_RO(modalias);
|
||||
|
||||
static ssize_t driver_override_store(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct subchannel *sch = to_subchannel(dev);
|
||||
int ret;
|
||||
|
||||
ret = driver_set_override(dev, &sch->driver_override, buf, count);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t driver_override_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct subchannel *sch = to_subchannel(dev);
|
||||
ssize_t len;
|
||||
|
||||
device_lock(dev);
|
||||
len = sysfs_emit(buf, "%s\n", sch->driver_override);
|
||||
device_unlock(dev);
|
||||
return len;
|
||||
}
|
||||
static DEVICE_ATTR_RW(driver_override);
|
||||
|
||||
static struct attribute *subch_attrs[] = {
|
||||
&dev_attr_type.attr,
|
||||
&dev_attr_modalias.attr,
|
||||
&dev_attr_driver_override.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -1356,9 +1327,11 @@ static int css_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
struct subchannel *sch = to_subchannel(dev);
|
||||
const struct css_driver *driver = to_cssdriver(drv);
|
||||
struct css_device_id *id;
|
||||
int ret;
|
||||
|
||||
/* When driver_override is set, only bind to the matching driver */
|
||||
if (sch->driver_override && strcmp(sch->driver_override, drv->name))
|
||||
ret = device_match_driver_override(dev, drv);
|
||||
if (ret == 0)
|
||||
return 0;
|
||||
|
||||
for (id = driver->subchannel_type; id->match_flags; id++) {
|
||||
@@ -1415,6 +1388,7 @@ static int css_uevent(const struct device *dev, struct kobj_uevent_env *env)
|
||||
|
||||
static const struct bus_type css_bus_type = {
|
||||
.name = "css",
|
||||
.driver_override = true,
|
||||
.match = css_bus_match,
|
||||
.probe = css_probe,
|
||||
.remove = css_remove,
|
||||
|
||||
Reference in New Issue
Block a user