]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
amba: use generic driver_override infrastructure
authorDanilo Krummrich <dakr@kernel.org>
Tue, 5 May 2026 13:37:21 +0000 (15:37 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Sat, 30 May 2026 20:25:23 +0000 (22:25 +0200)
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/
Reported-by: Gui-Dong Han <hanguidong02@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220789
Fixes: 3cf385713460 ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260505133935.3772495-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/amba/bus.c
include/linux/amba/bus.h

index 6d479caf89cbd7ecea130da028b82d8d90d2015c..d721d64a9858034fc1075296cb7ceb835ad22890 100644 (file)
@@ -82,33 +82,6 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
 }
 
 
-static ssize_t driver_override_show(struct device *_dev,
-                                   struct device_attribute *attr, char *buf)
-{
-       struct amba_device *dev = to_amba_device(_dev);
-       ssize_t len;
-
-       device_lock(_dev);
-       len = sprintf(buf, "%s\n", dev->driver_override);
-       device_unlock(_dev);
-       return len;
-}
-
-static ssize_t driver_override_store(struct device *_dev,
-                                    struct device_attribute *attr,
-                                    const char *buf, size_t count)
-{
-       struct amba_device *dev = to_amba_device(_dev);
-       int ret;
-
-       ret = driver_set_override(_dev, &dev->driver_override, buf, count);
-       if (ret)
-               return ret;
-
-       return count;
-}
-static DEVICE_ATTR_RW(driver_override);
-
 #define amba_attr_func(name,fmt,arg...)                                        \
 static ssize_t name##_show(struct device *_dev,                                \
                           struct device_attribute *attr, char *buf)    \
@@ -126,7 +99,6 @@ amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n",
 static struct attribute *amba_dev_attrs[] = {
        &dev_attr_id.attr,
        &dev_attr_resource.attr,
-       &dev_attr_driver_override.attr,
        NULL,
 };
 ATTRIBUTE_GROUPS(amba_dev);
@@ -209,10 +181,11 @@ static int amba_match(struct device *dev, const struct device_driver *drv)
 {
        struct amba_device *pcdev = to_amba_device(dev);
        const struct amba_driver *pcdrv = to_amba_driver(drv);
+       int ret;
 
        mutex_lock(&pcdev->periphid_lock);
        if (!pcdev->periphid) {
-               int ret = amba_read_periphid(pcdev);
+               ret = amba_read_periphid(pcdev);
 
                /*
                 * Returning any error other than -EPROBE_DEFER from bus match
@@ -230,8 +203,9 @@ static int amba_match(struct device *dev, const struct device_driver *drv)
        mutex_unlock(&pcdev->periphid_lock);
 
        /* When driver_override is set, only bind to the matching driver */
-       if (pcdev->driver_override)
-               return !strcmp(pcdev->driver_override, drv->name);
+       ret = device_match_driver_override(dev, drv);
+       if (ret >= 0)
+               return ret;
 
        return amba_lookup(pcdrv->id_table, pcdev) != NULL;
 }
@@ -436,6 +410,7 @@ static const struct dev_pm_ops amba_pm = {
 const struct bus_type amba_bustype = {
        .name           = "amba",
        .dev_groups     = amba_dev_groups,
+       .driver_override = true,
        .match          = amba_match,
        .uevent         = amba_uevent,
        .probe          = amba_probe,
index 9946276aff73779435fc42b7a44f0717944e3e1a..6c54d5c0d21f7ffd789898b4758d75813afa49f3 100644 (file)
@@ -71,11 +71,6 @@ struct amba_device {
        unsigned int            cid;
        struct amba_cs_uci_id   uci;
        unsigned int            irq[AMBA_NR_IRQS];
-       /*
-        * Driver name to force a match.  Do not set directly, because core
-        * frees it.  Use driver_set_override() to set or clear it.
-        */
-       const char              *driver_override;
 };
 
 struct amba_driver {