From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: sashiko-reviews@lists.linux.dev,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] driver core: Disable driver overriding by default
Date: Mon, 16 Nov 2026 16:48:21 +0100 [thread overview]
Message-ID: <avse90uItAVxWnQL@monoceros> (raw)
In-Reply-To: <sashiko-outbox-216950@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 6951 bytes --]
Hello,
On Mon, Nov 16, 2026 at 11:36:25AM +0000, sashiko-bot@kernel.org wrote:
> 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.
I think that's fine. The expected thing happens for
allow_driver_override=1
allow_driver_override=y
allow_driver_override=Y
allow_driver_override=oN
allow_driver_override=0
allow_driver_override=n
allow_driver_override=N
allow_driver_override=oFf
and that
allow_driver_override=disabled
and also
allow_driver_override=Thursday
also enables that override mode is IMHO ok. The documentation only
mentions =1, so I think that's good enough.
> > +
> > +/**
> > + * 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?
It breaks some intended use, yes, and I mentioned in the comment area
after the commit log that a followup is needed for some drivers. IMHO
it's not a big desaster if we miss one or the other, because there is
the kernel cmdline parameter that allows to restore the old behaviour
and catching up is easy.
> 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;
> }
> ...
OK, so samsung_i2s_driver in sound/soc/samsung/i2s.c needs this flag
set, too. Similar:
imx_clk_scu_driver in drivers/clk/imx/clk-scu.c
rpmsg_ctrldev_driver in drivers/rpmsg/rpmsg_ctrl.c
rpmsg_ns_driver in drivers/rpmsg/rpmsg_ns.c
qcom_slim_ngd_driver in drivers/slimbus/qcom-ngd-ctrl.c
vfio_fsl_mc_driver in drivers/vfio/fsl-mc/vfio_fsl_mc.c
> }
>
> 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.
I didn't completely understood that. I think this is remedied by
changing the return -1 that is criticised in the severity high issue
below to 0.
> > + 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;
> }
indeed, returning 0 is more sensible.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-11-16 15:48 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
2026-11-16 15:48 ` Uwe Kleine-König [this message]
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=avse90uItAVxWnQL@monoceros \
--to=u.kleine-koenig@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.