Re: [PATCH] driver core: Disable driver overriding by default
From: Uwe Kleine-König
Date: Wed Nov 18 2026 - 02:43:56 EST
On Wed, Nov 18, 2026 at 05:51:29AM +0000, Michael Kelley wrote:
> From: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx> Sent: Monday, November 16, 2026 3:09 AM
> >
> > Driver overriding is useful only in a very limited set of situations
> > and then only with very few drivers that are designed to support that.
> >
> > Disallow matching via driver_override unless the driver explicitly
> > allows it or the safe guard is disabled using the
> > "allow_driver_override=1" kernel parameter.
> >
> > There are many drivers that don't expect to be force-bound and often
> > doing it anyhow results in a NULL pointer exception. To make debugging
> > such cases easier, add a new taint if such a forced match happens.
>
> As noted by Alex Williamson [1], there's also the new_id mechanism
> that can force bogus matches and result in the same kind of NULL
> pointer exceptions. What's your thinking about covering that case
> as well?
>
> [1] https://lore.kernel.org/lkml/20261028094139.12ea7c16@xxxxxxxxxxx/
I didn't look into pci's new_id a lot. It sounds as if it should also be
guarded with a similar mechanism as the one from this patch for
driver_override. As my experience and testing capability with PCI is
limited, I'd not add it to this effort, but leave it for someone in a
better position than me.
> > Implementation detail: device_match_driver_override() isn't a static
> > inline any more. It grew a certain complexity (e.g. a pr_info()) and so
> > was made a regular exported function.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx>
> > ---
> > Hello,
> >
> > this is a rebase to current next of the series
> > https://lore.kernel.org/all/cover.1790612298.git.u.kleine-koenig@xxxxxxxxxxxx/
> > . It combines the functionality of former patches #2 and #3 (#1 was a
> > fix that was already applied). I also addressed sashiko's comments. I think
> > this matches what most people want in the previous discussion.
> >
> > As the rebase wasn't trivial and I merged the two patches, I didn't
> > apply the review tags I already received for v3.
> >
> > If this patch is accepted, a number of drivers that are supposed to be
> > force-bound need to get their .support_driver_override property set. I'm
> > aware of the following:
> >
> > - spidev_spi_driver in drivers/spi/spidev.c
> > - stub_driver in drivers/pci/pci-stub.c
> > - uio_dmem_genirq in drivers/uio/uio_dmem_genirq.c
> > - uio_pci_driver in drivers/uio/uio_pci_generic.c
> > - uio_pdrv_genirq in drivers/uio/uio_pdrv_genirq.c
> > - vfio_amba_driver in drivers/vfio/platform/vfio_amba.c
> > - vfio_ccw_sch_driver in drivers/s390/cio/vfio_ccw_drv.c
> > - vfio_pci_driver in drivers/vfio/pci/vfio_pci.c
> > - vfio_platform_driver in drivers/vfio/platform/vfio_platform.c
>
> drivers/uio/uio_hv_generic.c also probably needs to be in this list.
> It's used for running DPDK against the Hyper-V VMBus synthetic
> NIC device.
Noted.
> [...]
> > +static bool __read_mostly allow_driver_override;
> > +
> > +static int __init allow_driver_override_setup(char *str)
> > +{
> > + if (!str || kstrtobool(str, &allow_driver_override) < 0)
>
> If the kernel boot line parameter has a bogus value that doesn't
> map to "true" or "false", kstrtobool returns -EINVAL and
> allow_driver_override is set to true. Seems like a bogus value
> should default to false. If no value at all is supplied and str
> is NULL, it's debatable as to whether defaulting to true is OK.
> Seems like might want to insist on a value that indicates
> "true".
Well, the default without passing allow_driver_override=$anything is
false. Initially I wanted to have just
allow_driver_override
on the commandline to disable the safe-guard but sashiko wailed about it
(well, more about how I implemented it). Maybe I'm going back to that
approach.
> > + allow_driver_override = true;
> > +
> > + return 1;
> > +}
> > +__setup("allow_driver_override=", allow_driver_override_setup);
> > +
> > +/**
> > + * 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.
>
> Additionally, returns < 0 if a matching override exists but is disallowed.
Yeah, that comment is just taken unmodified from the old location of
device_match_driver_override(). Indeed needs adaption.
> > + */
> > +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) {
>
> Using "ret > 0" seems a bit odd since the value is essentially Boolean.
> Suggest using just "ret".
ok
> > + 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);
>
> Maybe "Disallowed" instead of "Suppressed" in the message? Even better,
> could the name of the device be provided? For example,
>
> "Disallowed bind of driver %s to device %s using driver override"
dev_warn() emits the device name.
> [...]
> > diff --git a/tools/debugging/kernel-chktaint b/tools/debugging/kernel-chktaint
> > index e1571c04afb5..56215e0f5112 100755
> > --- a/tools/debugging/kernel-chktaint
> > +++ b/tools/debugging/kernel-chktaint
> > @@ -211,6 +211,15 @@ else
> > addout "J"
> > echo " * fwctl's mutating debug interface was used (#19)"
> > fi
> > +
> > +T=`expr $T / 2`
> > +if [ `expr $T % 2` -eq 0 ]; then
> > + addout " "
> > +else
> > + addout "Z"
> > + echo " * A device was matched using driver_override to a driver not supporting that (#20)"
>
> The messages in kernel-chktaint usually word-for-word match the text
> in Documentation/admin-guide/tainted-kernels.rst. Any reason not to
> do the same for this one?
no, will adapt.
> > +fi
> > +
> > echo "Raw taint value as int/string: $taint/'$out'"
> >
> > # report on any tainted loadable modules
Thanks for the feedback.
Uwe
Attachment:
signature.asc
Description: PGP signature