All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] driver core: Disable driver overriding by default
Date: Mon, 16 Nov 2026 11:36:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-216950@kernel.org> (raw)
In-Reply-To: <20261116110853.3418077-2-u.kleine-koenig@baylibre.com>

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 <u.kleine-koenig@baylibre.com>

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.

> 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.

> +
> +/**
> + * 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.

> +			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

  reply	other threads:[~2026-11-16 11:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 11:08 [PATCH] driver core: Disable driver overriding by default Uwe Kleine-König
2026-11-16 11:36 ` sashiko-bot [this message]
2026-11-16 15:48   ` Uwe Kleine-König
2026-11-18  5:51 ` Michael Kelley
2026-11-18  7:43   ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-216950@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.