Linux Accidentally Left Legacy I/O & Memory Handlers Open In Kernel Lockdown Mode

Linux Accidentally Left Legacy I/O & Memory Handlers Open In Kernel Lockdown Mode

For nearly the past decade has been the kernel lockdown mode for tightening up kernel access from user-space such as when UEFI Secure Boot is enabled. The kernel lockdown mode restricts PCI BAR access, no writing to /dev/mem, and other restrictions so user-space can't can't modify the running kernel or access sensitive kernel memory. An oversight has allowed legacy I/O and memory interfaces via sysfs to remain open in lockdown mode, but a fix is on the way. Back in 2022 there was a trivial lockdown bypass bug while the latest accident in the kernel lockdown arena is the legacy_io and legacy_mem sysfs interfaces for PCI devices have remained open (for root users) for writing even with kernel lockdown mode enabled. The legacy_io file is used to read/write for legacy port I/O while legacy_mem is used to access legacy PCI memory space. Krzysztof Wilczyński explained in a patch queued into the PCI subsystem's "next" Git branch ahead of Linux 7.3 that lockdown checks were never added for the legacy I/O and memory handlers. That's been that way since 2019 when the code was originally added for locking down PCI BAR access when the kernel is in locked down mode. "Currently, the legacy I/O and memory sysfs handlers do not check security_locked_down(LOCKDOWN_PCI_ACCESS), leaving the legacy_io and legacy_mem files unprotected when the kernel is locked down. Commit eb627e17727e ("PCI: Lock down BAR access when the kernel is locked down") added the check to pci_write_config(), pci_mmap_resource(), and pci_write_resource_io() to prevent userspace from programming DMA-capable hardware that could be used to modify kernel code, but did not cover the legacy handlers. As a result, root can still write arbitrary I/O ports and map the legacy I/O and memory spaces while the kernel is locked down, which is the same capability the lockdown is meant to remove." The patch is in PCI's next Git branch for the upcoming Linux 7.3 merge window. As it's marked as a fix for the original 2019 PCI BAR patch, it's also likely it will get back-ported to existing stable Linux kernel versions as well.

Original Source

Read the full article at Phoronix →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.