Re: [PATCH v2 00/10] driver core: Disable driver overriding by default
From: Gary Guo
Date: Wed Nov 25 2026 - 21:13:53 EST
On Thu Nov 26, 2026 at 1:57 AM GMT, Gary Guo wrote:
> On Fri Nov 20, 2026 at 11:11 AM GMT, Uwe Kleine-König wrote:
>> Hello,
>>
>> here comes v2 which addresses the review feedback I got for (implicit)
>> v1. See https://lore.kernel.org/linux-kernel/20261116110853.3418077-2-u.kleine-koenig@xxxxxxxxxxxx
>> for the discussion about that previous submission.
>>
>> The objective is to deny force binding a device to a driver that isn't
>> prepared for that. There are many drivers that run in a null pointer
>> exception when this happens and only very few drivers are supposed to be
>> used like that. So the first patch implements an explicit opt-in for
>> drivers and denies other matches; the remaining patches implement the
>> opt-in for drivers that rely on it. This makes it unnecessary to fix
>> individual drivers to explicitly refuse such bindings. See commit
>> 1e50a0349012 ("iio: adc: mcp3564: reject devices without match data")
>> for an example of such a driver-specific fix.
>
> For PCI, there is actually already a mechanism for it -- override_only. VFIO
> devices already have that annotation. I think it's a better mechanism. In
> addition to providing a useful id_info, you can also say what IDs you want the
> override match to become possible.
>
> We can do something like this?
>
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 2398f03a77c1..2cf4659b36a4 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -218,8 +218,8 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
> if (found_id)
> return found_id;
>
> - /* driver_override will always match, send a dummy id */
> - if (ret > 0)
> + /* For a forced driver override, send a dummy id */
> + if (ret > 0 && device_forced_driver_override(dev))
> return &pci_device_id_any;
> return NULL;
> }
>
> Where device_forced_driver_override your added logic about parameter and
> tainting/warning logic.
>
> I suppose the issue is that only CDX and PCI have this mechanism via ID table.
> That said, other buses can gain a bus-specific allow_override field and you just
> do
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 720a72ecd174..7539b43961e6 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -563,7 +563,8 @@ static int spi_match_device(struct device *dev, const struct device_driver *drv)
>
> /* Check override first, and if set, only use the named driver */
> ret = device_match_driver_override(dev, drv);
> - if (ret >= 0)
> + if (ret >= 0 && (sdrv->support_driver_override ||
> + device_force_driver_override(dev, drv)))
> return ret;
To add on this, from
https://lore.kernel.org/all/7008c5ea-58fd-4452-a70a-2162cc3d562b@xxxxxxxxxxxxx/
tt looks like that for some buses, the "driver_override" is a mere preference
mechanism and not forced override, as ID/filter must still match.
I took another look at this direction, and it seems that s390/css, s390/ap, cdx
and vdpa all have this property where forced override wouldn't occur, which is
probably a hint that this direction is worth exploring.
Best,
Gary