From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: Michael Kelley <mhklinux@outlook.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
David Lechner <dlechner@baylibre.com>,
Armin Wolf <W_Armin@gmx.de>,
Thierry Reding <thierry.reding@kernel.org>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Karl Mehltretter <kmehltretter@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Marco Elver <elver@google.com>,
Ethan Nelson-Moore <enelsonmoore@gmail.com>,
Jeff Layton <jlayton@kernel.org>,
Bradley Morgan <brads@mainlining.org>,
Andrew Morton <akpm@linux-foundation.org>,
Petr Mladek <pmladek@suse.com>,
Pnina Feder <pnina.feder@mobileye.com>,
Mete Durlu <meted@linux.ibm.com>,
Aaron Tomlin <atomlin@atomlin.com>,
Rio <rioo.tsukatsukii@gmail.com>,
Feng Tang <feng.tang@linux.alibaba.com>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"driver-core@lists.linux.dev" <driver-core@lists.linux.dev>,
"linux-trace-kernel@vger.kernel.org"
<linux-trace-kernel@vger.kernel.org>,
Mark Brown <broonie@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Alex Williamson <alex@shazbot.org>
Subject: Re: [PATCH] driver core: Disable driver overriding by default
Date: Wed, 18 Nov 2026 08:43:46 +0100 [thread overview]
Message-ID: <av1UwuDq9JJkEYkN@monoceros> (raw)
In-Reply-To: <MN2PR02MB6863F6E744D2651D2520A238D47A2@MN2PR02MB6863.namprd02.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 6806 bytes --]
On Wed, Nov 18, 2026 at 05:51:29AM +0000, Michael Kelley wrote:
> From: Uwe Kleine-König <u.kleine-koenig@baylibre.com> 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@shazbot.org/
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@baylibre.com>
> > ---
> > Hello,
> >
> > this is a rebase to current next of the series
> > https://lore.kernel.org/all/cover.1790612298.git.u.kleine-koenig@baylibre.com/
> > . 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2026-11-18 7:43 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
2026-11-18 5:51 ` Michael Kelley
2026-11-18 7:43 ` Uwe Kleine-König [this message]
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=av1UwuDq9JJkEYkN@monoceros \
--to=u.kleine-koenig@baylibre.com \
--cc=W_Armin@gmx.de \
--cc=akpm@linux-foundation.org \
--cc=alex@shazbot.org \
--cc=arnd@arndb.de \
--cc=atomlin@atomlin.com \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=brads@mainlining.org \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=dapeng1.mi@linux.intel.com \
--cc=dlechner@baylibre.com \
--cc=driver-core@lists.linux.dev \
--cc=elver@google.com \
--cc=enelsonmoore@gmail.com \
--cc=feng.tang@linux.alibaba.com \
--cc=gregkh@linuxfoundation.org \
--cc=jlayton@kernel.org \
--cc=johan@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=meted@linux.ibm.com \
--cc=mhiramat@kernel.org \
--cc=mhklinux@outlook.com \
--cc=paulmck@kernel.org \
--cc=pmladek@suse.com \
--cc=pnina.feder@mobileye.com \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rioo.tsukatsukii@gmail.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=thierry.reding@kernel.org \
/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.