Greg Kroah-Hartman
2021-Sep-30 17:23 UTC
[PATCH v2 2/6] driver core: Add common support to skip probe for un-authorized devices
On Thu, Sep 30, 2021 at 10:17:09AM -0700, Andi Kleen wrote:> > > > The "it" that I referred to is the claim that no driver should be > > > touching hardware in their module init call. Andi seems to think > > > such drivers are worth working around with a special remap API. > > Andi is wrong. > > While overall it's a small percentage of the total, there are still quite a > few drivers that do touch hardware in init functions. Sometimes for good > reasons -- they need to do some extra probing to discover something that is > not enumerated -- sometimes just because it's very old legacy code that > predates the modern driver model.Are any of them in the kernel today? PCI drivers should not be messing with this, we have had well over a decade to fix that up.> The legacy drivers could be fixed, but nobody really wants to touch them > anymore and they're impossible to test.Pointers to them?> The drivers that probe something that is not enumerated in a standard way > have no choice, it cannot be implemented in a different way.PCI devices are not enumerated in a standard way???> So instead we're using a "firewall" the prevents these drivers from doing > bad things by not allowing ioremap access unless opted in, and also do some > filtering on the IO ports The device filter is still the primary mechanism, > the ioremap filtering is just belts and suspenders for those odd cases.That's horrible, don't try to protect the kernel from itself. Just fix the drivers. If you point me at them, I will be glad to have a look and throw some interns on them. But really, you all could have fixed them up by now if Intel really cared about it :(> If you want we can send an exact list, we did some analysis using a patched > smatch tool.Please do. thanks, greg k-h
Andi Kleen
2021-Sep-30 19:15 UTC
[PATCH v2 2/6] driver core: Add common support to skip probe for un-authorized devices
On 9/30/2021 10:23 AM, Greg Kroah-Hartman wrote:> On Thu, Sep 30, 2021 at 10:17:09AM -0700, Andi Kleen wrote: >>>> The "it" that I referred to is the claim that no driver should be >>>> touching hardware in their module init call. Andi seems to think >>>> such drivers are worth working around with a special remap API. >>> Andi is wrong. >> While overall it's a small percentage of the total, there are still quite a >> few drivers that do touch hardware in init functions. Sometimes for good >> reasons -- they need to do some extra probing to discover something that is >> not enumerated -- sometimes just because it's very old legacy code that >> predates the modern driver model. > Are any of them in the kernel today? > > PCI drivers should not be messing with this, we have had well over a > decade to fix that up.It's not just PCI driver, it's every driver that can do io port / MMIO / MSR / config space accesses. Maybe read the excellent article from Jon on this: https://lwn.net/Articles/865918/> >> The legacy drivers could be fixed, but nobody really wants to touch them >> anymore and they're impossible to test. > Pointers to them?For example if you look over old SCSI drivers in drivers/scsi/*.c there is a substantial number that has a module init longer than just registering a driver. As a single example look at drivers/scsi/BusLogic.c There were also quite a few platform drivers like this.> >> The drivers that probe something that is not enumerated in a standard way >> have no choice, it cannot be implemented in a different way. > PCI devices are not enumerated in a standard way???The pci devices are enumerated in a standard way, but typically the driver also needs something else outside PCI that needs some other probing mechanism.> >> So instead we're using a "firewall" the prevents these drivers from doing >> bad things by not allowing ioremap access unless opted in, and also do some >> filtering on the IO ports The device filter is still the primary mechanism, >> the ioremap filtering is just belts and suspenders for those odd cases. > That's horrible, don't try to protect the kernel from itself. Just fix > the drivers.I thought we had already established this last time we discussed it. That's completely impractical. We cannot harden thousands of drivers, especially since it would be all wasted work since nobody will ever need them in virtual guests. Even if we could harden them how would such a work be maintained long term? Using a firewall and filtering mechanism is much saner for everyone. -Andi
Greg Kroah-Hartman
2021-Oct-01 06:29 UTC
[PATCH v2 2/6] driver core: Add common support to skip probe for un-authorized devices
On Thu, Sep 30, 2021 at 12:15:16PM -0700, Andi Kleen wrote:> > On 9/30/2021 10:23 AM, Greg Kroah-Hartman wrote: > > On Thu, Sep 30, 2021 at 10:17:09AM -0700, Andi Kleen wrote: > > > The legacy drivers could be fixed, but nobody really wants to touch them > > > anymore and they're impossible to test. > > Pointers to them? > > For example if you look over old SCSI drivers in drivers/scsi/*.c there is a > substantial number that has a module init longer than just registering a > driver. As a single example look at drivers/scsi/BusLogic.cGreat, send patches to fix them up instead of adding new infrastructure to the kernel. It is better to remove code than add it. You can rip the ISA code out of that driver and then you will not have the issue anymore. Or again, just add that module to the deny list and never load it from userspace.> There were also quite a few platform drivers like this.Of course, platform drivers are horrible abusers of this. Just like the recent one submitted by Intel that would bind to any machine it was loaded on and did not actually do any hardware detection assuming that it owned the platform: https://lore.kernel.org/r/20210924213157.3584061-2-david.e.box at linux.intel.com So yes, some drivers are horrible, it is our job to catch that and fix it. If you don't want to load those drivers on your system, we have userspace solutions for that (you can have allow/deny lists there.)> > > The drivers that probe something that is not enumerated in a standard way > > > have no choice, it cannot be implemented in a different way. > > PCI devices are not enumerated in a standard way??? > > The pci devices are enumerated in a standard way, but typically the driver > also needs something else outside PCI that needs some other probing > mechanism.Like what? What PCI drivers need outside connections to control the hardware?> > > So instead we're using a "firewall" the prevents these drivers from doing > > > bad things by not allowing ioremap access unless opted in, and also do some > > > filtering on the IO ports The device filter is still the primary mechanism, > > > the ioremap filtering is just belts and suspenders for those odd cases. > > That's horrible, don't try to protect the kernel from itself. Just fix > > the drivers. > > I thought we had already established this last time we discussed it. > > That's completely impractical. We cannot harden thousands of drivers, > especially since it would be all wasted work since nobody will ever need > them in virtual guests. Even if we could harden them how would such a work > be maintained long term? Using a firewall and filtering mechanism is much > saner for everyone.I agree, you can not "harden" anything here. That is why I asked you to use the existing process that explicitly moves the model to userspace where a user can say "do I want this device to be controlled by the kernel or not" which then allows you to pick and choose what drivers you want to have in your system. You need to trust devices, and not worry about trusting drivers as you yourself admit :) The kernel's trust model is that once we bind to them, we trust almost all device types almost explicitly. If you wish to change that model, that's great, but it is a much larger discussion than this tiny patchset would require. thanks, greg k-h