Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] driver core: device_match_driver_override() returns -1 instead
of 0
- [High] driver core: disabling driver_override by default breaks
in-tree drivers
- [Low] driver core: allow_driver_override_setup() enables override on
parse error
--
commit 06f24686a63b0776fbdf7d5d7bb34b7905ceba41
Author: Uwe Kleine-König [off-list ref]
driver core: Disable driver overriding by default
This commit disables driver_override matching unless a driver sets
support_driver_override or the allow_driver_override=1 boot parameter is
used, and adds TAINT_DRIVER_OVERRIDE when an unsupported override match is
allowed.
quoted hunk ↗ jump to hunk
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 396097fdb3162..5344b20488fde 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -603,6 +603,56 @@ int bus_add_device(struct device *dev)
return error;
}
+static bool __read_mostly allow_driver_override;
+
+static int __init allow_driver_override_setup(char *str)
+{
+ if (!str || kstrtobool(str, &allow_driver_override) < 0)
+ allow_driver_override = true;
+
+ return 1;
+}
+__setup("allow_driver_override=", allow_driver_override_setup);
[Severity: Low]
Does allow_driver_override_setup() enable allow_driver_override when
kstrtobool() fails? Passing an unrecognized argument such as
allow_driver_override=disabled or allow_driver_override= causes kstrtobool()
to return -EINVAL, setting allow_driver_override to true instead of keeping
it disabled.
quoted hunk ↗ jump to hunk
+
+/**
+ * device_match_driver_override() - Match a driver against the device's driver_override.
+ * @dev: device to check
+ * @drv: driver to match against
+ *
+ * Returns > 0 if a driver override is set and matches the given driver, 0 if a
+ * driver override is set but does not match, or < 0 if a driver override is not
+ * set at all.
+ */
+int device_match_driver_override(struct device *dev,
+ const struct device_driver *drv)
+{
+ guard(spinlock)(&dev->driver_override.lock);
+ if (dev->driver_override.name) {
+ int ret = !strcmp(dev->driver_override.name, drv->name);
+
+ if (ret > 0 && !drv->support_driver_override) {
[Severity: High]
Does rejecting driver_override by default before any in-tree driver sets
support_driver_override break in-kernel callers of
device_set_driver_override() and git bisectability?
Several subsystems call device_set_driver_override() internally to bind
kernel-created devices whose names or ID tables do not match via normal bus
matching. For example, i2s_create_secondary_device() creates a "%s-sec"
platform device, sets its override to "samsung-i2s", and calls
device_attach():
sound/soc/samsung/i2s.c:i2s_create_secondary_device() {
...
ret = device_set_driver_override(&pdev_sec->dev, "samsung-i2s");
...
ret = device_attach(&pdev_sec->dev);
if (ret <= 0) {
platform_device_unregister(priv->pdev_sec);
dev_info(&pdev_sec->dev, "device_attach() failed\n");
return ret;
}
...
}
Because samsung_i2s_driver does not set support_driver_override,
platform_match() fails, device_attach() returns 0 while priv->pdev_sec is
still NULL (leaking pdev_sec), and samsung_i2s_probe() then dereferences
priv->pdev_sec. Other internal users such as imx_clk_scu_alloc_dev() and
rpmsg_ns_register_device() also fail to bind their drivers at boot, and all
VFIO, UIO, and stub driver_override workflows are broken at this commit.
In addition, PCI and CDX drivers that use PCI_DRIVER_OVERRIDE_DEVICE_VFIO()
or CDX_DEVICE_DRIVER_OVERRIDE() rely on device_match_driver_override()
returning > 0 so do_pci_match_id() and cdx_bus_match() match override_only
ID table entries, whereas setting support_driver_override on those drivers
would also allow pci_match_device() to bind arbitrary non-matching devices
via pci_device_id_any without tainting.
quoted hunk ↗ jump to hunk
+ if (allow_driver_override) {
+ add_taint_module(drv->owner,
+ TAINT_DRIVER_OVERRIDE, LOCKDEP_STILL_OK);
+ } else {
+ /*
+ * If you hit this warning and you need to
+ * quickly workaround this check, boot with
+ * allow_driver_override=1 on the kernel
+ * commandline. The right fix is to set the
+ * driver's .support_driver_override property.
+ */
+ dev_warn(dev, "Suppressed driver override binding to %s.\n", drv->name);
+ return -1;
[Severity: High]
Should device_match_driver_override() return 0 rather than -1 when
suppressing a match?
Per the function comment, < 0 means no driver_override is set at all, while
0 means an override is set but does not match drv. Returning -1 for the
matching driver while returning 0 for all other drivers causes callers to
fall through to normal bus matching for the overridden driver:
drivers/vdpa/vdpa.c:vdpa_dev_match() {
int ret;
/* Check override first, and if set, only use the named driver */
ret = device_match_driver_override(dev, drv);
if (ret >= 0)
return ret;
/* Currently devices must be supported by all vDPA bus drivers */
return 1;
}
On vDPA (and similarly in css_bus_match(), ap_device_probe(), and wildcard
PCI drivers), returning -1 logs that the override was suppressed, skips
TAINT_DRIVER_OVERRIDE, and still binds the device to the overridden driver.
And because device_match_driver_override() runs before normal bus matching,
setting driver_override to a driver that also matches the device natively
(such as in of_qcom_slim_ngd_register() or when rebinding a device to its
native driver) either logs a false suppression warning before binding anyway
or taints the kernel with TAINT_DRIVER_OVERRIDE.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116110853.3418077-2-u.kleine-koenig@baylibre.com?part=1